public class SemanticGraph
extends java.lang.Object
implements java.io.Serializable
edgeSet()
).
This is intentional. Use edgeIterable()
to iterate over the edges if necessary.SemanticGraphEdge
,
IndexedWord
,
Serialized FormModifier and Type | Class and Description |
---|---|
static class |
SemanticGraph.OutputFormat |
Modifier and Type | Field and Description |
---|---|
static boolean |
addSRLArcs |
Constructor and Description |
---|
SemanticGraph() |
SemanticGraph(java.util.Collection<TypedDependency> dependencies)
This is the constructor used by the parser.
|
SemanticGraph(SemanticGraph g)
Returns a new SemanticGraph which is a copy of the supplied SemanticGraph.
|
SemanticGraph(SemanticGraph g,
java.util.Map<IndexedWord,IndexedWord> prevToNewMap)
Copies a the current graph, but also sets the mapping from the old to new
graph.
|
Modifier and Type | Method and Description |
---|---|
void |
addComment(java.lang.String comment)
Store a comment line with this semantic graph.
|
SemanticGraphEdge |
addEdge(IndexedWord s,
IndexedWord d,
GrammaticalRelation reln,
double weight,
boolean isExtra) |
SemanticGraphEdge |
addEdge(SemanticGraphEdge edge) |
void |
addRoot(IndexedWord root) |
void |
addVertex(IndexedWord vertex) |
boolean |
attachedNegatedVerb(IndexedWord vertex) |
java.util.List<Pair<GrammaticalRelation,IndexedWord>> |
childPairs(IndexedWord vertex)
Returns a list of pairs of a relation name and the child
IndexedFeatureLabel that bears that relation.
|
java.util.Set<GrammaticalRelation> |
childRelns(IndexedWord vertex)
Returns a list of relations which this node has with its children.
|
int |
commonAncestor(IndexedWord v1,
IndexedWord v2)
Return the maximum distance to a least common ancestor.
|
boolean |
containsEdge(IndexedWord source,
IndexedWord target) |
boolean |
containsEdge(SemanticGraphEdge edge) |
boolean |
containsVertex(IndexedWord vertex) |
void |
deleteDuplicateEdges()
Delete all duplicate edges.
|
java.util.Set<IndexedWord> |
descendants(IndexedWord vertex)
Returns the set of descendants governed by this node in the graph.
|
int |
edgeCount() |
java.lang.Iterable<SemanticGraphEdge> |
edgeIterable() |
java.util.List<SemanticGraphEdge> |
edgeListSorted()
Returns an ordered list of edges in the graph.
|
boolean |
equals(java.lang.Object o) |
java.util.List<SemanticGraphEdge> |
findAllRelns(GrammaticalRelation tgtRelation)
Given a semantic graph, and a target relation, returns a list of all
relations (edges) matching.
|
java.util.List<SemanticGraphEdge> |
findAllRelns(java.lang.String tgtRelationShortname)
Given a semantic graph, and the short name of a target relation, returns a list of all
relations (edges) matching.
|
java.util.List<SemanticGraphEdge> |
getAllEdges(IndexedWord gov,
IndexedWord dep) |
java.util.List<IndexedWord> |
getAllNodesByPartOfSpeechPattern(java.lang.String pattern) |
java.util.List<IndexedWord> |
getAllNodesByWordPattern(java.lang.String pattern)
Returns all nodes of type
IndexedWord in this SemanticGraph having the given word or
regex, or returns empty list if no such found. |
java.util.List<IndexedWord> |
getChildList(IndexedWord vertex) |
java.util.Set<IndexedWord> |
getChildren(IndexedWord vertex) |
java.util.Set<IndexedWord> |
getChildrenWithReln(IndexedWord vertex,
GrammaticalRelation reln)
Returns a set of all children bearing a certain grammatical relation, or
an empty set if none.
|
java.util.Set<IndexedWord> |
getChildrenWithRelns(IndexedWord vertex,
java.util.Collection<GrammaticalRelation> relns)
Returns a set of all children bearing one of a set of grammatical
relations, or an empty set if none.
|
IndexedWord |
getChildWithReln(IndexedWord vertex,
GrammaticalRelation reln)
Returns the first IndexedFeatureLabel bearing a certain grammatical
relation, or null if none.
|
java.util.List<java.lang.String> |
getComments()
Return the list of comments stored with this graph.
|
IndexedWord |
getCommonAncestor(IndexedWord v1,
IndexedWord v2)
Returns the least common ancestor.
|
SemanticGraphEdge |
getEdge(IndexedWord gov,
IndexedWord dep) |
SemanticGraphEdge |
getEdge(IndexedWord gov,
IndexedWord dep,
GrammaticalRelation reln)
Given a governor, dependent, and the relation between them, returns the
SemanticGraphEdge object of that arc if it exists, otherwise returns null.
|
IndexedWord |
getFirstRoot()
Returns the (first) root of this SemanticGraph.
|
java.util.List<SemanticGraphEdge> |
getIncomingEdgesSorted(IndexedWord vertex) |
java.util.Set<IndexedWord> |
getLeafVertices() |
IndexedWord |
getNodeByIndex(int index)
Returns the first
IndexedWord in this SemanticGraph having the given integer index,
or throws IllegalArgumentException if no such node is found. |
IndexedWord |
getNodeByIndexAndCopyCount(int index,
int copyCount)
Returns the first
IndexedWord in this SemanticGraph having the given integer index,
or throws IllegalArgumentException if no such node is found. |
IndexedWord |
getNodeByIndexAndCopyCountSafe(int index,
int copyCount)
Same as above, but returns
null if the index does not exist
(instead of throwing an exception). |
IndexedWord |
getNodeByIndexSafe(int index)
Same as above, but returns
null if the index does not exist
(instead of throwing an exception). |
IndexedWord |
getNodeByWordPattern(java.lang.String pattern)
Returns the first
IndexedWord in this SemanticGraph having the given word or
regex, or return null if no such found. |
java.util.List<SemanticGraphEdge> |
getOutEdgesSorted(IndexedWord vertex) |
IndexedWord |
getParent(IndexedWord vertex)
Return the real syntactic parent of vertex.
|
java.util.List<IndexedWord> |
getParentList(IndexedWord vertex) |
java.util.Set<IndexedWord> |
getParents(IndexedWord vertex) |
java.util.Set<IndexedWord> |
getParentsWithReln(IndexedWord vertex,
GrammaticalRelation reln)
Returns a set of all parents bearing a certain grammatical relation, or an
empty set if none.
|
java.util.Set<IndexedWord> |
getParentsWithReln(IndexedWord vertex,
java.lang.String relnName)
Returns a set of all parents bearing a certain grammatical relation, or an
empty set if none.
|
java.util.List<IndexedWord> |
getPathToRoot(IndexedWord vertex)
Find the path from the given node to a root.
|
java.util.Collection<IndexedWord> |
getRoots() |
java.util.List<SemanticGraphEdge> |
getShortestDirectedPathEdges(IndexedWord source,
IndexedWord target) |
java.util.List<IndexedWord> |
getShortestDirectedPathNodes(IndexedWord source,
IndexedWord target)
Returns the shortest directed path between two edges in the graph.
|
java.util.List<SemanticGraphEdge> |
getShortestUndirectedPathEdges(IndexedWord source,
IndexedWord target) |
java.util.List<IndexedWord> |
getShortestUndirectedPathNodes(IndexedWord source,
IndexedWord target)
Returns the nodes in the shortest undirected path between two edges in the
graph.
|
java.util.Collection<IndexedWord> |
getSiblings(IndexedWord vertex)
Method for getting the siblings of a particular node.
|
java.util.Set<IndexedWord> |
getSubgraphVertices(IndexedWord root)
Returns all nodes reachable from
root . |
boolean |
hasChild(IndexedWord vertex,
GrammaticalRelation reln,
java.lang.String childLemma)
Does the given
vertex have at least one child with the given reln and the lemma childLemma ? |
boolean |
hasChildren(IndexedWord vertex) |
boolean |
hasChildWithReln(IndexedWord vertex,
GrammaticalRelation reln)
Does the given
vertex have at least one child with the given reln ? |
int |
hashCode() |
boolean |
hasParentWithReln(IndexedWord vertex,
GrammaticalRelation reln)
Returns true if vertex has an incoming relation reln
|
java.lang.Iterable<SemanticGraphEdge> |
incomingEdgeIterable(IndexedWord v) |
java.util.Iterator<SemanticGraphEdge> |
incomingEdgeIterator(IndexedWord v) |
java.util.List<SemanticGraphEdge> |
incomingEdgeList(IndexedWord v) |
int |
inDegree(IndexedWord vertex) |
int |
isAncestor(IndexedWord child,
IndexedWord ancestor)
Searches up to 2 levels to determine how far ancestor is from child (i.e.,
returns 1 if "ancestor" is a parent, or 2 if ancestor is a grandparent.
|
boolean |
isAuxiliaryVerb(IndexedWord vertex)
Returns true iff this vertex stands in the "aux" relation to (any of)
its parent(s).
|
boolean |
isDag() |
boolean |
isDag(IndexedWord root) |
boolean |
isEmpty() |
boolean |
isInConditionalContext(IndexedWord vertex)
Check if the vertex is in a "conditional" context.
|
boolean |
isNegatedVertex(IndexedWord vertex) |
SemanticGraph |
makeSoftCopy() |
boolean |
matchPatternToVertex(java.lang.String pattern,
IndexedWord vertex) |
boolean |
matchPatternToVertex(java.lang.String pattern,
IndexedWord vertex,
boolean det) |
int |
outDegree(IndexedWord vertex) |
java.lang.Iterable<SemanticGraphEdge> |
outgoingEdgeIterable(IndexedWord v) |
java.util.Iterator<SemanticGraphEdge> |
outgoingEdgeIterator(IndexedWord v) |
java.util.List<SemanticGraphEdge> |
outgoingEdgeList(IndexedWord v) |
java.util.List<Pair<GrammaticalRelation,IndexedWord>> |
parentPairs(IndexedWord vertex)
Returns a list of pairs of a relation name and the parent
IndexedFeatureLabel to which we bear that relation.
|
void |
prettyPrint()
Pretty-prints this semantic graph to
System.out , formatted by
the default semantic graph formatter. |
void |
prettyPrint(SemanticGraphFormatter formatter)
Pretty-prints this semantic graph to
System.out , formatted by
the supplied semantic graph formatter. |
GrammaticalRelation |
reln(IndexedWord a,
IndexedWord b)
Returns the relation that node a has with node b.
|
java.util.Set<GrammaticalRelation> |
relns(IndexedWord vertex)
Returns a set of relations which this node has with its parents.
|
boolean |
removeEdge(SemanticGraphEdge e) |
boolean |
removeVertex(IndexedWord vertex) |
void |
resetRoots()
This method should not be used if possible.
|
void |
setRoot(IndexedWord word) |
void |
setRoots(java.util.Collection<IndexedWord> words) |
int |
size()
Returns the number of nodes in the graph
|
java.lang.String |
toCompactString() |
java.lang.String |
toCompactString(boolean showTags) |
java.lang.String |
toDotFormat()
Returns an unnamed dot format digraph.
|
java.lang.String |
toDotFormat(java.lang.String graphname)
Returns a dot format digraph with the given name.
|
java.lang.String |
toDotFormat(java.lang.String graphname,
CoreLabel.OutputFormat indexedWordFormat) |
java.lang.String |
toEnUncollapsedSentenceString()
Similar to
toRecoveredString , but will fill in words that were
collapsed into relations (i.e. |
java.lang.String |
toFormattedString()
Returns a
String representation of this semantic graph,
formatted by the default semantic graph formatter. |
java.lang.String |
toFormattedString(SemanticGraphFormatter formatter)
Returns a
String representation of this semantic graph,
formatted by the supplied semantic graph formatter. |
java.lang.String |
toList()
Returns a String representation of this graph as a list of typed
dependencies, as exemplified by the following:
|
java.util.List<IndexedWord> |
topologicalSort() |
java.lang.String |
toPOSList()
Similar to toList(), but uses POS tags instead of word and index.
|
java.lang.String |
toRecoveredSentenceString() |
java.lang.String |
toRecoveredSentenceStringWithIndexMarking() |
java.lang.String |
toString()
Recursive depth first traversal.
|
java.lang.String |
toString(CoreLabel.OutputFormat wordFormat) |
java.lang.String |
toString(SemanticGraph.OutputFormat format)
Returns a String representation of the result of this set of typed
dependencies in a user-specified format.
|
java.util.Collection<TypedDependency> |
typedDependencies()
Returns a list of TypedDependency in the graph.
|
static SemanticGraph |
valueOf(java.lang.String s) |
static SemanticGraph |
valueOf(java.lang.String s,
Language language)
Tries to parse a String representing a SemanticGraph.
|
java.util.List<IndexedWord> |
vertexListSorted()
This returns an ordered list of vertices (based upon their
indices in the sentence).
|
java.util.Set<IndexedWord> |
vertexSet() |
java.util.List<IndexedWord> |
yield(IndexedWord word)
Returns the yield of a node, i.e., all descendents of the node.
|
Pair<java.lang.Integer,java.lang.Integer> |
yieldSpan(IndexedWord word)
Returns the span of the subtree yield of this node.
|
public static final boolean addSRLArcs
public SemanticGraph()
public SemanticGraph(SemanticGraph g)
IndexedWord
s) and the edges (SemanticGraphEdges)
are copied.public SemanticGraph(SemanticGraph g, java.util.Map<IndexedWord,IndexedWord> prevToNewMap)
public SemanticGraph(java.util.Collection<TypedDependency> dependencies)
public int edgeCount()
public int outDegree(IndexedWord vertex)
public int inDegree(IndexedWord vertex)
public java.util.List<SemanticGraphEdge> getAllEdges(IndexedWord gov, IndexedWord dep)
public SemanticGraphEdge getEdge(IndexedWord gov, IndexedWord dep)
public void addVertex(IndexedWord vertex)
public boolean containsVertex(IndexedWord vertex)
public boolean containsEdge(IndexedWord source, IndexedWord target)
public boolean containsEdge(SemanticGraphEdge edge)
public java.util.Set<IndexedWord> vertexSet()
public boolean removeEdge(SemanticGraphEdge e)
public boolean removeVertex(IndexedWord vertex)
public java.util.List<IndexedWord> vertexListSorted()
public java.util.List<SemanticGraphEdge> edgeListSorted()
public java.lang.Iterable<SemanticGraphEdge> edgeIterable()
public java.util.Iterator<SemanticGraphEdge> outgoingEdgeIterator(IndexedWord v)
public java.lang.Iterable<SemanticGraphEdge> outgoingEdgeIterable(IndexedWord v)
public java.util.Iterator<SemanticGraphEdge> incomingEdgeIterator(IndexedWord v)
public java.lang.Iterable<SemanticGraphEdge> incomingEdgeIterable(IndexedWord v)
public java.util.List<SemanticGraphEdge> outgoingEdgeList(IndexedWord v)
public java.util.List<SemanticGraphEdge> incomingEdgeList(IndexedWord v)
public boolean isEmpty()
public int isAncestor(IndexedWord child, IndexedWord ancestor)
child
- candidate childancestor
- candidate ancestorpublic int commonAncestor(IndexedWord v1, IndexedWord v2)
public IndexedWord getCommonAncestor(IndexedWord v1, IndexedWord v2)
public boolean matchPatternToVertex(java.lang.String pattern, IndexedWord vertex, boolean det)
public boolean matchPatternToVertex(java.lang.String pattern, IndexedWord vertex)
public java.util.List<IndexedWord> getChildList(IndexedWord vertex)
public java.util.Set<IndexedWord> getChildren(IndexedWord vertex)
public boolean hasChildren(IndexedWord vertex)
public java.util.List<SemanticGraphEdge> getIncomingEdgesSorted(IndexedWord vertex)
public java.util.List<SemanticGraphEdge> getOutEdgesSorted(IndexedWord vertex)
public java.util.List<IndexedWord> getParentList(IndexedWord vertex)
public java.util.Set<IndexedWord> getParents(IndexedWord vertex)
public java.util.Collection<IndexedWord> getSiblings(IndexedWord vertex)
public java.util.List<IndexedWord> getPathToRoot(IndexedWord vertex)
public IndexedWord getParent(IndexedWord vertex)
public IndexedWord getNodeByIndex(int index) throws java.lang.IllegalArgumentException
IndexedWord
in this SemanticGraph
having the given integer index,
or throws IllegalArgumentException
if no such node is found.java.lang.IllegalArgumentException
public IndexedWord getNodeByIndexSafe(int index)
null
if the index does not exist
(instead of throwing an exception).public IndexedWord getNodeByIndexAndCopyCount(int index, int copyCount) throws java.lang.IllegalArgumentException
IndexedWord
in this SemanticGraph
having the given integer index,
or throws IllegalArgumentException
if no such node is found.java.lang.IllegalArgumentException
public IndexedWord getNodeByIndexAndCopyCountSafe(int index, int copyCount)
null
if the index does not exist
(instead of throwing an exception).public IndexedWord getNodeByWordPattern(java.lang.String pattern)
IndexedWord
in this SemanticGraph
having the given word or
regex, or return null if no such found.public java.util.List<IndexedWord> getAllNodesByWordPattern(java.lang.String pattern)
IndexedWord
in this SemanticGraph
having the given word or
regex, or returns empty list if no such found.public java.util.List<IndexedWord> getAllNodesByPartOfSpeechPattern(java.lang.String pattern)
public java.util.Set<IndexedWord> descendants(IndexedWord vertex)
public java.util.List<Pair<GrammaticalRelation,IndexedWord>> childPairs(IndexedWord vertex)
public java.util.List<Pair<GrammaticalRelation,IndexedWord>> parentPairs(IndexedWord vertex)
public java.util.Set<GrammaticalRelation> relns(IndexedWord vertex)
public GrammaticalRelation reln(IndexedWord a, IndexedWord b)
a
and
b
, and this method only returns one relation.public java.util.Set<GrammaticalRelation> childRelns(IndexedWord vertex)
public java.util.Collection<IndexedWord> getRoots()
public IndexedWord getFirstRoot()
public void addRoot(IndexedWord root)
public void resetRoots()
public void setRoot(IndexedWord word)
public void setRoots(java.util.Collection<IndexedWord> words)
public java.util.List<IndexedWord> topologicalSort()
CyclicGraphException
- (a subtype of IllegalStateException) if this graph is not a DAGpublic boolean hasChild(IndexedWord vertex, GrammaticalRelation reln, java.lang.String childLemma)
vertex
have at least one child with the given reln
and the lemma childLemma
?public boolean hasChildWithReln(IndexedWord vertex, GrammaticalRelation reln)
vertex
have at least one child with the given reln
?public boolean hasParentWithReln(IndexedWord vertex, GrammaticalRelation reln)
vertex
- A node in this graphreln
- The relation we want to checkpublic IndexedWord getChildWithReln(IndexedWord vertex, GrammaticalRelation reln)
public java.util.Set<IndexedWord> getParentsWithReln(IndexedWord vertex, GrammaticalRelation reln)
public java.util.Set<IndexedWord> getParentsWithReln(IndexedWord vertex, java.lang.String relnName)
public java.util.Set<IndexedWord> getChildrenWithReln(IndexedWord vertex, GrammaticalRelation reln)
public java.util.Set<IndexedWord> getChildrenWithRelns(IndexedWord vertex, java.util.Collection<GrammaticalRelation> relns)
public SemanticGraphEdge getEdge(IndexedWord gov, IndexedWord dep, GrammaticalRelation reln)
public boolean isNegatedVertex(IndexedWord vertex)
public boolean isInConditionalContext(IndexedWord vertex)
public boolean attachedNegatedVerb(IndexedWord vertex)
public boolean isAuxiliaryVerb(IndexedWord vertex)
public java.util.Set<IndexedWord> getLeafVertices()
public int size()
public java.util.Set<IndexedWord> getSubgraphVertices(IndexedWord root)
root
.root
- the root node of the subgraphpublic boolean isDag()
public boolean isDag(IndexedWord root)
root
- root node of the subgraph.root
contains no cycles.public java.lang.String toString()
-> need-3 (root) -> We-0 (nsubj) -> do-1 (aux) -> n't-2 (neg) -> badges-6 (dobj) -> no-4 (det) -> stinking-5 (amod)This is a quite ugly way to print a SemanticGraph. You might instead want to try
toString(OutputFormat)
.toString
in class java.lang.Object
public java.lang.String toString(CoreLabel.OutputFormat wordFormat)
public java.lang.String toRecoveredSentenceString()
public java.lang.String toRecoveredSentenceStringWithIndexMarking()
public java.lang.String toEnUncollapsedSentenceString()
toRecoveredString
, but will fill in words that were
collapsed into relations (i.e. prep_for --> 'for'). Mostly to deal with
collapsed dependency trees.
TODO: consider merging with toRecoveredString() NOTE: assumptions currently
are for English. NOTE: currently takes immediate successors to current word
and expands them. This assumption may not be valid for other conditions or
languages?public java.lang.String toString(SemanticGraph.OutputFormat format)
SemanticGraph.OutputFormat
):
nsubj(died-1, Sam-0) tmod(died-1, today-2)
dependent
, relation
, and governor
,
as exemplified by the following:
Sam-0 nsubj died-1 today-2 tmod died-1
<dependencies> <dep type="nsubj"> <governor idx="1">died</governor> <dependent idx="0">Sam</dependent> </dep> <dep type="tmod"> <governor idx="1">died</governor> <dependent idx="2">today</dependent> </dep> </dependencies>
toString()
format
- A String
specifying the desired formatString
representation of the typed dependencies in
this GrammaticalStructure
public java.lang.String toList()
nsubj(died-6, Sam-3) tmod(died-6, today-9)
String
representation of this set of typed dependenciespublic java.lang.String toPOSList()
public java.lang.String toCompactString()
public java.lang.String toCompactString(boolean showTags)
public java.lang.String toFormattedString()
String
representation of this semantic graph,
formatted by the default semantic graph formatter.public java.lang.String toFormattedString(SemanticGraphFormatter formatter)
String
representation of this semantic graph,
formatted by the supplied semantic graph formatter.public void prettyPrint(SemanticGraphFormatter formatter)
System.out
, formatted by
the supplied semantic graph formatter.public void prettyPrint()
System.out
, formatted by
the default semantic graph formatter.public java.lang.String toDotFormat()
public java.lang.String toDotFormat(java.lang.String graphname)
public java.lang.String toDotFormat(java.lang.String graphname, CoreLabel.OutputFormat indexedWordFormat)
public SemanticGraphEdge addEdge(IndexedWord s, IndexedWord d, GrammaticalRelation reln, double weight, boolean isExtra)
public SemanticGraphEdge addEdge(SemanticGraphEdge edge)
public static SemanticGraph valueOf(java.lang.String s, Language language)
public static SemanticGraph valueOf(java.lang.String s)
valueOf(String, Language)
public java.util.List<IndexedWord> getShortestUndirectedPathNodes(IndexedWord source, IndexedWord target)
source
- nodetarget
- nodepublic java.util.List<SemanticGraphEdge> getShortestUndirectedPathEdges(IndexedWord source, IndexedWord target)
public java.util.List<IndexedWord> getShortestDirectedPathNodes(IndexedWord source, IndexedWord target)
source
- nodetarget
- nodepublic java.util.List<SemanticGraphEdge> getShortestDirectedPathEdges(IndexedWord source, IndexedWord target)
public SemanticGraph makeSoftCopy()
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.util.List<SemanticGraphEdge> findAllRelns(GrammaticalRelation tgtRelation)
public java.util.List<SemanticGraphEdge> findAllRelns(java.lang.String tgtRelationShortname)
public void deleteDuplicateEdges()
public java.util.Collection<TypedDependency> typedDependencies()
public Pair<java.lang.Integer,java.lang.Integer> yieldSpan(IndexedWord word)
word
- The word acting as the root of the constituent we are finding.public java.util.List<IndexedWord> yield(IndexedWord word)
word
- The word acting as the root of the constituent we are finding.public void addComment(java.lang.String comment)
comment
- public java.util.List<java.lang.String> getComments()