Package edu.stanford.nlp.trees

Examples of edu.stanford.nlp.trees.GrammaticalRelation$GovernorGRAnnotation


      IndexedWord thisWord = new IndexedWord(tokens.get(i - 1));
      IndexedWord headWord = head == 0 ? root
                                       : new IndexedWord(tokens.get(head - 1));

      GrammaticalRelation relation = head == 0
                                     ? GrammaticalRelation.ROOT
                                     : makeGrammaticalRelation(label);

      dependencies.add(new TypedDependency(relation, headWord, thisWord));
    }
View Full Code Here


    TreeGraphNode rootNode = new TreeGraphNode(root);
    return makeGrammaticalStructure(dependencies, rootNode);
  }

  private GrammaticalRelation makeGrammaticalRelation(String label) {
    GrammaticalRelation stored;

    switch (language) {
      case English:
        stored = EnglishGrammaticalRelations.shortNameToGRel.get(label);
        if (stored != null)
          return stored;
        break;
      case Chinese:
        stored = ChineseGrammaticalRelations.shortNameToGRel.get(label);
        if (stored != null)
          return stored;
        break;
    }

    return new GrammaticalRelation(language, label, null, GrammaticalRelation.DEPENDENT);
  }
View Full Code Here

    buf.write(String.valueOf(weight));
    return buf.toString();
  }
 
  public static AddEdge createEngAddEdge(String govName, String depName, String engRelnName) {
    GrammaticalRelation reln = EnglishGrammaticalRelations.valueOf(engRelnName);
    return new AddEdge(govName, depName, reln);
  }
View Full Code Here

    GrammaticalRelation reln = EnglishGrammaticalRelations.valueOf(engRelnName);
    return new AddEdge(govName, depName, reln);
  }

  public static AddEdge createEngAddEdge(String govName, String depName, String engRelnName, double weight) {
    GrammaticalRelation reln = EnglishGrammaticalRelations.valueOf(engRelnName);
    return new AddEdge(govName, depName, reln, weight);
  }
View Full Code Here

  /**
   * Creates an EnglishGrammaticalRelation AddDep edit.
   * @param newNode String representation of new dependent IndexedFeatureNode map.
   */
  public static AddDep createEngAddDep(String govNodeName, String engRelation,  String newNode) {
    GrammaticalRelation relation = EnglishGrammaticalRelations.valueOf(engRelation);
//  IndexedWord newNodeObj = new IndexedWord(CoreLabel.fromAbstractMapLabel(IndexedFeatureLabel.valueOf(newNode, MapFactory.HASH_MAP_FACTORY)));
    IndexedWord newNodeObj = fromCheapString(newNode);
    return new AddDep(govNodeName, relation, newNodeObj);
  }
View Full Code Here

   */
  public static List<SemanticGraphEdge> edgesWithReln(Iterable<SemanticGraphEdge> edges,
                                                      GrammaticalRelation reln) {
    List<SemanticGraphEdge> found = Generics.newArrayList();
    for (SemanticGraphEdge edge : edges) {
      GrammaticalRelation tgtReln = edge.getRelation();
      if (tgtReln.equals(reln)) {
        found.add(edge);
      }
    }
    return found;
  }
View Full Code Here

   *
   */
  public static List<SemanticGraphEdge> findAllRelnsWithPrefix(SemanticGraph sg, String prefix) {
    ArrayList<SemanticGraphEdge> relns = new ArrayList<SemanticGraphEdge>();
    for (SemanticGraphEdge edge : sg.edgeIterable()) {
      GrammaticalRelation edgeRelation = edge.getRelation();
      if (edgeRelation.toString().startsWith(prefix)) {
        relns.add(edge);
      }
    }
    return relns;
  }
View Full Code Here

   * generated edges indeed do have collapsed preps as strings.
   */
  public static void enRepairEdges(SemanticGraph sg, boolean verbose) {
    for (SemanticGraphEdge edge : sg.edgeIterable()) {
      if (edge.getRelation().isFromString()) {
        GrammaticalRelation newReln =
          EnglishGrammaticalRelations.valueOf(edge.getRelation().toString());
        if (newReln != null) {
          IndexedWord gov = edge.getGovernor();
          IndexedWord dep = edge.getDependent();
          double weight = edge.getWeight();
View Full Code Here

          throw new RuntimeIOException("Failed to find node " + ie.target + "-" + ie.targetCopy);
        }
        assert(target != null);
        synchronized (LOCK) {
          // this is not thread-safe: there are static fields in GrammaticalRelation
          GrammaticalRelation rel = GrammaticalRelation.valueOf(ie.dep);
          graph.addEdge(source, target, rel, 1.0, ie.isExtra);
        }
      }
     
      // compute root nodes if they weren't stored in the graph
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) {
      synchronized(conjs) {
        result = conjs.get(conjunctionString);
        if (result == null) {
          result = new GrammaticalRelation(Language.English, "conj", "conj_collapsed", CONJUNCT, conjunctionString);
          conjs.put(conjunctionString, result);
          threadSafeAddRelation(result);
        }
      }
    }
View Full Code Here

TOP

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

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.