|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.stanford.nlp.trees.TreeGraph
edu.stanford.nlp.trees.GrammaticalStructure
public class GrammaticalStructure
A GrammaticalStructure
is a
(that is, a tree with additional labeled
arcs between nodes) for representing the grammatical relations in a
parse tree. A new TreeGraph
GrammaticalStructure
is constructed
from an existing parse tree with the help of
, which
defines a hierarchy of English grammatical relations, along with
patterns for identifying them in parse trees. The constructor for
GrammaticalRelation
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.
Field Summary |
---|
Fields inherited from class edu.stanford.nlp.trees.TreeGraph |
---|
root |
Constructor Summary | |
---|---|
GrammaticalStructure(Tree t)
Construct a new GrammaticalStructure from an
existing parse tree. |
Method Summary | |
---|---|
TreeGraphNode |
getAdjectivalComplement(TreeGraphNode t)
Tries to return a node representing the of the given node t . |
TreeGraphNode |
getClausalComplement(TreeGraphNode t)
Tries to return a node representing the of the given node t . |
TreeGraphNode |
getClausalSubject(TreeGraphNode t)
Tries to return a node representing the of the given node t . |
java.util.List |
getDependencyPath(int nodeIndex,
int rootIndex)
Returns the dependency path as a list of labels, from node to root, it is assumed that that root is an ancestor of node |
java.util.List |
getDependencyPath(TreeGraphNode node,
TreeGraphNode root)
Returns the dependency path as a list of labels, from node to root, it is assumed that that root is an ancestor of node |
java.util.Set |
getDependents(TreeGraphNode t)
Tries to return a Set of leaf (terminal) nodes
which are the s of the given node t . |
TreeGraphNode |
getDirectObject(TreeGraphNode t)
Tries to return a node representing the of the given node t . |
TreeGraphNode |
getGovernor(TreeGraphNode t)
Tries to return a leaf (terminal) node which is the 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 |
TreeGraphNode |
getHeadTag(TreeGraphNode t)
Tries to return a (preterminal) node which represents the head tag for the given node t . |
TreeGraphNode |
getHeadWord(TreeGraphNode t)
Tries to return a leaf (terminal) node which represents the head word for the given node t . |
TreeGraphNode |
getIndirectObject(TreeGraphNode t)
Tries to return a node representing the of the given node t . |
TreeGraphNode |
getNominalSubject(TreeGraphNode t)
Tries to return a node representing the of the given node t . |
TreeGraphNode |
getPredicate(TreeGraphNode t)
Tries to return a node representing the of the given node t . |
TreeGraphNode |
getSubject(TreeGraphNode t)
Tries to return a node representing the (whether
nominal or clausal) of the given node t . |
TreeGraphNode |
getTemporalModifier(TreeGraphNode t)
Tries to return a node representing a of the given node
t . |
static void |
main(java.lang.String[] args)
Just for testing. |
void |
printTypedDependencies()
Prints the result of to stdout . |
void |
printTypedDependencies(java.io.PrintWriter pw)
Prints the result of to the specified
PrintWriter . |
void |
printTypedDependencies(java.lang.String format)
Prints the result of to stdout . |
void |
printTypedDependencies(java.lang.String format,
java.io.PrintWriter pw)
Prints the result of to the specified
PrintWriter . |
java.util.List |
typedDependencies()
Returns a List of Triple s, each
representing a typed dependency in the
GrammaticalStructure . |
java.lang.String |
typedDependenciesToString()
Returns a String representation of the result of
as exemplified by the following: |
java.lang.String |
typedDependenciesToString(java.lang.String format)
Returns a String representation of the result of in a user-specified format. |
Methods inherited from class edu.stanford.nlp.trees.TreeGraph |
---|
addNodeToIndexMap, getNodeByIndex, root, toString |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public GrammaticalStructure(Tree t)
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.
Method Detail |
---|
public TreeGraphNode getHeadWord(TreeGraphNode t)
t
.
t
- any node in this GrammaticalStructure
t
, or else null
public TreeGraphNode getHeadTag(TreeGraphNode t)
t
.
t
- any node in this GrammaticalStructure
t
, or else null
public TreeGraphNode getGovernor(TreeGraphNode t)
GOVERNOR
of the given node t
.
Probably, t
should be a leaf node as well.
t
- a leaf node in this GrammaticalStructure
t
, or else null
public java.util.Set getDependents(TreeGraphNode t)
Set
of leaf (terminal) nodes
which are the DEPENDENT
s of the given node t
.
Probably, t
should be a leaf node as well.
t
- a leaf node in this GrammaticalStructure
Set
of nodes which are dependents of
node t
, or else null
public TreeGraphNode getPredicate(TreeGraphNode t)
PREDICATE
of the given node t
.
Probably, node t
should represent a clause.
t
- a node in this GrammaticalStructure
t
, or else null
public TreeGraphNode getNominalSubject(TreeGraphNode t)
NOMINAL_SUBJECT
of the given node t
.
Probably, node t
should represent a clause or verb phrase.
t
- a node in this GrammaticalStructure
t
, or else null
public TreeGraphNode getClausalSubject(TreeGraphNode t)
CLAUSAL_SUBJECT
of the given node t
.
Probably, node t
should represent a clause or verb phrase.
t
- a node in this GrammaticalStructure
t
, or else null
public TreeGraphNode getSubject(TreeGraphNode t)
SUBJECT
(whether
nominal or clausal) of the given node t
.
Probably, node t
should represent a clause or
verb phrase.
t
- a node in this GrammaticalStructure
t
, or else null
public TreeGraphNode getDirectObject(TreeGraphNode t)
DIRECT_OBJECT
of the given node t
.
Probably, node t
should represent a clause or verb phrase.
t
- a node in this GrammaticalStructure
t
, or else null
public TreeGraphNode getIndirectObject(TreeGraphNode t)
INDIRECT_OBJECT
of the given node t
.
Probably, node t
should represent a clause or verb phrase.
t
- a node in this GrammaticalStructure
t
, or else null
public TreeGraphNode getClausalComplement(TreeGraphNode t)
CLAUSAL_COMPLEMENT
of the given node t
.
Probably, node t
should represent a clause or verb phrase.
t
- a node in this GrammaticalStructure
t
, or else null
public TreeGraphNode getAdjectivalComplement(TreeGraphNode t)
ADJECTIVAL_COMPLEMENT
of the given node t
.
Probably, node t
should represent a clause or verb phrase.
t
- a node in this GrammaticalStructure
t
, or else null
public TreeGraphNode getTemporalModifier(TreeGraphNode t)
TEMPORAL_MODIFIER
of the given node
t
. Probably, node t
should
represent a clause or verb phrase. (Currently, only NP-TMPs
are recognized, not PP-TMPs).
t
- a node in this GrammaticalStructure
t
, or else null
public GrammaticalRelation getGrammaticalRelation(int govIndex, int depIndex)
public GrammaticalRelation getGrammaticalRelation(TreeGraphNode gov, TreeGraphNode dep)
public java.util.List typedDependencies()
List
of Triple
s, each
representing a typed dependency in the
GrammaticalStructure
. Each Triple
is
of the form (GrammaticalRelation
,
TreeGraphNode
, TreeGraphNode
),
where both TreeGraphNode
s are leaf (terminal)
nodes. The first TreeGraphNode
is the governor,
the second is the dependent, and the
GrammaticalRelation
is the most specific relation
found to hold between the two nodes.
public java.util.List getDependencyPath(int nodeIndex, int rootIndex)
nodeIndex
- rootIndex
-
public java.util.List getDependencyPath(TreeGraphNode node, TreeGraphNode root)
node
- root
-
public java.lang.String typedDependenciesToString(java.lang.String format)
typedDependencies()
in a user-specified format.
Currently, two formats are supported:
<dependencies> <dep type="tmod"> <governor idx="6">died</governor> <dependent idx="9">today</dependent> </dep> <dep type="nsubj"> <governor idx="6">died</governor> <dependent idx="3">Sam</dependent> </dep> </dependencies>
tmod(died-6, today-9) nsubj(died-6, Sam-3)
format
- a String
specifying the desired format
String
representation of the typed
dependencies in this GrammaticalStructure
public java.lang.String typedDependenciesToString()
typedDependencies()
as exemplified by the following:
tmod(died-6, today-9) nsubj(died-6, Sam-3)
String
representation of the typed
dependencies in this GrammaticalStructure
public void printTypedDependencies()
typedDependenciesToString()
to stdout
.
public void printTypedDependencies(java.io.PrintWriter pw)
typedDependenciesToString()
to the specified
PrintWriter
.
public void printTypedDependencies(java.lang.String format)
typedDependenciesToString(format)
to stdout
.
public void printTypedDependencies(java.lang.String format, java.io.PrintWriter pw)
typedDependenciesToString(format)
to the specified
PrintWriter
.
public static void main(java.lang.String[] args)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |