/** * Recursive depth first traversal. Returns a structured representation of the * dependency graph. * * Example: * * <pre> * -> need-3 (root) * -> We-0 (nsubj) * -> do-1 (aux) * -> n't-2 (neg) * -> badges-6 (dobj) * -> no-4 (det) * -> stinking-5 (amod) * </pre> * * This is a quite ugly way to print a SemanticGraph. * You might instead want to try {@link #toString(OutputFormat)}. */ @Override public String toString() { return toString(CoreLabel.OutputFormat.VALUE_TAG); }
/** * Removes duplicate graphs from the set, using the string form of the graph * as the key (obviating issues with object equality). */ public static Collection<SemanticGraph> removeDuplicates(Collection<SemanticGraph> graphs) { Map<String, SemanticGraph> map = Generics.newHashMap(); for (SemanticGraph sg : graphs) { String keyVal = sg.toString().intern(); map.put(keyVal, sg); } return map.values(); }
/** * 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). */ public static Collection<SemanticGraph> removeDuplicates(Collection<SemanticGraph> graphs, Collection<SemanticGraph> tabuGraphs) { Map<String, SemanticGraph> tabuMap = Generics.newHashMap(); for (SemanticGraph tabuSg : tabuGraphs) { String keyVal = tabuSg.toString().intern(); tabuMap.put(keyVal, tabuSg); } Map<String, SemanticGraph> map = Generics.newHashMap(); for (SemanticGraph sg : graphs) { String keyVal = sg.toString().intern(); if (tabuMap.containsKey(keyVal)) continue; map.put(keyVal, sg); } return map.values(); }
public String toString(CoreLabel.OutputFormat wordFormat) { Collection<IndexedWord> rootNodes = getRoots(); if (rootNodes.isEmpty()) { // Shouldn't happen, but return something! return toString(OutputFormat.READABLE); } StringBuilder sb = new StringBuilder(); Set<IndexedWord> used = wordMapFactory.newSet(); for (IndexedWord root : rootNodes) { sb.append("-> ").append(root.toString(wordFormat)).append(" (root)\n"); recToString(root, wordFormat, sb, 1, used); } Set<IndexedWord> nodes = wordMapFactory.newSet(); nodes.addAll(vertexSet()); nodes.removeAll(used); while (!nodes.isEmpty()) { IndexedWord node = nodes.iterator().next(); sb.append(node.toString(wordFormat)).append("\n"); recToString(node, wordFormat, sb, 1, used); nodes.removeAll(used); } return sb.toString(); }
if (logPrefix != null) log.info(logPrefix); log.info("Pattern = '"+pattern.getUID()+"' generated "+generated.size()+" matches"); log.info("= = = = = = = = = =\nSrc graph:\n"+sg.toString()+"\n= = = = = = = = = =\n"); int index=1; for (SemanticGraph genSg : generated) { log.info("REWRITE "+(index++)); log.info(genSg.toString()); log.info(". . . . .\n");
System.out.println(sg.toString()); System.out.println(sg.toCompactString()); SemanticGraph g1 = SemanticGraphFactory.generateCollapsedDependencies(t); System.out.println("TEST SEMANTIC GRAPH - graph ----------------------------"); System.out.println(g1.toString()); System.out.println("readable ----------------------------"); System.out.println(g1.toString(SemanticGraph.OutputFormat.READABLE)); System.out.println("List of dependencies ----------------------------"); System.out.println(g1.toList()); System.out.println("xml ----------------------------"); System.out.println(g1.toString(SemanticGraph.OutputFormat.XML)); System.out.println("dot ----------------------------"); System.out.println(g1.toDotFormat());
return toList(); case RECURSIVE: return toString(); default: throw new IllegalArgumentException("Unsupported format " + format);
out.println(sentence.get(SemanticGraphCoreAnnotations.BasicDependenciesAnnotation.class).toString(SemanticGraph.OutputFormat.LIST)); sentNo++;
log.info("Matched graph:" + System.lineSeparator() + graph.toString(SemanticGraph.OutputFormat.LIST)); int i = 1; boolean found = true;
for (SemanticGraph genSg : generated) { log.info("REWRITE "+(index++)); log.info(genSg.toString()); log.info(". . . . .\n");
out.println(); out.println("The first sentence basic dependencies are:"); out.println(sentence.get(SemanticGraphCoreAnnotations.BasicDependenciesAnnotation.class).toString(SemanticGraph.OutputFormat.LIST)); out.println("The first sentence collapsed, CC-processed dependencies are:"); SemanticGraph graph = sentence.get(SemanticGraphCoreAnnotations.CollapsedCCProcessedDependenciesAnnotation.class); out.println(graph.toString(SemanticGraph.OutputFormat.LIST));
System.err.println(sg.toString(SemanticGraph.OutputFormat.READABLE));
logger.finer(srcMention.dependency.toString()); } catch (Exception e){} //throw new RuntimeException(e);} logger.finer("Parse:"); logger.finer("\nAntecedent:: -----------------------------------------------------"); try { logger.finer(dstMention.dependency.toString()); } catch (Exception e){} //throw new RuntimeException(e);} logger.finer("Parse:");
public static void main(String[] args) { String text; if (args.length > 0) { text = IOUtils.slurpFileNoExceptions(args[0], "utf-8"); } else { text = "I can almost always tell when movies use fake dinosaurs."; } Annotation ann = new Annotation(text); Properties props = PropertiesUtils.asProperties( "annotators", "tokenize,ssplit,pos,depparse", "depparse.model", DependencyParser.DEFAULT_MODEL ); AnnotationPipeline pipeline = new StanfordCoreNLP(props); pipeline.annotate(ann); for (CoreMap sent : ann.get(CoreAnnotations.SentencesAnnotation.class)) { SemanticGraph sg = sent.get(SemanticGraphCoreAnnotations.BasicDependenciesAnnotation.class); log.info(IOUtils.eolChar + sg.toString(SemanticGraph.OutputFormat.LIST)); } }
log.info(deps.toString(SemanticGraph.OutputFormat.LIST));
/** * Removes duplicate graphs from the set, using the string form of the graph * as the key (obviating issues with object equality). */ public static Collection<SemanticGraph> removeDuplicates(Collection<SemanticGraph> graphs) { Map<String, SemanticGraph> map = Generics.newHashMap(); for (SemanticGraph sg : graphs) { String keyVal = sg.toString().intern(); map.put(keyVal, sg); } return map.values(); }
/** * Removes duplicate graphs from the set, using the string form of the graph * as the key (obviating issues with object equality). */ public static Collection<SemanticGraph> removeDuplicates(Collection<SemanticGraph> graphs) { Map<String, SemanticGraph> map = Generics.newHashMap(); for (SemanticGraph sg : graphs) { String keyVal = sg.toString().intern(); map.put(keyVal, sg); } return map.values(); }
List<CoreMap> sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class); CoreMap sentence = (CoreMap) sentences.get(0); SemanticGraph graph = sentence.get(SemanticGraphCoreAnnotations.CollapsedCCProcessedDependenciesAnnotation.class); System.out.println(graph.toString("plain"));
private void topologicalSortHelper(IndexedWord vertex, Set<IndexedWord> temporary, Set<IndexedWord> permanent, List<IndexedWord> result) { temporary.add(vertex); for (SemanticGraphEdge edge : outgoingEdgeIterable(vertex)) { IndexedWord target = edge.getTarget(); if (permanent.contains(target)) { continue; } if (temporary.contains(target)) { throw new IllegalStateException("This graph has cycles. Topological sort not possible: " + this.toString()); } topologicalSortHelper(target, temporary, permanent, result); } result.add(vertex); permanent.add(vertex); }