GrammaticalRelation
is used to define a standardized, hierarchical set of grammatical relations, together with patterns for identifying them in parse trees.
Each GrammaticalRelation
has:
- A
String
short name, which should be a lowercase abbreviation of some kind. - A
String
long name, which should be descriptive. - A parent in the
GrammaticalRelation
hierarchy. - A {@link Pattern
Pattern
} calledsourcePattern
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.) - A list of zero or more {@link TregexPattern
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()
.)
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 {@link TregexPattern
TregexPattern
} such that:
- the root of the pattern matches A, and
- the pattern includes a special node label, "target", which matches B.
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 {@link GrammaticalRelation#getRelatedNodes 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, {@link GrammaticalRelation#getRelatedNodes getRelatedNodes()
}can be overridden on a per-relation basis using anonymous subclassing.
@see GrammaticalStructure
@see EnglishGrammaticalStructure
@see EnglishGrammaticalRelations
@see edu.stanford.nlp.trees.international.pennchinese.ChineseGrammaticalRelations
@author Bill MacCartney
@author Galen Andrew (refactoring English-specific stuff)
@author Ilya Sherman (refactoring annotation-relation pairing)