edu.stanford.nlp.trees
Class EnglishGrammaticalStructure

java.lang.Object
  extended by edu.stanford.nlp.trees.TreeGraph
      extended by edu.stanford.nlp.trees.GrammaticalStructure
          extended by edu.stanford.nlp.trees.EnglishGrammaticalStructure
All Implemented Interfaces:
java.io.Serializable

public class EnglishGrammaticalStructure
extends GrammaticalStructure

A GrammaticalStructure for English.

The Stanford parser should be run with the "-retainNPTmpSubcategories" option! Caveat emptor! This is a work in progress. Suggestions welcome.

Author:
Bill MacCartney, Marie-Catherine de Marneffe, Christopher Manning, Daniel Cer (CoNLLX format and alternative user selected dependency printer/reader interface)
See Also:
Serialized Form

Nested Class Summary
static class EnglishGrammaticalStructure.FromDependenciesFactory
           
 
Field Summary
 
Fields inherited from class edu.stanford.nlp.trees.GrammaticalStructure
allTypedDependencies, CoNLLX_FieldCount, CoNLLX_GovField, CoNLLX_POSField, CoNLLX_RelnField, CoNLLX_WordField, DEFAULT_PARSER_FILE, dependencies, puncFilter, typedDependencies
 
Fields inherited from class edu.stanford.nlp.trees.TreeGraph
root
 
Constructor Summary
EnglishGrammaticalStructure(java.util.List<TypedDependency> projectiveDependencies, TreeGraphNode root)
          Used for postprocessing CoNLL X dependencies
EnglishGrammaticalStructure(Tree t)
          Construct a new GrammaticalStructure from an existing parse tree.
EnglishGrammaticalStructure(Tree t, Filter<java.lang.String> puncFilter)
          This gets used by GrammaticalStructureFactory (by reflection).
EnglishGrammaticalStructure(Tree t, Filter<java.lang.String> puncFilter, HeadFinder hf)
          This gets used by GrammaticalStructureFactory (by reflection).
EnglishGrammaticalStructure(Tree t, Filter<java.lang.String> puncFilter, HeadFinder hf, boolean threadSafe)
          Construct a new GrammaticalStructure from an existing parse tree.
 
Method Summary
static EnglishGrammaticalStructure buildCoNLLXGrammaticalStructure(java.util.List<java.util.List<java.lang.String>> tokenFields)
           
protected  void collapseDependencies(java.util.List<TypedDependency> list, boolean CCprocess, boolean includeExtras)
          Destructively modifies this Collection<TypedDependency> by collapsing several types of transitive pairs of dependencies.
protected  void collapseDependenciesTree(java.util.List<TypedDependency> list)
          Destructively modify the Collection<TypedDependency> to collapse language-dependent transitive dependencies but keeping a tree structure.
protected static GrammaticalRelation conjValue(java.lang.String conj)
          Does some hard coding to deal with relation in CONJP.
protected  void correctDependencies(java.util.Collection<TypedDependency> list)
          Destructively modify the TypedDependencyGraph to correct language-dependent dependencies.
protected  Filter<TypedDependency> extraTreeDepFilter()
          Returns a Filter which checks dependencies for usefulness as extra tree-based dependencies.
protected  void getExtras(java.util.List<TypedDependency> list)
          Get extra dependencies that do not depend on the tree structure, but rather only depend on the existing dependency structure.
static TreeGraphNode getSubject(TreeGraphNode t)
          Tries to return a node representing the SUBJECT (whether nominal or clausal) of the given node t.
protected  void postProcessDependencies(java.util.List<TypedDependency> list)
          Post process the dependencies in whatever way this language requires.
static java.util.List<GrammaticalStructure> readCoNLLXGrammaticalStructureCollection(java.lang.String fileName)
           
 
Methods inherited from class edu.stanford.nlp.trees.GrammaticalStructure
allTypedDependencies, buildCoNLLXGrammaticalStructure, dependencies, dependenciesToString, fromStringReps, getDependencyPath, getDependents, getGovernor, getGrammaticalRelation, getGrammaticalRelation, getListGrammaticalRelation, getNodeInRelation, getRoots, isConnected, main, printDependencies, readCoNLLXGrammaticalStructureCollection, typedDependencies, typedDependencies, typedDependenciesCCprocessed, typedDependenciesCCprocessed, typedDependenciesCollapsed, typedDependenciesCollapsed, typedDependenciesCollapsedTree
 
Methods inherited from class edu.stanford.nlp.trees.TreeGraph
addNodeToIndexMap, getNodeByIndex, getNodes, root, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

EnglishGrammaticalStructure

public EnglishGrammaticalStructure(Tree t)
Construct a new GrammaticalStructure from an existing parse tree. The new GrammaticalStructure has the same tree structure and label values as the given tree (but no shared storage). As part of construction, the parse tree is analyzed using definitions from GrammaticalRelation to populate the new GrammaticalStructure with as many labeled grammatical relations as it can.

Parameters:
t - Parse tree to make grammatical structure from

EnglishGrammaticalStructure

public EnglishGrammaticalStructure(Tree t,
                                   Filter<java.lang.String> puncFilter)
This gets used by GrammaticalStructureFactory (by reflection). DON'T DELETE.

Parameters:
t - Parse tree to make grammatical structure from
puncFilter - Filter to remove punctuation dependencies

EnglishGrammaticalStructure

public EnglishGrammaticalStructure(Tree t,
                                   Filter<java.lang.String> puncFilter,
                                   HeadFinder hf)
