Java Code Examples for edu.stanford.nlp.semgraph.SemanticGraph#addEdge()

The following examples show how to use edu.stanford.nlp.semgraph.SemanticGraph#addEdge() . 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: Clause.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
private void connectHeads(SemanticGraph semanticGraph) {
  Constituent vc = constituents.get(verb);
  if(vc instanceof TextConstituent) {
    return;
  }
  IndexedConstituent vic  = (IndexedConstituent)vc;
  for (int i = 0; i < constituents.size(); i++) {
    if (i == verb || constituents.get(i) instanceof TextConstituent) {
      continue;
    }
    IndexedConstituent dic = (IndexedConstituent) constituents.get(i);
    semanticGraph.addEdge(vic.root, dic.root, GrammaticalRelation.DEPENDENT, 0.0, false);
  }
}
 
Example 2
Source File: DpUtils.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
public static void replaceNodeFromSemanticGraph(IndexedWord original, IndexedWord replace, SemanticGraph semanticGraph, boolean onlyIncoming) {
  List<SemanticGraphEdge> edgesToAdd = new ArrayList<>();
  edgesToAdd.addAll(semanticGraph.getIncomingEdgesSorted(original));
  if(!onlyIncoming) {
    edgesToAdd.addAll(semanticGraph.getOutEdgesSorted(original));
  }
  edgesToAdd.addAll(DpUtils.findAllRelationsOrDescendant(semanticGraph.getOutEdgesSorted(original), EnglishGrammaticalRelations.SUBJECT));
  edgesToAdd.addAll(DpUtils.findAllRelationsOrDescendant(semanticGraph.getOutEdgesSorted(original), EnglishGrammaticalRelations.COPULA));
  Set<GrammaticalRelation> relations = DpUtils.getIncommingRelations(replace, semanticGraph);
  for(SemanticGraphEdge edge: edgesToAdd) {
    IndexedWord governor = replace;
    IndexedWord dependent = edge.getDependent();
    if(edge.getGovernor().equals(original)) {
      governor = replace;
      dependent = edge.getDependent();
    } else {
      if(relations.contains(edge.getRelation())) {
        continue;
      }
      governor = edge.getGovernor();
      dependent = replace;
    }
    semanticGraph.addEdge(governor, dependent, edge.getRelation(), edge.getWeight(), edge.isExtra());
  }
  if(semanticGraph.getRoots().contains(original)) {
    semanticGraph.resetRoots();
    semanticGraph.setRoot(replace);
  }
  disconectNodeFromSemanticGraph(original, semanticGraph);
}
 
Example 3
Source File: ClauseDetector.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
/** 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 4
Source File: ProcessConjunctions.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
private static void addEdges(List<SemanticGraphEdge> outEdgesSorted, IndexedWord governor, SemanticGraph semanticGraph) {
  Set<GrammaticalRelation> relations = collectRelations(outEdgesSorted);
  Set<GrammaticalRelation> noRelations = collectRelations(semanticGraph.getOutEdgesSorted(governor));
  relations.removeAll(noRelations);
  for(SemanticGraphEdge edge: outEdgesSorted) {
    if(!relations.contains(edge.getRelation())) {
      continue;
    }
    SemanticGraphEdge nedge = new SemanticGraphEdge(governor, edge.getDependent(), edge.getRelation(), edge.getWeight(), edge.isExtra());
    semanticGraph.addEdge(nedge);
  }
}
 
Example 5
Source File: ClauseDetector.java    From minie with GNU General Public License v3.0 5 votes vote down vote up
/** 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);
}