edu.stanford.nlp.trees.semgraph
Class SemanticGraphFactory

java.lang.Object
  extended by edu.stanford.nlp.trees.semgraph.SemanticGraphFactory

public class SemanticGraphFactory
extends java.lang.Object

Refactoring of static makers of SemanticGraphs in order to simplify the SemanticGraph class.

Author:
rafferty

Method Summary
static SemanticGraph allTypedDependencies(Tree tree, boolean collapse)
          Returns a new SemanticGraph constructed from the given tree.
static SemanticGraph deepCopyFromGraphs(java.util.List<SemanticGraph> graphs, java.util.List<java.lang.Integer> lengths)
          Like makeFromGraphs, but it makes a deep copy of the graphs and renumbers the index words.
static SemanticGraph duplicateKeepNodes(SemanticGraph sg)
          This creates a new graph based off the given, but uses the existing nodes objects.
static java.util.Set<IndexedWord> getVerticesFromEdgeSet(java.lang.Iterable<SemanticGraphEdge> edges)
          Given an iterable set of edges, returns the set of vertices covered by these edges.
static SemanticGraph makeFromEdges(java.lang.Iterable<SemanticGraphEdge> edges)
          Given a list of edges, attempts to create and return a rooted SemanticGraph.
static SemanticGraph makeFromGraphs(java.util.Collection<SemanticGraph> sgList)
          Given a list of graphs, constructs a new graph combined from the collection of graphs.
static SemanticGraph makeFromTree(GrammaticalStructure gs, boolean collapse, boolean tree, boolean ccProcess, boolean includeExtras, boolean lemmatize, boolean threadSafe, Filter<TypedDependency> filter, java.lang.String docID, int sentIndex)
           
static SemanticGraph makeFromTree(GrammaticalStructure structure, java.lang.String docID, int sentIndex)
           
static SemanticGraph makeFromTree(Tree tree)
          Returns a new SemanticGraph constructed from the given tree.
static SemanticGraph makeFromTree(Tree tree, boolean collapse)
          Returns a new SemanticGraph constructed from the given tree.
static SemanticGraph makeFromTree(Tree tree, boolean collapse, boolean ccProcess, boolean includeExtras, boolean lemmatize, boolean threadSafe)
           
static SemanticGraph makeFromTree(Tree tree, boolean collapse, boolean ccProcess, boolean includeExtras, boolean lemmatize, boolean threadSafe, Filter<TypedDependency> filter)
          Returns a new SemanticGraph constructed from a given Tree with given options.
static SemanticGraph makeFromTree(Tree tree, boolean collapse, boolean ccProcess, boolean includeExtras, boolean lemmatize, boolean threadSafe, Filter<TypedDependency> filter, java.lang.String docID, int sentIndex)
          Returns a new SemanticGraph constructed from a given Tree with given options.
static SemanticGraph makeFromTree(Tree tree, boolean collapse, boolean ccProcess, boolean includeExtras, Filter<TypedDependency> filter)
           
static SemanticGraph makeFromVertices(SemanticGraph sg, java.util.Collection<IndexedWord> nodes)
          Given a set of vertices, and the source graph they are drawn from, create a path composed of the minimum paths between the vertices.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

makeFromTree

public static SemanticGraph makeFromTree(Tree tree,
                                         boolean collapse,
                                         boolean ccProcess,
                                         boolean includeExtras,
                                         boolean lemmatize,
                                         boolean threadSafe,
                                         Filter<TypedDependency> filter)
Returns a new SemanticGraph constructed from a given Tree with given options.

This factory method is intended to replace a profusion of highly similar factory methods, such as typedDependencies(), typedDependenciesCollapsed(), allTypedDependencies(), allTypedDependenciesCollapsed(), etc.

For a fuller explanation of the meaning of the boolean arguments, see GrammaticalStructure.

Parameters:
tree - A tree representing a phrase structure parse
collapse - Whether to do "collapsing" of pairs of dependencies into single dependencies, e.g., for prepositions and conjunctions
ccProcess - Whether to do processing of CC complements resulting from collapsing. This argument is ignored unless collapse is true
includeExtras - Whether to include extra dependencies, which may result in a non-tree
lemmatize - Whether to compute lemma for each node
threadSafe - Whether to make sure processing is thread-safe
filter - A filter to exclude certain dependencies; ignored if null
Returns:
A SemanticGraph

makeFromTree

public static SemanticGraph makeFromTree(Tree tree,
                                         boolean collapse,
                                         boolean ccProcess,
                                         boolean includeExtras,
                                         boolean lemmatize,
                                         boolean threadSafe,
                                         Filter<TypedDependency> filter,
                                         java.lang.String docID,
                                         int sentIndex)
Returns a new SemanticGraph constructed from a given Tree with given options.

This factory method is intended to replace a profusion of highly similar factory methods, such as typedDependencies(), typedDependenciesCollapsed(), allTypedDependencies(), allTypedDependenciesCollapsed(), etc.

