edu.stanford.nlp.trees
Class MemoryTreebank

java.lang.Object
  |
  +--java.util.AbstractCollection
        |
        +--edu.stanford.nlp.trees.Treebank
              |
              +--edu.stanford.nlp.trees.MemoryTreebank
All Implemented Interfaces:
Collection, FileProcessor, List

public final class MemoryTreebank
extends Treebank
implements FileProcessor, List

A MemoryTreebank object stores a corpus of examples with given tree structures in memory (as a List).

Author:
Christopher Manning, Roger Levy (added encoding variable and method)

Constructor Summary
MemoryTreebank()
          Create a new tree bank.
MemoryTreebank(int initialCapacity)
          Create a new Treebank.
MemoryTreebank(int initialCapacity, TreeReaderFactory trf)
          Create a new tree bank.
MemoryTreebank(String encoding)
          Create a new tree bank, set the encoding for file access
MemoryTreebank(TreeReaderFactory trf)
          Create a new tree bank.
MemoryTreebank(TreeReaderFactory trf, String encoding)
          Create a new tree bank.
 
Method Summary
 void add(int index, Object element)
           
 boolean add(Object element)
           
 boolean addAll(int index, Collection c)
           
 void apply(TreeProcessor tp)
          Apply the TreeProcessor tp to all trees in the Treebank.
 void clear()
          Empty a Treebank.
 Object get(int i)
          Get a tree by index from the Treebank.
 String getEncoding()
          Returns the encoding in use for bytestream access.
 int indexOf(Object o)
           
 Iterator iterator()
          Return an Iterator over Trees in the Treebank.
 int lastIndexOf(Object o)
           
 ListIterator listIterator()
           
 ListIterator listIterator(int index)
           
 void loadPath(File path, FileFilter filt)
          Load trees from given directory.
static void main(String[] args)
          Loads treebank grammar from first argument and prints it.
 void processFile(File file)
          Load a collection of parse trees from the file of given name.
 Object remove(int index)
           
 Object set(int index, Object element)
           
 int size()
          Returns the size of the Treebank.
 List subList(int fromIndex, int toIndex)
           
 
Methods inherited from class edu.stanford.nlp.trees.Treebank
loadPath, loadPath, loadPath, loadPath, loadPath, remove, toString, treeReaderFactory
 
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, removeAll, retainAll, toArray, toArray
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
addAll, contains, containsAll, equals, hashCode, isEmpty, remove, removeAll, retainAll, toArray, toArray
 

Constructor Detail

MemoryTreebank

public MemoryTreebank()
Create a new tree bank.


MemoryTreebank

public MemoryTreebank(String encoding)
Create a new tree bank, set the encoding for file access

Parameters:
encoding - the encoding to use for file access.

MemoryTreebank

public MemoryTreebank(TreeReaderFactory trf)
Create a new tree bank.

Parameters:
trf - the factory class to be called to create a new TreeReader

MemoryTreebank

public MemoryTreebank(TreeReaderFactory trf,
                      String encoding)
Create a new tree bank.

Parameters:
trf - the factory class to be called to create a new TreeReader
encoding - the encoding to use for file access.

MemoryTreebank

public MemoryTreebank(int initialCapacity)
Create a new Treebank.

Parameters:
initialCapacity - The initial size of the underlying Collection, (if a Collection-based storage mechanism is being provided)

MemoryTreebank

public MemoryTreebank(int initialCapacity,
                      TreeReaderFactory trf)
Create a new tree bank.

Parameters:
initialCapacity - The initial size of the underlying Collection
trf - the factory class to be called to create a new TreeReader
Method Detail

getEncoding

public String getEncoding()
Returns the encoding in use for bytestream access.


clear

public void clear()
Empty a Treebank.

Specified by:
clear in interface List
Specified by:
clear in class Treebank

loadPath

public void loadPath(File path,
                     FileFilter filt)
Load trees from given directory.

Specified by:
loadPath in class Treebank
Parameters:
path - file or directory to load from
filt - a FilenameFilter of files to load

processFile

public void processFile(File file)
Load a collection of parse trees from the file of given name. Each tree may optionally be encased in parens to allow for Penn Treebank style trees. This methods implements the FileProcessor interface.

Specified by:
processFile in interface FileProcessor
Parameters:
file - file to load a tree from
See Also:
for traversing directories

get

public Object get(int i)
Get a tree by index from the Treebank. This operation isn't in the Treebank feature set, and so is only available with a MemoryTreebank, but is useful in allowing the latter to be used as an ArrayList.

Specified by:
get in interface List
Parameters:
i - The integer (counting from 0) index of the tree
Returns:
A tree

apply

public void apply(TreeProcessor tp)
Apply the TreeProcessor tp to all trees in the Treebank.

Specified by:
apply in class Treebank
Parameters:
tp - A class that implements the TreeProcessor interface

iterator

public Iterator iterator()
Return an Iterator over Trees in the Treebank.

Specified by:
iterator in interface List
Specified by:
iterator in class Treebank
Returns:
The iterator

size

public int size()
Returns the size of the Treebank. Provides a more efficient implementation than the one for a generic Treebank

Specified by:
size in interface List
Overrides:
size in class Treebank
Returns:
the number of trees in the Treebank

add

public void add(int index,
                Object element)
Specified by:
add in interface List

add

public boolean add(Object element)
Specified by:
add in interface List
Overrides:
add in class AbstractCollection

addAll

public boolean addAll(int index,
                      Collection c)
Specified by:
addAll in interface List

indexOf

public int indexOf(Object o)
Specified by:
indexOf in interface List

lastIndexOf

public int lastIndexOf(Object o)
Specified by:
lastIndexOf in interface List

remove

public Object remove(int index)
Specified by:
remove in interface List

set

public Object set(int index,
                  Object element)
Specified by:
set in interface List

listIterator

public ListIterator listIterator()
Specified by:
listIterator in interface List

listIterator

public ListIterator listIterator(int index)
Specified by:
listIterator in interface List

subList

public List subList(int fromIndex,
                    int toIndex)
Specified by:
subList in interface List

main

public static void main(String[] args)
Loads treebank grammar from first argument and prints it. Just a demonstration of functionality.
usage: java MemoryTreebank treebankFilesPath

Parameters:
args - array of command-line arguments


Stanford NLP Group