Package edu.stanford.nlp.trees

Examples of edu.stanford.nlp.trees.GrammaticalRelation


      // search for the complement: pobj|pcomp(mwp1,X)
      for (TypedDependency td2 : list) {
        if (td2.gov().equals(mwp1) && td2.reln() == PREPOSITIONAL_OBJECT) {
          pobj = td2;
          // create the new gr relation
          GrammaticalRelation gr = EnglishGrammaticalRelations.getPrep(mwp[0] + '_' + mwp[1]);
          newTypedDeps.add(new TypedDependency(gr, governor, pobj.dep()));
        }
        if (td2.gov().equals(mwp1) && td2.reln() == PREPOSITIONAL_COMPLEMENT) {
          pobj = td2;
          // create the new gr relation
          GrammaticalRelation gr = EnglishGrammaticalRelations.getPrepC(mwp[0] + '_' + mwp[1]);
          newTypedDeps.add(new TypedDependency(gr, governor, pobj.dep()));
        }
      }

      if (pobj == null) {
View Full Code Here


          if (edge+n > edgePath.size())
            break;
          StringBuilder sbRelsHi = new StringBuilder();
          StringBuilder sbRelsLo = new StringBuilder();
          for (int elt = edge; elt < edge+n; elt++) {
            GrammaticalRelation gr = edgePath.get(elt).getRelation();
            sbRelsHi.append(generalizeRelation(gr));
            sbRelsHi.append("_");
            sbRelsLo.append(gr);
            sbRelsLo.append("_");
          }
View Full Code Here

  public static List<String> dependencyPathAsList(List<SemanticGraphEdge> edgePath, IndexedWord node, boolean generalize) {
    if(edgePath == null) return null;
    List<String> path = new ArrayList<String>();
    for (SemanticGraphEdge edge : edgePath) {
      IndexedWord nextNode;
      GrammaticalRelation relation;
      if (generalize) {
        relation = generalizeRelation(edge.getRelation());
      } else {
        relation = edge.getRelation();
      }
View Full Code Here

    SemanticGraph ccProcessed = document.get(CoreAnnotations.SentencesAnnotation.class).get(0)
                                        .get(
                                            SemanticGraphCoreAnnotations.CollapsedCCProcessedDependenciesAnnotation.class);
    Collection<TypedDependency> dependencies = ccProcessed.typedDependencies();

    GrammaticalRelation expected = EnglishGrammaticalRelations.getConj("and");
    assertThat(dependencies.stream().map(d -> d.reln()).collect(toList()),
        hasItem(expected));
  }
View Full Code Here

    if(dependency.getRoots().isEmpty()) return null;
    // root relation
    if(dependency.getFirstRoot().equals(headIndexedWord)) return "root";
    if(!dependency.containsVertex(dependency.getParent(headIndexedWord))) return null;
    GrammaticalRelation relation = dependency.reln(dependency.getParent(headIndexedWord), headIndexedWord);

    // adjunct relations
    if(relation.toString().startsWith("prep") || relation == EnglishGrammaticalRelations.PREPOSITIONAL_OBJECT || relation == EnglishGrammaticalRelations.TEMPORAL_MODIFIER || relation == EnglishGrammaticalRelations.ADV_CLAUSE_MODIFIER || relation == EnglishGrammaticalRelations.ADVERBIAL_MODIFIER || relation == EnglishGrammaticalRelations.PREPOSITIONAL_COMPLEMENT) return "adjunct";

    // subject relations
    if(relation == EnglishGrammaticalRelations.NOMINAL_SUBJECT || relation == EnglishGrammaticalRelations.CLAUSAL_SUBJECT) return "subject";
    if(relation == EnglishGrammaticalRelations.NOMINAL_PASSIVE_SUBJECT || relation == EnglishGrammaticalRelations.CLAUSAL_PASSIVE_SUBJECT) return "subject";
View Full Code Here

    if(headIndexedWord == null) return 0;

    int count = 0;
    List<Pair<GrammaticalRelation, IndexedWord>> childPairs = dependency.childPairs(headIndexedWord);
    for(Pair<GrammaticalRelation, IndexedWord> childPair : childPairs) {
      GrammaticalRelation gr = childPair.first;
      IndexedWord word = childPair.second;
      if(gr == EnglishGrammaticalRelations.ADJECTIVAL_MODIFIER || gr == EnglishGrammaticalRelations.VERBAL_MODIFIER ||
         gr == EnglishGrammaticalRelations.RELATIVE_CLAUSE_MODIFIER || gr.toString().startsWith("prep_")) {
        count++;
      }
      // add noun modifier when the mention isn't a NER
      if(nerString.equals("O") && gr == EnglishGrammaticalRelations.NOUN_COMPOUND_MODIFIER) {
        count++;
View Full Code Here

    }
    // check the parent
    List<Pair<GrammaticalRelation,IndexedWord>> parentPairs = dependency.parentPairs(headIndexedWord);
    if (!parentPairs.isEmpty()) {
      Pair<GrammaticalRelation,IndexedWord> parentPair = parentPairs.get(0);
      GrammaticalRelation gr = parentPair.first;
      // check negative prepositions
      if(dict.neg_relations.contains(gr.toString())) return 1;
    }
    return 0;
  }
View Full Code Here

   *
   * @param conjunctionString The conjunction to make a GrammaticalRelation out of
   * @return A grammatical relation for this conjunction
   */
  public static GrammaticalRelation getConj(String conjunctionString) {
    GrammaticalRelation result = conjs.get(conjunctionString);
    if (result == null) {
      result = new GrammaticalRelation(Language.English, "conj", "conj_collapsed", null, DEPENDENT, conjunctionString);
      conjs.put(conjunctionString, result);
      threadSafeAddRelation(result);
    }
    return result;
  }
View Full Code Here

   *
   * @param prepositionString The presposition to make a GrammaticalRelation out of
   * @return A grammatical relation for this presposition
   */
  public static GrammaticalRelation getPrep(String prepositionString) {
    GrammaticalRelation result = preps.get(prepositionString);
    if (result == null) {
      result = new GrammaticalRelation(Language.English, "prep", "prep_collapsed", null, DEPENDENT, prepositionString);
      preps.put(prepositionString, result);
      threadSafeAddRelation(result);
    }
    return result;
  }
View Full Code Here

   *
   * @param prepositionString The presposition to make a GrammaticalRelation out of
   * @return A grammatical relation for this presposition
   */
  public static GrammaticalRelation getPrepC(String prepositionString) {
    GrammaticalRelation result = prepsC.get(prepositionString);
    if (result == null) {
      result = new GrammaticalRelation(Language.English, "prepc", "prepc_collapsed", null, DEPENDENT, prepositionString);
      prepsC.put(prepositionString, result);
      threadSafeAddRelation(result);
    }
    return result;
  }
View Full Code Here

TOP

Related Classes of edu.stanford.nlp.trees.GrammaticalRelation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.