For a fuller explanation of the meaning of the boolean arguments, see GrammaticalStructure.

Parameters:
tree - A tree representing a phrase structure parse
collapse - Whether to do "collapsing" of pairs of dependencies into single dependencies, e.g., for prepositions and conjunctions
ccProcess - Whether to do processing of CC complements resulting from collapsing. This argument is ignored unless collapse is true
includeExtras - Whether to include extra dependencies, which may result in a non-tree
lemmatize - Whether to compute lemma for each node
threadSafe - Whether to make sure processing is thread-safe
filter - A filter to exclude certain dependencies; ignored if null
docID - The docID that the tree came from
sentIndex - The sentence number of the tree in the document
Returns:
A SemanticGraph

makeFromTree

public static SemanticGraph makeFromTree(GrammaticalStructure gs,
                                         boolean collapse,
                                         boolean tree,
                                         boolean ccProcess,
                                         boolean includeExtras,
                                         boolean lemmatize,
                                         boolean threadSafe,
                                         Filter<TypedDependency> filter,
                                         java.lang.String docID,
                                         int sentIndex)

makeFromTree

public static SemanticGraph makeFromTree(GrammaticalStructure structure,
                                         java.lang.String docID,
                                         int sentIndex)

makeFromTree

public static SemanticGraph makeFromTree(Tree tree,
                                         boolean collapse,
                                         boolean ccProcess,
                                         boolean includeExtras,
                                         Filter<TypedDependency> filter)

makeFromTree

public static SemanticGraph makeFromTree(Tree tree,
                                         boolean collapse,
                                         boolean ccProcess,
                                         boolean includeExtras,
                                         boolean lemmatize,
                                         boolean threadSafe)

makeFromTree

public static SemanticGraph makeFromTree(Tree tree,
                                         boolean collapse)
Returns a new SemanticGraph constructed from the given tree. Dependencies are collapsed according to the parameter "collapse", and extra dependencies are not included

Parameters:
tree - tree from which to make new semantic graph
collapse - collapse dependencies iff this parameter is true

makeFromTree

public static SemanticGraph makeFromTree(Tree tree)
Returns a new SemanticGraph constructed from the given tree. Dependencies are collapsed, and extra dependencies are not included (convenience method for makeFromTree(Tree tree, boolean collapse))


allTypedDependencies

public static SemanticGraph allTypedDependencies(Tree tree,
                                                 boolean collapse)
Returns a new SemanticGraph constructed from the given tree. Collapsing of dependencies is performed according to "collapse". The list includes extra dependencies which do not respect a tree structure of the dependencies.

(Internally, this invokes (@link edu.stanford.nlp.trees.GrammaticalStructure#allTypedDependencies() GrammaticalStructure.allTypedDependencies()).)

Parameters:
tree - tree from which to make new semantic graph
collapse - collapse dependencies iff this parameter is true

makeFromEdges

public static SemanticGraph makeFromEdges(java.lang.Iterable<SemanticGraphEdge> edges)
Given a list of edges, attempts to create and return a rooted SemanticGraph.

TODO: throw Exceptions, or flag warnings on conditions for concern (no root, etc)


getVerticesFromEdgeSet

public static java.util.Set<IndexedWord> getVerticesFromEdgeSet(java.lang.Iterable<SemanticGraphEdge> edges)
Given an iterable set of edges, returns the set of vertices covered by these edges.

Note: CDM changed the return of this from a List to a Set in 2011. This seemed more sensible. Hopefully it doesn't break anything....


makeFromVertices

public static SemanticGraph makeFromVertices(SemanticGraph sg,
                                             java.util.Collection<IndexedWord> nodes)
Given a set of vertices, and the source graph they are drawn from, create a path composed of the minimum paths between the vertices. i.e. this is a simple brain-dead attempt at getting something approximating a minimum spanning graph. NOTE: the hope is the vertices will already be contiguous, but facilities are added just in case for adding additional nodes.


duplicateKeepNodes

public static SemanticGraph duplicateKeepNodes(SemanticGraph sg)
This creates a new graph based off the given, but uses the existing nodes objects.


makeFromGraphs

public static SemanticGraph makeFromGraphs(java.util.Collection<SemanticGraph> sgList)
Given a list of graphs, constructs a new graph combined from the collection of graphs. Original vertices are used, edges are copied. Graphs are ordered by the sentence index and index of the original vertices. Intent is to create a "mega graph" similar to the graphs used in the RTE problem.
This method only works if the indexed words have different sentence ids, as otherwise the maps used will confuse several of the IndexedWords.


deepCopyFromGraphs

public static SemanticGraph deepCopyFromGraphs(java.util.List<SemanticGraph> graphs,
                                               java.util.List<java.lang.Integer> lengths)
Like makeFromGraphs, but it makes a deep copy of the graphs and renumbers the index words.
lengths must be a vector containing the number of tokens in each sentence. This is used to reindex the tokens.



Stanford NLP Group