Java Code Examples for edu.stanford.nlp.semgraph.SemanticGraph#edgeListSorted()
The following examples show how to use
edu.stanford.nlp.semgraph.SemanticGraph#edgeListSorted() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StanfordRNNDParser.java From ambiverse-nlu with Apache License 2.0 | 6 votes |
@Override public void process(JCas jCas) throws AnalysisEngineProcessException { mappingProvider.configure(jCas.getCas()); DKPro2CoreNlp converter = new DKPro2CoreNlp(); Annotation annotatios = converter.convert(jCas, new Annotation()); List<CoreMap> sentences = annotatios.get(CoreAnnotations.SentencesAnnotation.class); for (CoreMap sentence : sentences) { GrammaticalStructure gs = parser.predict(sentence); SemanticGraph semanticGraph = SemanticGraphFactory.makeFromTree(gs, SemanticGraphFactory.Mode.CCPROCESSED, GrammaticalStructure.Extras.MAXIMAL, null);; semanticGraph.prettyPrint(); semanticGraph = semanticGraphUniversalEnglishToEnglish(semanticGraph); sentence.set(SemanticGraphCoreAnnotations.EnhancedDependenciesAnnotation.class, semanticGraph); for(SemanticGraphEdge edge: semanticGraph.edgeListSorted()) { System.out.println(edge); } } convertDependencies(jCas, annotatios, true); }
Example 2
Source File: ProcessConjunctions.java From ambiverse-nlu with Apache License 2.0 | 6 votes |
private static void removeUnnecessary(List<Constituent> result) { for (Constituent c : result) { SemanticGraph semanticGraph = ((IndexedConstituent) c).getSemanticGraph(); IndexedWord root = ((IndexedConstituent) c).getRoot(); List<SemanticGraphEdge> edges = semanticGraph.edgeListSorted(); Set<IndexedWord> descendants = semanticGraph.descendants(root); for (int i = 0; i < edges.size(); i++) { if (!descendants.contains(edges.get(i).getDependent())) { semanticGraph.removeEdge(edges.get(i)); edges = semanticGraph.edgeListSorted(); i--; } } } }
Example 3
Source File: StanfordRNNDParser.java From ambiverse-nlu with Apache License 2.0 | 5 votes |
public static SemanticGraph semanticGraphUniversalEnglishToEnglish(SemanticGraph semanticGraph) { for (SemanticGraphEdge edge: semanticGraph.edgeListSorted()) { GrammaticalRelation oldRel = edge.getRelation(); edge.setRelation(EnglishGrammaticalRelations.shortNameToGRel.get(oldRel.getShortName())); } return semanticGraph; }
Example 4
Source File: DpUtils.java From minie with GNU General Public License v3.0 | 5 votes |
/** * Remove the 'punct' edges * @param g -> Semantic graph gotten from the dependency parse */ public static void removePunctEdges(SemanticGraph semanticGraph){ for (SemanticGraphEdge edge : new ArrayList<>(semanticGraph.edgeListSorted())){ if (EnglishGrammaticalRelations.PUNCTUATION.equals(edge.getRelation())){ semanticGraph.removeEdge(edge); } } }
Example 5
Source File: CoreNLPUtils.java From minie with GNU General Public License v3.0 | 5 votes |
public static SemanticGraph semanticGraphUniversalEnglishToEnglish(SemanticGraph semanticGraph) { for (SemanticGraphEdge edge: semanticGraph.edgeListSorted()) { GrammaticalRelation oldRel = edge.getRelation(); edge.setRelation(EnglishGrammaticalRelations.shortNameToGRel.get(oldRel.getShortName())); } return semanticGraph; }