edu.stanford.nlp.trees
Class MemoryTreebank

java.lang.Object
  extended by java.util.AbstractCollection<Tree>
      extended by edu.stanford.nlp.trees.Treebank
          extended by edu.stanford.nlp.trees.MemoryTreebank
All Implemented Interfaces:
FileProcessor, java.lang.Iterable<Tree>, java.util.Collection<Tree>, java.util.List<Tree>

public final class MemoryTreebank
extends Treebank
implements FileProcessor, java.util.List<Tree>

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

Author:
Christopher Manning

Field Summary
 
Fields inherited from class edu.stanford.nlp.trees.Treebank
DEFAULT_TREE_FILE_SUFFIX
 
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(java.util.List<Tree> trees, TreeReaderFactory trf, java.lang.String encoding)
          Create a new tree bank.
MemoryTreebank(java.lang.String encoding)
          Create a new tree bank, set the encoding for file access
MemoryTreebank(TreeNormalizer tm)
          Create a new tree bank, using a specific TreeNormalizer.
MemoryTreebank(TreeReaderFactory trf)
          Create a new tree bank.
MemoryTreebank(TreeReaderFactory trf, java.lang.String encoding)
          Create a new tree bank.
 
Method Summary
 void add(int index, Tree element)
           
 boolean add(Tree element)
           
 boolean addAll(int index, java.util.Collection<? extends Tree> c)
           
 void apply(TreeVisitor tp)
          Apply the TreeVisitor tp to all trees in the Treebank.
 void clear()
          Empty a Treebank.
 Tree get(int i)
          Get a tree by index from the Treebank.
 int indexOf(java.lang.Object o)
           
 java.util.Iterator<Tree> iterator()
          Return an Iterator over Trees in the Treebank.
 int lastIndexOf(java.lang.Object o)
           
 java.util.ListIterator<Tree> listIterator()
           
 java.util.ListIterator<Tree> listIterator(int index)
           
 void load(java.io.Reader r)
          Load a collection of parse trees from a Reader.
 void load(java.io.Reader r, java.lang.String id)
          Load a collection of parse trees from a Reader.
 void loadPath(java.io.File path, java.io.FileFilter filt)
          Load trees from given directory.
 void loadPath(java.lang.String path, java.io.FileFilter filt, java.lang.String srlFile)
           
static void main(java.lang.String[] args)
          Loads treebank grammar from first argument and prints it.
 void processFile(java.io.File file)
          Load a collection of parse trees from the file of given name.
 Tree remove(int index)
           
 Tree set(int index, Tree element)
           
 int size()
          Returns the size of the Treebank.
 java.util.List<Tree> subList(int fromIndex, int toIndex)
           
 Treebank transform(TreeTransformer treeTrans)
          Return a MemoryTreebank where each Tree in the current treebank has been transformed using the TreeTransformer.
 
Methods inherited from class edu.stanford.nlp.trees.Treebank
decimate, encoding, loadPath, loadPath, loadPath, loadPath, loadPath, remove, textualSummary, textualSummary, 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. The trees are made with a LabeledScoredTreeReaderFactory.

Compatibility note: Until Sep 2004, this used to create a Treebank with a SimpleTreeReaderFactory, but this was changed as the old default wasn't very useful, especially to naive users.


MemoryTreebank

public MemoryTreebank(TreeNormalizer tm)
Create a new tree bank, using a specific TreeNormalizer. The trees are made with a LabeledScoredTreeReaderFactory.

Compatibility note: Until Sep 2004, this used to create a Treebank with a SimpleTreeReaderFactory, but this was changed as the old default wasn't very useful, especially to naive users.


MemoryTreebank

public MemoryTreebank(java.lang.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,
                      java.lang.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(java.util.List<Tree> trees,
                      TreeReaderFactory trf,
                      java.lang.String encoding)
Create a new tree bank. The list of trees passed in is simply placed in the Treebank. It is not copied.

Parameters:
trees - The trees to put in the Treebank.
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

clear

public void clear()
Empty a Treebank.

Specified by:
clear in interface java.util.Collection<Tree>
Specified by:
clear in interface java.util.List<Tree>
Specified by:
clear in class Treebank

loadPath

public void loadPath(java.io.File path,
                     java.io.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

loadPath

public void loadPath(java.lang.String path,
                     java.io.FileFilter filt,
                     java.lang.String srlFile)

processFile

public void processFile(java.io.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

load

public void load(java.io.Reader r)
Load a collection of parse trees from a Reader. Each tree may optionally be encased in parens to allow for Penn Treebank style trees.

Parameters:
r - The reader to read trees from. (If you want it buffered, you should already have buffered it!)

load

public void load(java.io.Reader r,
                 java.lang.String id)
Load a collection of parse trees from a Reader. Each tree may optionally be encased in parens to allow for Penn Treebank style trees.

Parameters:
r - The reader to read trees from. (If you want it buffered, you should already have buffered it!)
id - An ID for where these files come from (arbitrary, but something like a filename. Can be null for none.

get

public Tree 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 a List.

Specified by:
get in interface java.util.List<Tree>
Parameters:
i - The integer (counting from 0) index of the tree
Returns:
A tree

apply

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

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

iterator

public java.util.Iterator<Tree> iterator()
Return an Iterator over Trees in the Treebank.

Specified by:
iterator in interface java.lang.Iterable<Tree>
Specified by:
iterator in interface java.util.Collection<Tree>
Specified by:
iterator in interface java.util.List<Tree>
Specified by:
iterator in class java.util.AbstractCollection<Tree>
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 java.util.Collection<Tree>
Specified by:
size in interface java.util.List<Tree>
Overrides:
size in class Treebank
Returns:
the number of trees in the Treebank

add

public void add(int index,
                Tree element)
Specified by:
add in interface java.util.List<Tree>

add

public boolean add(Tree element)
Specified by:
add in interface java.util.Collection<Tree>
Specified by:
add in interface java.util.List<Tree>
Overrides:
add in class java.util.AbstractCollection<Tree>

addAll

public boolean addAll(int index,
                      java.util.Collection<? extends Tree> c)
Specified by:
addAll in interface java.util.List<Tree>

indexOf

public int indexOf(java.lang.Object o)
Specified by:
indexOf in interface java.util.List<Tree>

lastIndexOf

public int lastIndexOf(java.lang.Object o)
Specified by:
lastIndexOf in interface java.util.List<Tree>

remove

public Tree remove(int index)
Specified by:
remove in interface java.util.List<Tree>

set

public Tree set(int index,
                Tree element)
Specified by:
set in interface java.util.List<Tree>

listIterator

public java.util.ListIterator<Tree> listIterator()
Specified by:
listIterator in interface java.util.List<Tree>

listIterator

public java.util.ListIterator<Tree> listIterator(int index)
Specified by:
listIterator in interface java.util.List<Tree>

subList

public java.util.List<Tree> subList(int fromIndex,
                                    int toIndex)
Specified by:
subList in interface java.util.List<Tree>

transform

public Treebank transform(TreeTransformer treeTrans)
Return a MemoryTreebank where each Tree in the current treebank has been transformed using the TreeTransformer. This Treebank is unchanged (assuming that the TreeTransformer correctly doesn't change input Trees.

Overrides:
transform in class Treebank
Parameters:
treeTrans - The TreeTransformer to use
Returns:
A Treebank (actually a TransformingTreebank) where each Tree in the current treebank has been transformed using the TreeTransformer.

main

public static void main(java.lang.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