edu.stanford.nlp.trees
Class GrammaticalStructure

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

public abstract class GrammaticalStructure
extends TreeGraph
implements Serializable

A GrammaticalStructure is a TreeGraph (that is, a tree with additional labeled arcs between nodes) for representing the grammatical relations in a parse tree. A new GrammaticalStructure is constructed from an existing parse tree with the help of GrammaticalRelation, which defines a hierarchy of grammatical relations, along with patterns for identifying them in parse trees. The constructor for GrammaticalStructure uses these definitions to populate the new GrammaticalStructure with as many labeled grammatical relations as it can. Once constructed, the new GrammaticalStructure can be printed in various formats, or interrogated using the interface methods in this class.

Caveat emptor! This is a work in progress. Nothing in here should be relied upon to function perfectly. Feedback welcome.

Author:
Bill MacCartney, Galen Andrew (refactoring English-specific stuff)
See Also:
EnglishGrammaticalRelations, GrammaticalRelation, EnglishGrammaticalStructure, Serialized Form

Field Summary
protected  Collection<TypedDependency> allTypedDependencies
           
protected  Set<Dependency> dependencies
           
protected  Collection<TypedDependency> typedDependencies
           
 
Fields inherited from class edu.stanford.nlp.trees.TreeGraph
root
 
Constructor Summary
GrammaticalStructure(Tree t, Collection<GrammaticalRelation> relations, HeadFinder hf, Filter<String> puncFilter)
          Create a new GrammaticalStructure, analyzing the parse tree and populate the GrammaticalStructure with as many labeled grammatical relation arcs as possible.
 
Method Summary
 Collection<TypedDependency> allTypedDependencies()
          Returns all the typed dependencies of this grammatical structure.
protected  void collapseDependencies(Collection<TypedDependency> list, boolean CCprocess)
          Destructively modify the TypedDependencyList to collapse language-dependent transitive dependencies.
protected  void correctDependencies(Collection<TypedDependency> list)
          Destructively modify the TypedDependencyGraph to correct language-dependent dependencies.
 Set<Dependency> dependencies()
          Returns the set of (governor, dependent) dependencies in this GrammaticalStructure.
 Map<Class<? extends CoreAnnotation>,Object> getAllDependents(TreeGraphNode node)
          returns all the dependencies of a certain node.
 List<String> getDependencyPath(int nodeIndex, int rootIndex)
          Returns the dependency path as a list of String, from node to root, it is assumed that that root is an ancestor of node
 List<String> getDependencyPath(TreeGraphNode node, TreeGraphNode root)
          Returns the dependency path as a list of String, from node to root, it is assumed that that root is an ancestor of node
 Set<Tree> getDependents(TreeGraphNode t)
          Tries to return a Set of leaf (terminal) nodes which are the DEPENDENTs of the given node t.
 Collection<TypedDependency> getDeps(boolean getExtra, Filter<TypedDependency> f)
          The constructor builds a list of typed dependencies using information from a GrammaticalStructure.
 TreeGraphNode getGovernor(TreeGraphNode t)
          Tries to return a leaf (terminal) node which is the GOVERNOR of the given node t.
 GrammaticalRelation getGrammaticalRelation(int govIndex, int depIndex)
          Get GrammaticalRelation between gov and dep, and null if gov is not the governor of dep
 GrammaticalRelation getGrammaticalRelation(TreeGraphNode gov, TreeGraphNode dep)
          Get GrammaticalRelation between gov and dep, and null if gov is not the governor of dep
 List<GrammaticalRelation> getListGrammaticalRelation(TreeGraphNode gov, TreeGraphNode dep)
          Get a list of GrammaticalRelation between gov and dep.
 TreeGraphNode getNodeInRelation(TreeGraphNode t, GrammaticalRelation r)
           
 Collection<TypedDependency> getRoots(Collection<TypedDependency> list)
          Return a list of TypedDependencies which are not dependent on any node from the list
 boolean isConnected(Collection<TypedDependency> list)
          Checks if all the typeDependencies are connected
 String toString()
          Return a String representing this treegraph.
 Collection<TypedDependency> typedDependencies()
          Returns the typed dependencies of this grammatical structure which do not break the tree structure of dependencies
 Collection<TypedDependency> typedDependencies(boolean includeExtras)
          Returns the typed dependencies of this grammatical structure.
 Collection<TypedDependency> typedDependenciesCCprocessed(boolean includeExtras)
          Get the typed dependencies after collapsing them and processing eventual CC complements.
 Collection<TypedDependency> typedDependenciesCollapsed()
          Get the typed dependencies after collapsing them.
 Collection<TypedDependency> typedDependenciesCollapsed(boolean includeExtras)
          Get the typed dependencies after collapsing them.
 
Methods inherited from class edu.stanford.nlp.trees.TreeGraph
addNodeToIndexMap, getNodeByIndex, getNodes, main, root
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

dependencies

protected Set<Dependency> dependencies

typedDependencies

protected Collection<TypedDependency> typedDependencies

allTypedDependencies

protected Collection<TypedDependency> allTypedDependencies
Constructor Detail

GrammaticalStructure

public GrammaticalStructure(Tree t,
                            Collection<GrammaticalRelation> relations,
                            HeadFinder hf,
                            Filter<String> puncFilter)
Create a new GrammaticalStructure, analyzing the parse tree and populate the GrammaticalStructure with as many labeled grammatical relation arcs as possible.