This gets used by GrammaticalStructureFactory (by reflection). DON'T DELETE.

Parameters:
t - Parse tree to make grammatical structure from
puncFilter - Filter to remove punctuation dependencies
hf - HeadFinder to use when building it

EnglishGrammaticalStructure

public EnglishGrammaticalStructure(Tree t,
                                   Filter<java.lang.String> puncFilter,
                                   HeadFinder hf,
                                   boolean threadSafe)
Construct a new GrammaticalStructure from an existing parse tree. The new GrammaticalStructure has the same tree structure and label values as the given tree (but no shared storage). As part of construction, the parse tree is analyzed using definitions from GrammaticalRelation to populate the new GrammaticalStructure with as many labeled grammatical relations as it can.

Parameters:
t - Parse tree to make grammatical structure from
puncFilter - Filter for punctuation words
hf - HeadFinder to use when building it
threadSafe - Whether or not to support simultaneous instances among multiple threads

EnglishGrammaticalStructure

public EnglishGrammaticalStructure(java.util.List<TypedDependency> projectiveDependencies,
                                   TreeGraphNode root)
Used for postprocessing CoNLL X dependencies

Method Detail

extraTreeDepFilter

protected Filter<TypedDependency> extraTreeDepFilter()
Returns a Filter which checks dependencies for usefulness as extra tree-based dependencies. By default, everything is accepted. One example of how this can be useful is in the English dependencies, where the REL dependency is used as an intermediate and we do not want this to be added when we make a second pass over the trees for missing dependencies.

Overrides:
extraTreeDepFilter in class GrammaticalStructure

getSubject

public static TreeGraphNode getSubject(TreeGraphNode t)
Tries to return a node representing the SUBJECT (whether nominal or clausal) of the given node t. Probably, node t should represent a clause or verb phrase.

Parameters:
t - a node in this GrammaticalStructure
Returns:
a node which is the subject of node t, or else null

correctDependencies

protected void correctDependencies(java.util.Collection<TypedDependency> list)
Description copied from class: GrammaticalStructure
Destructively modify the TypedDependencyGraph to correct language-dependent dependencies. (e.g., nsubjpass in a relative clause)

Default is no-op; to be over-ridden in subclasses.

Overrides:
correctDependencies in class GrammaticalStructure

postProcessDependencies

protected void postProcessDependencies(java.util.List<TypedDependency> list)
Description copied from class: GrammaticalStructure
Post process the dependencies in whatever way this language requires. For example, English might replace "rel" dependencies with either dobj or pobj depending on the surrounding dependencies.

Overrides:
postProcessDependencies in class GrammaticalStructure

getExtras

protected void getExtras(java.util.List<TypedDependency> list)
Description copied from class: GrammaticalStructure
Get extra dependencies that do not depend on the tree structure, but rather only depend on the existing dependency structure. For example, the English xsubj dependency can be extracted that way.

Overrides:
getExtras in class GrammaticalStructure

collapseDependencies

protected void collapseDependencies(java.util.List<TypedDependency> list,
                                    boolean CCprocess,
                                    boolean includeExtras)
Destructively modifies this Collection<TypedDependency> by collapsing several types of transitive pairs of dependencies. If called with a tree of dependencies and both CCprocess and includeExtras set to false, then the tree structure is preserved.
prepositional object dependencies: pobj
prep(cat, in) and pobj(in, hat) are collapsed to prep_in(cat, hat)
prepositional complement dependencies: pcomp
prep(heard, of) and pcomp(of, attacking) are collapsed to prepc_of(heard, attacking)
conjunct dependencies
cc(investors, and) and conj(investors, regulators) are collapsed to conj_and(investors,regulators)
possessive dependencies: possessive
possessive(Montezuma, 's) will be erased. This is like a collapsing, but due to the flatness of NPs, two dependencies are not actually composed.
For relative clauses, it will collapse referent
ref(man, that) and dobj(love, that) are collapsed to dobj(love, man)

Overrides:
collapseDependencies in class GrammaticalStructure
Parameters:
list - A list of dependencies to process for possible collapsing
CCprocess - apply CC process?

collapseDependenciesTree

protected void collapseDependenciesTree(java.util.List<TypedDependency> list)
Description copied from class: GrammaticalStructure
Destructively modify the Collection<TypedDependency> to collapse language-dependent transitive dependencies but keeping a tree structure.

Default is no-op; to be over-ridden in subclasses.

Overrides:
collapseDependenciesTree in class GrammaticalStructure
Parameters:
list - A list of dependencies to process for possible collapsing

conjValue

protected static GrammaticalRelation conjValue(java.lang.String conj)
Does some hard coding to deal with relation in CONJP. For now we deal with: but not, if not, instead of, rather than, but rather GO TO negcc as well as, not to mention, but also, & GO TO and.

Parameters:
conj - The head dependency of the conjunction marker
Returns:
A GrammaticalRelation made from a normalized form of that conjunction.

readCoNLLXGrammaticalStructureCollection

public static java.util.List<GrammaticalStructure> readCoNLLXGrammaticalStructureCollection(java.lang.String fileName)
                                                                                     throws java.io.IOException
Throws:
java.io.IOException

buildCoNLLXGrammaticalStructure

public static EnglishGrammaticalStructure buildCoNLLXGrammaticalStructure(java.util.List<java.util.List<java.lang.String>> tokenFields)


Stanford NLP Group