Suppose I have a semantic graph g
, and then I get its representation through the following two strings:
String sg = g.toCompactString();
String dp = g.typedDependencies().toString();
Suppose that these strings are now the only thing I have (the object g
is not visible anymore). Is it possible to create another object g2
which can use the strings sg
or dp
in some way in order to get the same object? Ideally, it would be great if CoreNLP provided a constructor for this, for example:
SemanticGraph g2 = new SemanticGraph(sg);
or
SemanticGraph g2 = new SemanticGraph(dp);
Any ideas how to do this in an efficient way?
Can you provide more context for your problem?
Are you trying to store the graph on disk and load it later and then rebuild the SemanticGraph? You'd probably be better off using the ProtobufAnnotationSerializer for that use case.
It would help to understand why you are losing access to the SemanticGraph.
If you really wanted to go from a String representation of an edges list to a SemanticGraph you'd have to rebuild the tokens from the String, build SemanticGraphEdges, and then you could use SemanticGraphFactory.makeFromEdges to build a SemanticGraph from a list of edges.
Classes you want to look at:
edu.stanford.nlp.ling.IndexedWord
edu.stanford.nlp.semgraph.SemanticGraphEdge
edu.stanford.nlp.semgraph.SemanticGraphFactory