Java Code Examples for edu.stanford.nlp.semgraph.SemanticGraph#removeEdge()
The following examples show how to use
edu.stanford.nlp.semgraph.SemanticGraph#removeEdge() .
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: 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 2
Source File: DpUtils.java From ambiverse-nlu with Apache License 2.0 | 5 votes |
/** Removes some edges from the given semantic graph. * * This method traverses the semantic graph starting from the given root. An edge is removed if * (1) its child appears in <code>excludeVertexes</code>, (2) its relation appears in * <code>excludeRelations</code>, or (3) the edge has the root as parent and its relation * appears in <code>excludeRelationsTop</code>. */ public static void removeEdges(SemanticGraph graph, IndexedWord root, Collection<IndexedWord> excludeVertexes, Collection<GrammaticalRelation> excludeRelations, Collection<GrammaticalRelation> excludeRelationsTop) { if (!excludeVertexes.contains(root)) { List<SemanticGraphEdge> edgesToRemove = new ArrayList<SemanticGraphEdge>(); subgraph(graph, root, excludeVertexes, excludeRelations, excludeRelationsTop, edgesToRemove); for (SemanticGraphEdge edge : edgesToRemove) { graph.removeEdge(edge); } } }
Example 3
Source File: DpUtils.java From ambiverse-nlu with Apache License 2.0 | 5 votes |
public static void disconectNodeFromSemanticGraph(IndexedWord node, SemanticGraph semanticGraph) { List<SemanticGraphEdge> edgesToRemove = new ArrayList<>(); edgesToRemove.addAll(semanticGraph.getIncomingEdgesSorted(node)); edgesToRemove.addAll(semanticGraph.outgoingEdgeList(node)); for(SemanticGraphEdge edge: edgesToRemove) { semanticGraph.removeEdge(edge); } }
Example 4
Source File: DpUtils.java From ambiverse-nlu with Apache License 2.0 | 5 votes |
/** Disconnects independent clauses by removing the edge representing the coordinating conjunction */ public static void disconectClauses(SemanticGraph graph, Constituent constituent) { List<SemanticGraphEdge> outedges = graph.getOutEdgesSorted(((IndexedConstituent) constituent).getRoot()); for (int i = 0; i < outedges.size(); i++) { SemanticGraphEdge e = outedges.get(i); if (DpUtils.isAnyConj(e)) { IndexedWord child = e.getDependent(); List<SemanticGraphEdge> outNewRoot = graph.getOutEdgesSorted(child); SemanticGraphEdge sub = DpUtils.findFirstOfRelationOrDescendent(outNewRoot, EnglishGrammaticalRelations.SUBJECT); if (sub != null) graph.removeEdge(e); } } }
Example 5
Source File: ClauseDetector.java From ambiverse-nlu with Apache License 2.0 | 5 votes |
/** Creates a constituent for a possessive relative clause * @param semanticGraph The semantic graph * @param poss The edge referring to the possessive relation * @param rcmod The relative clause modifier of the relation * @param constGovernor The root of the constituent * @param type The type of the constituent*/ private static Constituent createPossConstituent(SemanticGraph semanticGraph, SemanticGraphEdge poss, SemanticGraphEdge rcmod, IndexedWord constGovernor, Type type) { SemanticGraph newSemanticGraph = new SemanticGraph(semanticGraph); double weight = poss.getWeight(); newSemanticGraph.addEdge(poss.getGovernor(), rcmod.getGovernor(), EnglishGrammaticalRelations.POSSESSION_MODIFIER, weight, false); Set<IndexedWord> exclude = DpUtils.exclude(newSemanticGraph, EXCLUDE_RELATIONS_COMPLEMENT, rcmod.getGovernor()); newSemanticGraph.removeEdge(poss); newSemanticGraph.removeEdge(rcmod); return new IndexedConstituent(newSemanticGraph, constGovernor, Collections.<IndexedWord>emptySet(), exclude, type); }
Example 6
Source File: DpUtils.java From minie with GNU General Public License v3.0 | 5 votes |
/** Removes some edges from the given semantic graph. * * This method traverses the semantic graph starting from the given root. An edge is removed if * (1) its child appears in <code>excludeVertexes</code>, (2) its relation appears in * <code>excludeRelations</code>, or (3) the edge has the root as parent and its relation * appears in <code>excludeRelationsTop</code>. */ public static void removeEdges(SemanticGraph graph, IndexedWord root, Collection<IndexedWord> excludeVertexes, Collection<GrammaticalRelation> excludeRelations, Collection<GrammaticalRelation> excludeRelationsTop) { if (!excludeVertexes.contains(root)) { Set<SemanticGraphEdge> edgesToRemove = new HashSet<SemanticGraphEdge>(); subgraph(graph, root, excludeVertexes, excludeRelations, excludeRelationsTop, edgesToRemove, 0); for (SemanticGraphEdge edge : edgesToRemove) { graph.removeEdge(edge); } } }
Example 7
Source File: DpUtils.java From minie with GNU General Public License v3.0 | 5 votes |
/** Disconnects independent clauses by removing the edge representing the coordinating conjunction */ public static void disconectClauses(SemanticGraph graph, Constituent constituent) { List<SemanticGraphEdge> outedges = graph.getOutEdgesSorted(((IndexedConstituent) constituent).getRoot()); for (int i = 0; i < outedges.size(); i++) { SemanticGraphEdge e = outedges.get(i); if (DpUtils.isAnyConj(e)) { IndexedWord child = e.getDependent(); List<SemanticGraphEdge> outNewRoot = graph.getOutEdgesSorted(child); SemanticGraphEdge sub = DpUtils.findFirstOfRelationOrDescendent(outNewRoot, EnglishGrammaticalRelations.SUBJECT); if (sub != null) graph.removeEdge(e); } } }
Example 8
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 9
Source File: ClauseDetector.java From minie with GNU General Public License v3.0 | 5 votes |
/** Creates a constituent for a possessive relative clause * @param semanticGraph The semantic graph * @param poss The edge referring to the possessive relation * @param rcmod The relative clause modifier of the relation * @param constGovernor The root of the constituent * @param type The type of the constituent */ private static Constituent createPossConstituent(SemanticGraph semanticGraph, SemanticGraphEdge poss, SemanticGraphEdge rcmod, IndexedWord constGovernor, Type type) { SemanticGraph newSemanticGraph = new SemanticGraph(semanticGraph); double weight = poss.getWeight(); newSemanticGraph.addEdge(poss.getGovernor(), rcmod.getGovernor(), EnglishGrammaticalRelations.POSSESSION_MODIFIER, weight, false); Set<IndexedWord> exclude = DpUtils.exclude(newSemanticGraph, EXCLUDE_RELATIONS_COMPLEMENT, rcmod.getGovernor()); newSemanticGraph.removeEdge(poss); newSemanticGraph.removeEdge(rcmod); return new IndexedConstituent(newSemanticGraph, constGovernor, Collections.<IndexedWord> emptySet(), exclude, type); }
Example 10
Source File: DpUtils.java From ambiverse-nlu with Apache License 2.0 | 4 votes |
public static void removeEdges(SemanticGraph semanticGraph, List<SemanticGraphEdge> edges) { for(SemanticGraphEdge edge: edges) { semanticGraph.removeEdge(edge); } }