|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.stanford.nlp.trees.GrammaticalRelation
public class 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:
String
short name, which should be a lowercase
abbreviation of some kind.String
long name, which should be descriptive.GrammaticalRelation
hierarchy.Pattern
called
sourcePattern
which matches (parent) nodes from which
this GrammaticalRelation
could hold. (Note: this is done
with the Java regex Pattern matches()
predicate: the pattern
must match the
whole node name, and ^
or $
aren't needed.)TregexPattern
s
called targetPatterns
,
which describe the local tree structure which must hold between
the source node and a target node for the
GrammaticalRelation
to apply. (Note tregex
regular expressions match with the find()
method - though
literal string label descriptions that are not regular expressions must
be equals()
.)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:
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
takes a getRelatedNodes()
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,
can be overridden on a per-relation basis using anonymous subclassing.getRelatedNodes()
GrammaticalStructure
,
EnglishGrammaticalRelations
,
edu.stanford.nlp.trees.international.pennchinese.ChineseGrammaticalRelations
,
EnglishGrammaticalStructure
,
Serialized FormNested Class Summary | |
---|---|
static class |
GrammaticalRelation.DependendentGRAnnotation
|
static class |
GrammaticalRelation.GovernorGRAnnotation
|
static class |
GrammaticalRelation.GrammaticalRelationAnnotation
|
static class |
GrammaticalRelation.KillGRAnnotation
|
Field Summary | |
---|---|
protected static Map<Class<? extends GrammaticalRelation.GrammaticalRelationAnnotation>,GrammaticalRelation> |
annotationsToRelations
|
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 |
protected static Map<GrammaticalRelation,Class<? extends GrammaticalRelation.GrammaticalRelationAnnotation>> |
relationsToAnnotatoins
|
protected static Map<String,GrammaticalRelation> |
stringsToRelations
|
Constructor Summary | |
---|---|
GrammaticalRelation(String shortName,
String longName,
Class<? extends GrammaticalRelation.GrammaticalRelationAnnotation> annotation,
GrammaticalRelation parent)
|
|
GrammaticalRelation(String shortName,
String longName,
Class<? extends GrammaticalRelation.GrammaticalRelationAnnotation> annotation,
GrammaticalRelation parent,
String specificString)
|
|
GrammaticalRelation(String shortName,
String longName,
Class<? extends GrammaticalRelation.GrammaticalRelationAnnotation> annotation,
GrammaticalRelation parent,
String sourcePattern,
String[] targetPatterns)
|
|
GrammaticalRelation(String shortName,
String longName,
Class<? extends GrammaticalRelation.GrammaticalRelationAnnotation> annotation,
GrammaticalRelation parent,
String sourcePattern,
String[] targetPatterns,
String specificString)
|
Method Summary | |
---|---|
int |
compareTo(GrammaticalRelation o)
|
boolean |
equals(Object o)
Grammatical relations are equal with other grammatical relations if they have the same shortName and specific (if present). |
static Class<? extends GrammaticalRelation.GrammaticalRelationAnnotation> |
getAnnotationClass(GrammaticalRelation relation)
|
String |
getLongName()
|
GrammaticalRelation |
getParent()
Returns the parent of this GrammaticalRelation . |
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. |
static GrammaticalRelation |
getRelation(Class<? extends GrammaticalRelation.GrammaticalRelationAnnotation> annotation)
|
String |
getShortName()
|
String |
getSpecific()
|
int |
hashCode()
|
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. |
boolean |
isFromString()
This function is used to determine whether the GrammaticalRelation in question is one that was created to be a thin wrapper around a String representation by valueOf(String), or whether it is a full-fledged GrammaticalRelation created by direct invocation of the constructor. |
static void |
main(String[] args)
|
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)
Convert from a String representation of a GrammaticalRelation to a GrammaticalRelation. |
static GrammaticalRelation |
valueOf(String s,
Collection<GrammaticalRelation> values)
Returns the GrammaticalRelation having the given string representation (e.g. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected static Map<Class<? extends GrammaticalRelation.GrammaticalRelationAnnotation>,GrammaticalRelation> annotationsToRelations
protected static Map<GrammaticalRelation,Class<? extends GrammaticalRelation.GrammaticalRelationAnnotation>> relationsToAnnotatoins
protected static Map<String,GrammaticalRelation> stringsToRelations
public static final GrammaticalRelation GOVERNOR
Example: "the red car" →
gov
(red, car)
public static final GrammaticalRelation DEPENDENT
Example: "the red car" →
dep
(car, red)
public static final GrammaticalRelation KILL
Constructor Detail |
---|
public GrammaticalRelation(String shortName, String longName, Class<? extends GrammaticalRelation.GrammaticalRelationAnnotation> annotation, GrammaticalRelation parent, String sourcePattern, String[] targetPatterns, String specificString)
public GrammaticalRelation(String shortName, String longName, Class<? extends GrammaticalRelation.GrammaticalRelationAnnotation> annotation, GrammaticalRelation parent, String sourcePattern, String[] targetPatterns)
public GrammaticalRelation(String shortName, String longName, Class<? extends GrammaticalRelation.GrammaticalRelationAnnotation> annotation, GrammaticalRelation parent)
public GrammaticalRelation(String shortName, String longName, Class<? extends GrammaticalRelation.GrammaticalRelationAnnotation> annotation, GrammaticalRelation parent, String specificString)
Method Detail |
---|
public static Class<? extends GrammaticalRelation.GrammaticalRelationAnnotation> getAnnotationClass(GrammaticalRelation relation)
public static GrammaticalRelation getRelation(Class<? extends GrammaticalRelation.GrammaticalRelationAnnotation> annotation)
public static GrammaticalRelation valueOf(String s, Collection<GrammaticalRelation> values)
s
- The short name of the GrammaticalRelation
public static GrammaticalRelation valueOf(String s)
s
- The String representation of a GrammaticalRelation
public boolean isFromString()
public Collection<Tree> getRelatedNodes(Tree t, Tree root)
Tree
node t
, attempts to
return a list of nodes to which node t
has this
grammatical relation.
public boolean isApplicable(Tree t)
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.
public boolean isAncestor(GrammaticalRelation gr)
public final String toString()
GrammaticalRelation
.
Implementation note: Note that this method must be synced with
the equals() and valueOf(String) methods
toString
in class Object
public String toPrettyString()
String
representation of this
GrammaticalRelation
and the hierarchy below
it, with one node per line, indented according to level.
String
representation of this
GrammaticalRelation
public boolean equals(Object o)
equals
in class Object
o
- Object to be compared
public int hashCode()
hashCode
in class Object
public int compareTo(GrammaticalRelation o)
compareTo
in interface Comparable<GrammaticalRelation>
public String getLongName()
public String getShortName()
public String getSpecific()
public GrammaticalRelation getParent()
GrammaticalRelation
.
public static void main(String[] args)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |