Package edu.stanford.nlp.trees

Examples of edu.stanford.nlp.trees.Tree


   * TueBa-D/Z adaptation. Fixes trees with non-unary roots, does nothing else.
   */
  @Override
  public Tree normalizeWholeTree(Tree tree, TreeFactory tf) {
    if (tree.label().value().equals(root) && tree.children().length > 1) {
      Tree underRoot = tree.treeFactory().newTreeNode(root, tree.getChildrenAsList());
      tree.setChildren(new Tree[1]);
      tree.setChild(0, underRoot);

    }
    // we just want the non-unary root fixed.
View Full Code Here


  private void findTreePattern(Tree tree, TregexPattern tgrepPattern, Set<Pair<Integer, Integer>> foundPairs) {
    try {
      TregexMatcher m = tgrepPattern.matcher(tree);
      while (m.find()) {
        Tree t = m.getMatch();
        Tree np1 = m.getNode("m1");
        Tree np2 = m.getNode("m2");
        Tree np3 = null;
        if(tgrepPattern.pattern().contains("m3")) np3 = m.getNode("m3");
        addFoundPair(np1, np2, t, foundPairs);
        if(np3!=null) addFoundPair(np2, np3, t, foundPairs);
      }
    } catch (Exception e) {
View Full Code Here

    public double score(Tree tree) {
      double totalScore = 0.0;
      for (DVParserCostAndGradient scorer : scorers) {
        IdentityHashMap<Tree, SimpleMatrix> nodeVectors = Generics.newIdentityHashMap();
        Tree transformedTree = transformer.transformTree(tree);
        if (op.trainOptions.useContextWords) {
          Trees.convertToCoreLabels(transformedTree);
          transformedTree.setSpans();
        }
        double score = scorer.score(transformedTree, nodeVectors);
        totalScore += score;
        //totalScore = Math.max(totalScore, score);
      }
View Full Code Here

    }
  }

  private void addFoundPair(Tree np1, Tree np2, Tree t,
      Set<Pair<Integer, Integer>> foundPairs) {
    Tree head1 = np1.headTerminal(headFinder);
    Tree head2 = np2.headTerminal(headFinder);
    int h1 = ((CoreMap) head1.label()).get(CoreAnnotations.IndexAnnotation.class) - 1;
    int h2 = ((CoreMap) head2.label()).get(CoreAnnotations.IndexAnnotation.class) - 1;
    Pair<Integer, Integer> p = new Pair<Integer, Integer>(h1, h2);
    foundPairs.add(p);
  }
View Full Code Here

    if(thisFirst == first && thisLast == last) {
      return tree;
    } else {
      Tree [] kids = tree.children();
      for(Tree k: kids){
        Tree t = findExactMatch(k, first, last);
        if(t != null) return t;
      }
    }
    return null;
  }
View Full Code Here

      throw new RuntimeException(e);
    }
    if (!(o instanceof Tree)) {
      throw new IllegalArgumentException("Expected a tree");
    }
    Tree tree = (Tree) o;

    socket.close();
    return tree;
  }
View Full Code Here

    LexicalizedParserClient client =
      new LexicalizedParserClient("localhost",
                                  LexicalizedParserServer.DEFAULT_PORT);
    String query = "John Bauer works at Stanford.";
    System.out.println(query);
    Tree tree = client.getTree(query);
    System.out.println(tree);
    String results = client.getParse(query, false);
    System.out.println(results);
  }
View Full Code Here

  /** Divides a sentence into clauses and sorts the antecedents for pronoun matching. */
  private static List<Mention> sortMentionsForPronoun(List<Mention> l, Mention m1, boolean sameSentence) {
    List<Mention> sorted = new ArrayList<Mention>();
    if (sameSentence) {
      Tree tree = m1.contextParseTree;
      Tree current = m1.mentionSubTree;
      current = current.parent(tree);
      while (current != null) {
        if (current.label().value().startsWith("S")) {
          for (Mention m : l) {
            if (!sorted.contains(m) && current.dominates(m.mentionSubTree)) {
              sorted.add(m);
            }
          }
        }
        current = current.parent(tree);
      }
      if (SieveCoreferenceSystem.logger.isLoggable(Level.FINEST)) {
        if (l.size()!=sorted.size()) {
          SieveCoreferenceSystem.logger.finest("sorting failed!!! -> parser error?? \tmentionID: "+m1.mentionID+" " + m1.spanToString());
          sorted = l;
View Full Code Here

      this.deepTrees = Generics.newArrayList();
    }
   
    public double score(Tree tree) {
      IdentityHashMap<Tree, SimpleMatrix> nodeVectors = Generics.newIdentityHashMap();
      Tree transformedTree = transformer.transformTree(tree);
      if (op.trainOptions.useContextWords) {
        Trees.convertToCoreLabels(transformedTree);
        transformedTree.setSpans();
      }
      double score = scorer.score(transformedTree, nodeVectors);
      deepTrees.add(new DeepTree(tree, nodeVectors, score));
      return score;
    }
View Full Code Here

    // See if there is a constraint whose boundaries match the end
    // points of the top node on the stack.  If so, we can apply a
    // UnaryTransition / CompoundUnaryTransition if that would solve
    // the constraint
    if (constraints != null) {
      final Tree top = state.stack.peek();
      for (ParserConstraint constraint : constraints) {
        if (ShiftReduceUtils.leftIndex(top) != constraint.start || ShiftReduceUtils.rightIndex(top) != constraint.end - 1) {
          continue;
        }
        if (ShiftReduceUtils.constraintMatchesTreeTop(top, constraint)) {
View Full Code Here

TOP

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

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.