public class SGraph extends Object
Constructor and Description |
---|
SGraph()
Creates an empty s-graph.
|
Modifier and Type | Method and Description |
---|---|
GraphNode |
addAnonymousNode(String label)
Adds an "anonymous" node with the given label to the s-graph.
|
GraphEdge |
addEdge(GraphNode src,
GraphNode tgt,
String label)
Adds an edge with the given label between the two nodes to the s-graph.
|
GraphNode |
addNode(String name,
String label)
Adds a node with the given name and label to the s-graph.
|
void |
addSource(String sourceName,
String nodename)
Designates the node with the given name as the source for the
given source name.
|
boolean |
containsAsSubgraph(org.jgrapht.DirectedGraph<GraphNode,GraphEdge> subgraph,
Map<String,String> nodeRenaming)
Checks whether the s-graph contains the given graph as a sub-graph.
|
boolean |
containsNode(String name)
Checks if a node with the given name exists in this s-graph.
|
boolean |
equals(Object obj)
Checks whether this graph is equal to another.
|
void |
foreachMatchingSubgraph(SGraph subgraph,
Consumer<SGraph> fn)
Applies the given function "fn" to all sub-s-graphs of this s-graph
that match the given "subgraph".
|
SGraph |
forgetSourcesExcept(Set<String> retainedSources)
Forgets all sources except for the specified set.
|
Collection<String> |
getAllNodeNames()
Returns the collection of all node names in this s-graph.
|
Iterable<String> |
getAllNonSourceNodenames()
Returns the set of all node names of this s-graph that
are not sources.
|
Iterable<String> |
getAllSourceNodenames()
Returns the set of all node names of this s-graph that
are an "a"-source for any source "a".
|
Set<String> |
getAllSources()
Returns the set of all source names in this s-graph (e.g.
|
org.jgrapht.DirectedGraph<GraphNode,GraphEdge> |
getGraph()
Returns the graph underlying this s-graph.
|
List<SGraph> |
getMatchingSubgraphs(SGraph subgraph)
Returns a list of matching subgraphs.
|
GraphNode |
getNode(String name)
Returns the node in this s-graph with the given name.
|
String |
getNodeForSource(String sourceName)
Returns the node for the given source name.
|
String |
getSourceLabel(String nodename)
Returns a string representation of the source status
of the given node.
|
Collection<String> |
getSourcesAtNode(String nodename)
Returns a collection containing all the source names
for which the given node is a source.
|
static String |
graphToString(org.jgrapht.DirectedGraph<GraphNode,GraphEdge> graph)
Returns a string representation of the graph.
|
boolean |
hasCommonSource(SGraph other)
Checks whether two s-graphs have a source name in common.
|
int |
hashCode()
Computes a hash code for the s-graph.
|
boolean |
hasLabelledNode()
Returns true iff at least one node in the graph has a label.
|
boolean |
isIdentical(SGraph other)
Checks whether this graph is identical to the other graph.
|
boolean |
isIdenticalExceptSources(SGraph other)
Checks whether this graph is identical to the other graph, ignoring source assignments.
|
boolean |
isIsomorphic(SGraph other)
Checks whether two s-graphs are isomorphic.
|
boolean |
isIsomorphicAlsoEdges(SGraph other)
Checks whether two s-graphs are isomorphic.
|
boolean |
isSourceNode(String nodename)
Checks if the node with the given name is a source.
|
SGraph |
merge(SGraph other)
Merges this s-graph with another s-graph.
|
int |
nodeCount() |
boolean |
nodenamesForSourcesAgree(SGraph other)
Checks whether two s-graphs have consistent node names for the sources.
|
boolean |
overlapsOnlyInSources(SGraph other)
Checks whether two s-graphs have any nodes in common that are not sources.
|
SGraph |
renameSource(String oldName,
String newName)
Renames a source in this s-graph to another source name.
|
void |
setEqualsMeansIsomorphy(boolean equalsMeansIsomorphy)
Controls whether equality on this s-graph should be checked
using identity or isomorphy.
|
SGraph |
swapSources(String sourceName1,
String sourceName2) |
String |
toIsiAmrString()
Returns a string representation of this s-graph in the format
of the ISI AMR-Bank.
|
String |
toString()
Returns a string representation of this s-graph.
|
SGraph |
withFreshNodenames()
Returns a copy in this s-graph in which all node names have been
assigned fresh names.
|
public GraphNode addNode(String name, String label)
name
- label
- public GraphNode addAnonymousNode(String label)
label
- public GraphEdge addEdge(GraphNode src, GraphNode tgt, String label)
src
- tgt
- label
- public void addSource(String sourceName, String nodename)
sourceName
- nodename
- public String getNodeForSource(String sourceName)
sourceName
- public GraphNode getNode(String name)
name
- public Collection<String> getAllNodeNames()
public boolean containsNode(String name)
name
- public boolean hasLabelledNode()
public SGraph merge(SGraph other)
This method returns a new s-graph object; the two original s-graphs are not modified. It renames the nodes of the "other" s-graph to fresh node names to avoid accidental fusing of nodes.
other
- public SGraph renameSource(String oldName, String newName)
This method returns a new s-graph object; the original s-graph is not modified.
oldName
- newName
- public SGraph forgetSourcesExcept(Set<String> retainedSources)
retainedSources
- public Set<String> getAllSources()
public Iterable<String> getAllSourceNodenames()
public Iterable<String> getAllNonSourceNodenames()
getAllNonSourceNodenames()
.public SGraph withFreshNodenames()
public org.jgrapht.DirectedGraph<GraphNode,GraphEdge> getGraph()
library at http://jgrapht.org/
public boolean isSourceNode(String nodename)
nodename
- public String getSourceLabel(String nodename)
nodename
- public Collection<String> getSourcesAtNode(String nodename)
nodename
- public String toIsiAmrString()
public static String graphToString(org.jgrapht.DirectedGraph<GraphNode,GraphEdge> graph)
graph
- nra
- public String toString()
public void setEqualsMeansIsomorphy(boolean equalsMeansIsomorphy)
equalsMeansIsomorphy
- equals(java.lang.Object)
public boolean equals(Object obj)
setEqualsMeansIsomorphy(boolean)
.
If "equals means isomorphy" is set to false, then equality is checked
by verifying that the two s-graphs have the same set of node names,
each node has the same label, any two nodes are connected by edges
with the same edge label, and all the sources are the same.If "equals means isomorphy" is set to true (the default), the equality check first looks for an isomorphic mapping between the node names of the two s-graphs, and then checks for node labels, edges, and sources relative to this mapping. In other words, this mode ignores node names.
public boolean isIdentical(SGraph other)
equals(java.lang.Object)
in the mode where "equals means isomorphy" is set to false.other
- public boolean isIdenticalExceptSources(SGraph other)
other
- public boolean overlapsOnlyInSources(SGraph other)
other
- public boolean nodenamesForSourcesAgree(SGraph other)
other
- public boolean containsAsSubgraph(org.jgrapht.DirectedGraph<GraphNode,GraphEdge> subgraph, Map<String,String> nodeRenaming)
subgraph
- nodeRenaming
- public List<SGraph> getMatchingSubgraphs(SGraph subgraph)
subgraph
- foreachMatchingSubgraph(de.up.ling.irtg.algebra.graph.SGraph, java.util.function.Consumer)
public void foreachMatchingSubgraph(SGraph subgraph, Consumer<SGraph> fn)
subgraph
- fn
- public boolean isIsomorphic(SGraph other)
equals(java.lang.Object)
in the mode where
"equals means isomorphy" is true. Does not check edge labels.other
- public boolean isIsomorphicAlsoEdges(SGraph other)
equals(java.lang.Object)
in the mode where
"equals means isomorphy" is true. Also compares whether edges are
labelled equally.other
- public int hashCode()
equals(java.lang.Object)
in this class. However, it is a very weak implementation in that many
s-graphs that are actually not equals will have the same hash code.
One should therefore avoid actually using HashMaps or HashSets of s-graphs,
because performance will be poor.public boolean hasCommonSource(SGraph other)
other
- public int nodeCount()
Copyright © 2017. All rights reserved.