Parameters:
relations - a set of GrammaticalRelations to consider
t - a Tree to analyze
hf - a HeadFinder for analysis
puncFilter - a Filter to reject punctuation
Method Detail

toString

public String toString()
Description copied from class: TreeGraph
Return a String representing this treegraph. By default, the nodes of the treegraph are printed in Lispy (parenthesized) format, with one node per line, indented according to depth.

Overrides:
toString in class TreeGraph
Returns:
a String representation of this treegraph

getDeps

public Collection<TypedDependency> getDeps(boolean getExtra,
                                           Filter<TypedDependency> f)
The constructor builds a list of typed dependencies using information from a GrammaticalStructure.

Parameters:
getExtra - If true, the list of typed dependencies will contain extra ones. If false, the list of typed dependencies will respect the tree structure.

dependencies

public Set<Dependency> dependencies()
Returns the set of (governor, dependent) dependencies in this GrammaticalStructure.

Returns:
The set of (governor, dependent) dependencies in this GrammaticalStructure.

getDependents

public Set<Tree> getDependents(TreeGraphNode t)
Tries to return a Set of leaf (terminal) nodes which are the DEPENDENTs of the given node t. Probably, t should be a leaf node as well.

Parameters:
t - a leaf node in this GrammaticalStructure
Returns:
a Set of nodes which are dependents of node t, or else null

getGovernor

public TreeGraphNode getGovernor(TreeGraphNode t)
Tries to return a leaf (terminal) node which is the GOVERNOR of the given node t. Probably, t should be a leaf node as well.

Parameters:
t - a leaf node in this GrammaticalStructure
Returns:
a node which is the governor for node t, or else null

getNodeInRelation

public TreeGraphNode getNodeInRelation(TreeGraphNode t,
                                       GrammaticalRelation r)

getGrammaticalRelation

public GrammaticalRelation getGrammaticalRelation(int govIndex,
                                                  int depIndex)
Get GrammaticalRelation between gov and dep, and null if gov is not the governor of dep


getGrammaticalRelation

public GrammaticalRelation getGrammaticalRelation(TreeGraphNode gov,
                                                  TreeGraphNode dep)
Get GrammaticalRelation between gov and dep, and null if gov is not the governor of dep


getListGrammaticalRelation

public List<GrammaticalRelation> getListGrammaticalRelation(TreeGraphNode gov,
                                                            TreeGraphNode dep)
Get a list of GrammaticalRelation between gov and dep. Useful for getting extra dependencies, in which two nodes can be linked by multiple arcs.


typedDependencies

public Collection<TypedDependency> typedDependencies()
Returns the typed dependencies of this grammatical structure which do not break the tree structure of dependencies


allTypedDependencies

public Collection<TypedDependency> allTypedDependencies()
Returns all the typed dependencies of this grammatical structure.


typedDependencies

public Collection<TypedDependency> typedDependencies(boolean includeExtras)
Returns the typed dependencies of this grammatical structure.

If the boolean argument is true, the list of typed dependencies returned may include "extras".


typedDependenciesCollapsed

public Collection<TypedDependency> typedDependenciesCollapsed()
Get the typed dependencies after collapsing them.

Returns:
collapsed dependencies

typedDependenciesCollapsed

public Collection<TypedDependency> typedDependenciesCollapsed(boolean includeExtras)
Get the typed dependencies after collapsing them.

If the boolean argument is true, the list of typed dependencies returned may include "extras".

Returns:
collapsed dependencies

typedDependenciesCCprocessed

public Collection<TypedDependency> typedDependenciesCCprocessed(boolean includeExtras)
Get the typed dependencies after collapsing them and processing eventual CC complements.

If the boolean argument is true, the list of typed dependencies returned may include "extras".

Returns:
collapsed dependencies with CC processed

collapseDependencies

protected void collapseDependencies(Collection<TypedDependency> list,
                                    boolean CCprocess)
Destructively modify the TypedDependencyList to collapse language-dependent transitive dependencies.

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

Parameters:
list - A list of dependencies to process for possible collapsing

correctDependencies

protected void correctDependencies(Collection<TypedDependency> list)
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.

Parameters:
list -

getDependencyPath

public List<String> getDependencyPath(int nodeIndex,
                                      int rootIndex)
Returns the dependency path as a list of String, from node to root, it is assumed that that root is an ancestor of node

Parameters:
nodeIndex -
rootIndex -
Returns:
a list of dependency labels

getDependencyPath

public List<String> getDependencyPath(TreeGraphNode node,
                                      TreeGraphNode root)
Returns the dependency path as a list of String, from node to root, it is assumed that that root is an ancestor of node

Parameters:
node - Note to return path from
root - The root of the tree, an ancestor of node
Returns:
A list of dependency labels

getAllDependents

public Map<Class<? extends CoreAnnotation>,Object> getAllDependents(TreeGraphNode node)
returns all the dependencies of a certain node.

Parameters:
node -
Returns:
map of dependencies

isConnected

public boolean isConnected(Collection<TypedDependency> list)
Checks if all the typeDependencies are connected

Parameters:
list - a list of typedDependencies
Returns:
true if the list represents a connected graph, false otherwise

getRoots

public Collection<TypedDependency> getRoots(Collection<TypedDependency> list)
Return a list of TypedDependencies which are not dependent on any node from the list

Parameters:
list -
Returns:
A list of TypedDependencies which are not dependent on any node from the list


Stanford NLP Group