edu.stanford.nlp.trees
Class GrammaticalRelation

java.lang.Object
  extended by edu.stanford.nlp.trees.GrammaticalRelation
All Implemented Interfaces:
Comparable<GrammaticalRelation>

public class GrammaticalRelation
extends Object
implements Comparable<GrammaticalRelation>

GrammaticalRelation is used to define a standardized, hierarchical set of grammatical relations, together with patterns for identifying them in parse trees.

Each GrammaticalRelation has:

The targetPatterns associated with a GrammaticalRelation are designed as follows. In order to recognize a grammatical relation X holding between nodes A and B in a parse tree, we want to associate with GrammaticalRelation X a TregexPattern such that: For example, for the grammatical relation PREDICATE which holds between a clause and its primary verb phrase, we might want to use the pattern "S < VP=target", in which the root will match a clause and the node labeled "target" will match the verb phrase.

For a given grammatical relation, the method getRelatedNodes() takes a Tree node as an argument and attempts to return other nodes which have this grammatical relation to the argument node. By default, this method operates as follows: it steps through the patterns in the pattern list, trying to match each pattern against the argument node, until it finds some matches. If a pattern matches, all matching nodes (that is, each node which corresponds to node label "target" in some match) are returned as a list; otherwise the next pattern is tried.

For some grammatical relations, we need more sophisticated logic to identify related nodes. In such cases, getRelatedNodes() can be overridden on a per-relation basis using anonymous subclassing.

Author:
Bill MacCartney, Galen Andrew (refactoring English-specific stuff)
See Also:
GrammaticalStructure, EnglishGrammaticalRelations, ChineseGrammaticalRelations, EnglishGrammaticalStructure

Nested Class Summary
static class GrammaticalRelation.DependendentGRAnnotation
           
static class GrammaticalRelation.GovernorGRAnnotation
           
static class GrammaticalRelation.GrammaticalRelationAnnotation
           
static class GrammaticalRelation.KillGRAnnotation
           
 
Field Summary
static GrammaticalRelation DEPENDENT
          The "dependent" grammatical relation, which is the inverse of "governor".
static GrammaticalRelation GOVERNOR
          The "governor" grammatical relation, which is the inverse of "dependent".
static GrammaticalRelation KILL
          Dummy relation, used while collapsing relations, in English & Chinese GrammaticalStructure
 
Constructor Summary
GrammaticalRelation(String shortName, String longName, GrammaticalRelation parent, String sourcePattern, String[] targetPatterns)
           
GrammaticalRelation(String shortName, String longName, GrammaticalRelation parent, String sourcePattern, String[] targetPatterns, String specificString)
           
 
Method Summary
 int compareTo(GrammaticalRelation o)
           
 boolean equals(GrammaticalRelation gr)
           
 String getLongName()
           
 Collection<Tree> getRelatedNodes(Tree t, Tree root)
          Given a Tree node t, attempts to return a list of nodes to which node t has this grammatical relation.
 String getShortName()
           
 String getSpecific()
           
 boolean isAncestor(GrammaticalRelation gr)
           
 boolean isApplicable(Tree t)
          Returns true iff the value of Tree node t matches the sourcePattern for this GrammaticalRelation, indicating that this GrammaticalRelation is one that could hold between Tree node t and some other node.
 GrammaticalRelation parent()
          Returns the parent of this GrammaticalRelation.
 String toPrettyString()
          Returns a String representation of this GrammaticalRelation and the hierarchy below it, with one node per line, indented according to level.
 String toString()
          Returns short name (abbreviation) for this GrammaticalRelation.
static GrammaticalRelation valueOf(String s, List<GrammaticalRelation> values)
          Returns the GrammaticalRelation having the given string representation (e.g.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

GOVERNOR

public static final GrammaticalRelation GOVERNOR
The "governor" grammatical relation, which is the inverse of "dependent".

Example: "the red car" → gov(red, car)


DEPENDENT

public static final GrammaticalRelation DEPENDENT
The "dependent" grammatical relation, which is the inverse of "governor".

Example: "the red car" → dep(car, red)


KILL

public static final GrammaticalRelation KILL
Dummy relation, used while collapsing relations, in English & Chinese GrammaticalStructure

Constructor Detail

GrammaticalRelation

public GrammaticalRelation(String shortName,
                           String longName,
                           GrammaticalRelation parent,
                           String sourcePattern,
                           String[] targetPatterns)

GrammaticalRelation

public GrammaticalRelation(String shortName,
                           String longName,
                           GrammaticalRelation parent,
                           String sourcePattern,
                           String[] targetPatterns,
                           String specificString)
Method Detail

getSpecific

public String getSpecific()

getRelatedNodes

public Collection<Tree> getRelatedNodes(Tree t,
                                        Tree root)
Given a Tree node t, attempts to return a list of nodes to which node t has this grammatical relation.


isApplicable

public boolean isApplicable(Tree t)
Returns true iff the value of Tree node t matches the sourcePattern for this GrammaticalRelation, indicating that this GrammaticalRelation is one that could hold between Tree node t and some other node.


isAncestor

public boolean isAncestor(GrammaticalRelation gr)

toString

public String toString()
Returns short name (abbreviation) for this GrammaticalRelation.

Overrides:
toString in class Object

parent

public GrammaticalRelation parent()
Returns the parent of this GrammaticalRelation.


equals

public boolean equals(GrammaticalRelation gr)

toPrettyString

public String toPrettyString()
Returns a String representation of this GrammaticalRelation and the hierarchy below it, with one node per line, indented according to level.

Returns:
String representation of this GrammaticalRelation

valueOf

public static GrammaticalRelation valueOf(String s,
                                          List<GrammaticalRelation> values)
Returns the GrammaticalRelation having the given string representation (e.g. "nsubj"), or null if no such is found.

Parameters:
s - The short name of the GrammaticalRelation
Returns:
The GrammaticalRelation with that name

compareTo

public int compareTo(GrammaticalRelation o)
Specified by:
compareTo in interface Comparable<GrammaticalRelation>

getLongName

public String getLongName()

getShortName

public String getShortName()


Stanford NLP Group