public class SemanticGraphUtils
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static class |
SemanticGraphUtils.EdgeDiffResult |
static class |
SemanticGraphUtils.PositionedTree
This is used to uniquely index trees within a
Tree, maintaining the position of this subtree
within the context of the root.
|
static class |
SemanticGraphUtils.PrintVerticeParams |
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
BLANKET_NODE_ANON_PREFIX |
static java.lang.String |
SHARED_NODE_ANON_PREFIX |
static IndexedWord |
WILDCARD_VERTICE |
static java.lang.String |
WILDCARD_VERTICE_TOKEN |
| Modifier and Type | Method and Description |
|---|---|
static java.util.Set<SemanticGraphEdge> |
allEdgesInSet(java.lang.Iterable<IndexedWord> vertices,
SemanticGraph sg)
Given a set of vertices from the same graph, returns the set of all edges between these
vertices.
|
static java.util.Map<IndexedWord,IndexedWord> |
anonymyizeNodes(java.lang.Iterable<IndexedWord> verts,
java.lang.String prefix)
Given an iterable set of distinct vertices, creates a new mapping that maps the
original vertices to a set of "generic" versions.
|
static java.util.Set<IndexedWord> |
descendantsTabuRelns(SemanticGraph sg,
IndexedWord vertex,
java.util.Collection<GrammaticalRelation> tabuRelns) |
static java.util.Set<IndexedWord> |
descendantsTabuTestAndRelns(SemanticGraph sg,
IndexedWord vertex,
java.util.Collection<GrammaticalRelation> tabuRelns,
java.util.function.Predicate<IndexedWord> tabuTest) |
static java.util.Set<IndexedWord> |
descendantsTabuTestAndRelns(SemanticGraph sg,
IndexedWord vertex,
java.util.Collection<IndexedWord> tabuNodes,
java.util.Collection<GrammaticalRelation> tabuRelns,
java.util.function.BiPredicate<IndexedWord,SemanticGraph> tabuTest) |
static java.util.Set<IndexedWord> |
descendantsTabuTestAndRelns(SemanticGraph sg,
IndexedWord vertex,
java.util.Collection<IndexedWord> tabuNodes,
java.util.Collection<GrammaticalRelation> tabuRelns,
java.util.function.Predicate<IndexedWord> tabuTest) |
static SemanticGraphUtils.EdgeDiffResult |
diffEdges(java.util.Collection<SemanticGraphEdge> edges1,
java.util.Collection<SemanticGraphEdge> edges2,
SemanticGraph sg1,
SemanticGraph sg2,
ISemanticGraphEdgeEql compareObj)
Given two iterable sequences of edges, returns a pair containing the set of
edges in the first graph not in the second, and edges in the second not in the first.
|
static java.util.List<SemanticGraphEdge> |
edgesWithReln(java.lang.Iterable<SemanticGraphEdge> edges,
GrammaticalRelation reln)
Given a list of edges, returns those which match the given relation (can be string or
GrammaticalRelation object).
|
static void |
enRepairEdges(SemanticGraph sg) |
static java.util.List<SemanticGraphEdge> |
findAllRelnsWithPrefix(SemanticGraph sg,
java.lang.String prefix)
Given a semantic graph, and a relation prefix, returns a list of all relations (edges)
that start with the given prefix (e.g., prefix "prep" gives you all the prep relations: prep_by, pref_in,etc.)
|
static IndexedWord |
findMatchingNode(IndexedWord node,
SemanticGraph sg)
Finds the vertex in the given SemanticGraph that corresponds to the given node.
|
static java.util.List<IndexedWord> |
getChildrenWithPrepC(SemanticGraph sg,
IndexedWord vertex)
Since graphs can be have preps collapsed, finds all the immediate children of this node
that are linked by a collapsed preposition edge.
|
static java.util.List<IndexedWord> |
getChildrenWithRelnPrefix(SemanticGraph graph,
IndexedWord vertex,
java.util.Collection<java.lang.String> relnPrefixes)
Returns a list of all children bearing a grammatical relation starting with the given set of relation prefixes
|
static java.util.List<IndexedWord> |
getChildrenWithRelnPrefix(SemanticGraph graph,
IndexedWord vertex,
java.lang.String relnPrefix)
Returns a list of all children bearing a grammatical relation starting with the given string, relnPrefix
|
static java.util.Collection<IndexedWord> |
getDependencyBlanket(SemanticGraph sg,
java.util.Collection<IndexedWord> assertedNodes)
Given a SemanticGraph, and a set of nodes, finds the "blanket" of nodes that are one
edge away from the set of nodes passed in.
|
static java.util.Collection<SemanticGraphEdge> |
getEdgesSpannedByVertices(java.util.Collection<IndexedWord> nodes,
SemanticGraph sg)
Given a set of nodes from a SemanticGraph, returns the set of
edges that are spanned between these nodes.
|
static java.util.Set<SemanticGraphEdge> |
getSubTreeEdges(IndexedWord vertice,
SemanticGraph sg,
SemanticGraphEdge excludedEdge)
Given a starting vertice, grabs the subtree encapsulated by portion of the semantic graph, excluding
a given edge.
|
static void |
getSubTreeEdgesHelper(IndexedWord vertice,
SemanticGraph sg,
java.util.Set<SemanticGraphEdge> tabuEdges) |
static java.util.List<SemanticGraphEdge> |
incomingEdgesWithReln(IndexedWord node,
SemanticGraph sg,
GrammaticalRelation reln)
Returns the set of incoming edges for the given node that have the given
relation.
|
static boolean |
isTree(SemanticGraph sg)
Checks whether a given SemanticGraph is a strict surface syntax tree.
|
static void |
killNonRooted(SemanticGraph sg)
Deletes all nodes that are not rooted (such as dangling vertices after a series of
edges have been chopped).
|
static IndexedWord |
leftMostChildVertice(IndexedWord startNode,
SemanticGraph sg)
Returns the vertice that is "leftmost." Note this requires that the IndexedFeatureLabels present actually have
ordering information.
|
static Pair<IndexedWord,IndexedWord> |
leftRightMostChildVertices(IndexedWord startNode,
SemanticGraph sg)
Returns the vertices that are "leftmost, rightmost" Note this requires that the IndexedFeatureLabels present actually have
ordering information.
|
static void |
lemmatize(SemanticGraph sg)
Given a
SemanticGraph, sets the lemmas on its label
objects based on their word and tag. |
static java.util.Map<IndexedWord,IndexedWord> |
makeBlanketVertices(java.lang.Iterable<IndexedWord> verts)
Used to assign generic labels to the nodes in the "blanket" for a set of vertices in a graph.
|
static java.util.Map<IndexedWord,IndexedWord> |
makeGenericVertices(java.lang.Iterable<IndexedWord> verts)
Used to make a mapping that lets you create "anonymous" versions of shared nodes between two
graphs (given in the arg) using the shared prefix.
|
static SemanticGraph |
makeGraphFromNodes(java.util.Collection<IndexedWord> nodes,
SemanticGraph srcGraph)
Given a collection of nodes from srcGraph, generates a new
SemanticGraph based off the subset represented by those nodes.
|
static java.util.List<SemanticGraphEdge> |
makeReplacedEdges(java.lang.Iterable<SemanticGraphEdge> edges,
java.util.Map<IndexedWord,IndexedWord> vertReplacementMap,
boolean useGenericReplacement)
Given a set of edges, and a mapping between the replacement and target vertices that comprise the
vertices of the edges, returns a new set of edges with the replacement vertices.
|
static java.util.Map<SemanticGraphUtils.PositionedTree,IndexedWord> |
mapTreeToSg(Tree tree,
SemanticGraph sg)
Given a CFG Tree parse, and the equivalent SemanticGraph derived from that Tree, generates a mapping
from each of the tree terminals to the best-guess SemanticGraph node(s).
|
static java.util.List<SemanticGraphEdge> |
outgoingEdgesWithReln(IndexedWord node,
SemanticGraph sg,
GrammaticalRelation reln)
Checks for outgoing edges of the node, in the given graph, which contain
the given relation.
|
static java.lang.String |
printEdges(java.lang.Iterable<SemanticGraphEdge> edges)
Pretty printers
|
static java.lang.String |
printVertices(SemanticGraph sg) |
static java.lang.String |
printVertices(SemanticGraph sg,
SemanticGraphUtils.PrintVerticeParams params) |
static java.util.Collection<SemanticGraph> |
removeDuplicates(java.util.Collection<SemanticGraph> graphs)
Removes duplicate graphs from the set, using the string form of the graph
as the key (obviating issues with object equality).
|
static java.util.Collection<SemanticGraph> |
removeDuplicates(java.util.Collection<SemanticGraph> graphs,
java.util.Collection<SemanticGraph> tabuGraphs)
Given the set of graphs to remove duplicates from, also removes those on the tabu graphs
(and does not include them in the return set).
|
static java.util.Collection<SemanticGraph> |
removeDuplicates(java.util.Collection<SemanticGraph> graphs,
SemanticGraph tabuGraph) |
static void |
replaceNode(IndexedWord newNode,
IndexedWord oldNode,
SemanticGraph sg)
Replaces a node in the given SemanticGraph with the new node,
replacing its position in the node edges.
|
static SemanticGraph |
resetVerticeOrdering(SemanticGraph sg)
Resets the indices for the vertices in the graph, using the current
ordering returned by vertexList (presumably in order).
|
static java.lang.String |
sanitizeForSemgrexName(java.lang.String text)
Sanitizes the given string into a Semgrex friendly name
|
static java.lang.String |
semgrexFromGraph(java.lang.Iterable<SemanticGraphEdge> edges,
boolean matchTag,
boolean matchWord,
java.util.Map<IndexedWord,java.lang.String> nodeNameMap)
Given a set of edges that form a rooted and connected graph, returns a Semgrex pattern
corresponding to it.
|
static java.lang.String |
semgrexFromGraph(SemanticGraph sg,
boolean matchTag,
boolean matchWord,
java.util.Map<IndexedWord,java.lang.String> nodeNameMap)
Given a SemanticGraph, creates a SemgrexPattern string based off of this graph.
|
static java.lang.String |
semgrexFromGraph(SemanticGraph sg,
java.util.Collection<IndexedWord> wildcardNodes,
boolean useTag,
boolean useWord,
java.util.Map<IndexedWord,java.lang.String> nodeNameMap) |
static java.lang.String |
semgrexFromGraph(SemanticGraph sg,
java.util.Collection<IndexedWord> wildcardNodes,
java.util.Map<IndexedWord,java.lang.String> nodeNameMap,
java.util.function.Function<IndexedWord,java.lang.String> wordTransformation)
nodeValuesTranformation is a function that converts a vertex (IndexedWord) to the value.
|
protected static java.lang.String |
semgrexFromGraphHelper(IndexedWord vertice,
SemanticGraph sg,
java.util.Set<IndexedWord> tabu,
java.util.Set<SemanticGraphEdge> seenEdges,
boolean useWordAsLabel,
boolean nameEdges,
java.util.Collection<IndexedWord> wildcardNodes,
java.util.Map<IndexedWord,java.lang.String> nodeNameMap,
boolean orderedNodes,
java.util.function.Function<IndexedWord,java.lang.String> nodeValuesTransformation)
Recursive call to generate the Semgrex pattern based off of this SemanticGraph.
|
static java.lang.String |
semgrexFromGraphOrderedNodes(SemanticGraph sg,
java.util.Collection<IndexedWord> wildcardNodes,
java.util.Map<IndexedWord,java.lang.String> nodeNameMap,
java.util.function.Function<IndexedWord,java.lang.String> wordTransformation)
Same as semgrexFromGraph except the node traversal is ordered by sorting
|
static SemanticGraph |
setSentIndex(SemanticGraph sg,
int newSentIndex)
GIven a graph, returns a new graph with the the new sentence index enforced.
|
static java.util.Set<IndexedWord> |
tabuDescendants(SemanticGraph sg,
IndexedWord vertex,
java.util.Collection<IndexedWord> tabu)
Finds the descendents of the given node in graph, avoiding the given set of nodes
|
static java.util.Set<IndexedWord> |
tabuDescendants(SemanticGraph sg,
IndexedWord vertex,
java.util.Collection<IndexedWord> tabu,
java.util.Collection<GrammaticalRelation> tabuRelns)
Finds the set of descendants for a node in the graph, avoiding the set of nodes and the
set of edge relations.
|
public static final java.lang.String WILDCARD_VERTICE_TOKEN
public static final IndexedWord WILDCARD_VERTICE
public static final java.lang.String SHARED_NODE_ANON_PREFIX
public static final java.lang.String BLANKET_NODE_ANON_PREFIX
public static SemanticGraph makeGraphFromNodes(java.util.Collection<IndexedWord> nodes, SemanticGraph srcGraph)
public static IndexedWord findMatchingNode(IndexedWord node, SemanticGraph sg)
public static java.util.Set<SemanticGraphEdge> getSubTreeEdges(IndexedWord vertice, SemanticGraph sg, SemanticGraphEdge excludedEdge)
public static void getSubTreeEdgesHelper(IndexedWord vertice, SemanticGraph sg, java.util.Set<SemanticGraphEdge> tabuEdges)
public static java.util.Collection<SemanticGraphEdge> getEdgesSpannedByVertices(java.util.Collection<IndexedWord> nodes, SemanticGraph sg)
public static java.util.List<IndexedWord> getChildrenWithRelnPrefix(SemanticGraph graph, IndexedWord vertex, java.lang.String relnPrefix)
public static java.util.List<IndexedWord> getChildrenWithRelnPrefix(SemanticGraph graph, IndexedWord vertex, java.util.Collection<java.lang.String> relnPrefixes)
public static java.util.List<IndexedWord> getChildrenWithPrepC(SemanticGraph sg, IndexedWord vertex)
public static java.util.List<SemanticGraphEdge> incomingEdgesWithReln(IndexedWord node, SemanticGraph sg, GrammaticalRelation reln)
public static java.util.List<SemanticGraphEdge> outgoingEdgesWithReln(IndexedWord node, SemanticGraph sg, GrammaticalRelation reln)
public static java.util.List<SemanticGraphEdge> edgesWithReln(java.lang.Iterable<SemanticGraphEdge> edges, GrammaticalRelation reln)
public static java.util.List<SemanticGraphEdge> findAllRelnsWithPrefix(SemanticGraph sg, java.lang.String prefix)
public static java.util.Set<IndexedWord> tabuDescendants(SemanticGraph sg, IndexedWord vertex, java.util.Collection<IndexedWord> tabu)
public static java.util.Set<IndexedWord> tabuDescendants(SemanticGraph sg, IndexedWord vertex, java.util.Collection<IndexedWord> tabu, java.util.Collection<GrammaticalRelation> tabuRelns)
public static java.util.Set<IndexedWord> descendantsTabuRelns(SemanticGraph sg, IndexedWord vertex, java.util.Collection<GrammaticalRelation> tabuRelns)
public static java.util.Set<IndexedWord> descendantsTabuTestAndRelns(SemanticGraph sg, IndexedWord vertex, java.util.Collection<GrammaticalRelation> tabuRelns, java.util.function.Predicate<IndexedWord> tabuTest)
public static java.util.Set<IndexedWord> descendantsTabuTestAndRelns(SemanticGraph sg, IndexedWord vertex, java.util.Collection<IndexedWord> tabuNodes, java.util.Collection<GrammaticalRelation> tabuRelns, java.util.function.Predicate<IndexedWord> tabuTest)
public static java.util.Set<IndexedWord> descendantsTabuTestAndRelns(SemanticGraph sg, IndexedWord vertex, java.util.Collection<IndexedWord> tabuNodes, java.util.Collection<GrammaticalRelation> tabuRelns, java.util.function.BiPredicate<IndexedWord,SemanticGraph> tabuTest)
public static IndexedWord leftMostChildVertice(IndexedWord startNode, SemanticGraph sg)
public static Pair<IndexedWord,IndexedWord> leftRightMostChildVertices(IndexedWord startNode, SemanticGraph sg)
public static java.util.Collection<IndexedWord> getDependencyBlanket(SemanticGraph sg, java.util.Collection<IndexedWord> assertedNodes)
public static SemanticGraph resetVerticeOrdering(SemanticGraph sg)
public static void enRepairEdges(SemanticGraph sg)
public static void killNonRooted(SemanticGraph sg)
public static void replaceNode(IndexedWord newNode, IndexedWord oldNode, SemanticGraph sg)
public static java.util.Map<IndexedWord,IndexedWord> anonymyizeNodes(java.lang.Iterable<IndexedWord> verts, java.lang.String prefix)
verts - Vertices to anonymizeprefix - Prefix to assign to this anonymizationpublic static java.util.Map<IndexedWord,IndexedWord> makeGenericVertices(java.lang.Iterable<IndexedWord> verts)
public static java.util.Map<IndexedWord,IndexedWord> makeBlanketVertices(java.lang.Iterable<IndexedWord> verts)
public static java.util.List<SemanticGraphEdge> makeReplacedEdges(java.lang.Iterable<SemanticGraphEdge> edges, java.util.Map<IndexedWord,IndexedWord> vertReplacementMap, boolean useGenericReplacement)
public static java.util.Set<SemanticGraphEdge> allEdgesInSet(java.lang.Iterable<IndexedWord> vertices, SemanticGraph sg)
public static SemanticGraphUtils.EdgeDiffResult diffEdges(java.util.Collection<SemanticGraphEdge> edges1, java.util.Collection<SemanticGraphEdge> edges2, SemanticGraph sg1, SemanticGraph sg2, ISemanticGraphEdgeEql compareObj)
public static java.lang.String printEdges(java.lang.Iterable<SemanticGraphEdge> edges)
public static java.lang.String printVertices(SemanticGraph sg)
public static java.lang.String printVertices(SemanticGraph sg, SemanticGraphUtils.PrintVerticeParams params)
public static java.lang.String semgrexFromGraph(SemanticGraph sg, boolean matchTag, boolean matchWord, java.util.Map<IndexedWord,java.lang.String> nodeNameMap) throws java.lang.Exception
sg - SemanticGraph to base this pattern on.java.lang.Exceptionpublic static java.lang.String semgrexFromGraph(SemanticGraph sg, java.util.Collection<IndexedWord> wildcardNodes, boolean useTag, boolean useWord, java.util.Map<IndexedWord,java.lang.String> nodeNameMap) throws java.lang.Exception
java.lang.Exceptionpublic static java.lang.String semgrexFromGraph(SemanticGraph sg, java.util.Collection<IndexedWord> wildcardNodes, java.util.Map<IndexedWord,java.lang.String> nodeNameMap, java.util.function.Function<IndexedWord,java.lang.String> wordTransformation)
semgrexFromGraph
function implementations (if useWord and useTag is true, the value is "{word: vertex.word; tag: vertex.tag}").java.lang.Exceptionpublic static java.lang.String semgrexFromGraph(java.lang.Iterable<SemanticGraphEdge> edges, boolean matchTag, boolean matchWord, java.util.Map<IndexedWord,java.lang.String> nodeNameMap) throws java.lang.Exception
java.lang.Exceptionprotected static java.lang.String semgrexFromGraphHelper(IndexedWord vertice, SemanticGraph sg, java.util.Set<IndexedWord> tabu, java.util.Set<SemanticGraphEdge> seenEdges, boolean useWordAsLabel, boolean nameEdges, java.util.Collection<IndexedWord> wildcardNodes, java.util.Map<IndexedWord,java.lang.String> nodeNameMap, boolean orderedNodes, java.util.function.Function<IndexedWord,java.lang.String> nodeValuesTransformation)
semgrexFromGraph
function implementations.public static java.lang.String semgrexFromGraphOrderedNodes(SemanticGraph sg, java.util.Collection<IndexedWord> wildcardNodes, java.util.Map<IndexedWord,java.lang.String> nodeNameMap, java.util.function.Function<IndexedWord,java.lang.String> wordTransformation)
public static java.lang.String sanitizeForSemgrexName(java.lang.String text)
public static void lemmatize(SemanticGraph sg)
SemanticGraph, sets the lemmas on its label
objects based on their word and tag.public static SemanticGraph setSentIndex(SemanticGraph sg, int newSentIndex)
public static java.util.Collection<SemanticGraph> removeDuplicates(java.util.Collection<SemanticGraph> graphs)
public static java.util.Collection<SemanticGraph> removeDuplicates(java.util.Collection<SemanticGraph> graphs, java.util.Collection<SemanticGraph> tabuGraphs)
public static java.util.Collection<SemanticGraph> removeDuplicates(java.util.Collection<SemanticGraph> graphs, SemanticGraph tabuGraph)
public static java.util.Map<SemanticGraphUtils.PositionedTree,IndexedWord> mapTreeToSg(Tree tree, SemanticGraph sg)
public static boolean isTree(SemanticGraph sg)
sg -