Package edu.stanford.nlp.trees

Examples of edu.stanford.nlp.trees.Tree$TreeIterator


    final Iterator<Tree> goldItr = goldTreebank.iterator();
    int goldLineId = 0;
    int skippedGuessTrees = 0;

    for(final Tree guess : guessTreebank) {
      final Tree evalGuess = tc.transformTree(guess);
      if(guess.yield().size() > MAX_GUESS_YIELD) {
        skippedGuessTrees++;
        continue;
      }

      boolean doneEval = false;
      while(goldItr.hasNext() && !doneEval) {
        final Tree gold = goldItr.next();
        final Tree evalGold = tc.transformTree(gold);
        goldLineId++;

        if(gold.yield().size() > MAX_GOLD_YIELD) {
          continue;

        } else if(evalGold.yield().size() != evalGuess.yield().size()) {
          pwOut.println("Yield mismatch at gold line " + goldLineId);
          skippedGuessTrees++;
          break; //Default evalb behavior -- skip this guess tree
        }
View Full Code Here


        for (HasWord word : sentence) {
          outputMatrix(bout, model.getWordVector(word.word()));
        }

        Tree rootTree = findRootTree(vectors);
        outputTreeMatrices(bout, rootTree, vectors);

        bout.flush();
        fout.close();
      }
View Full Code Here

   * @return The parse tree that is the head.  The convention has been
   *         that this returns <code>null</code> if no head is found.
   *         But maybe it should throw an exception?
   */
  public Tree determineHead(Tree t) {
    Tree result = determineBinaryHead(t);
    if (result == null && fallbackHF != null) {
      result = fallbackHF.determineHead(t);
    }
    if (result != null) {
      return result;
View Full Code Here

    }
    throw new IllegalStateException("BinaryHeadFinder: unexpected tree: " + t);
  }
 
  public Tree determineHead(Tree t, Tree parent){
    Tree result = determineBinaryHead(t);
    if (result == null && fallbackHF != null) {
      result = fallbackHF.determineHead(t, parent);
    }
    if (result != null) {
      return result;
View Full Code Here

    final Iterator<Tree> goldItr = goldTreebank.iterator();
    int goldLineId = 0;
    int skippedGuessTrees = 0;

    for(final Tree guess : guessTreebank) {
      final Tree evalGuess = tc.transformTree(guess);
      final ArrayList<Label> guessSent = guess.yield();
      final String guessChars = Sentence.listToString(guessSent).replaceAll("\\s+","");
      if(guessSent.size() > maxGuessYield) {
        skippedGuessTrees++;
        continue;
      }

      boolean doneEval = false;
      while(goldItr.hasNext() && !doneEval) {
        final Tree gold = goldItr.next();
        final Tree evalGold = tc.transformTree(gold);
        goldLineId++;

        final ArrayList<Label> goldSent = gold.yield();
        final String goldChars = Sentence.listToString(goldSent).replaceAll("\\s+","");
View Full Code Here

    } else {
      while(!stack.isEmpty()) {
        Pair<Integer,Tree> depthNode = stack.pop();

        final int nodeDepth = depthNode.first();
        final Tree node = depthNode.second();
        if(nodeDepth != maxDepth) {
          maxDepth = nodeDepth;
          if(node.isPhrasal() && stack.size() + 1 > maxBreadth) maxBreadth = stack.size() + 1;
        }

        if(node.isPhrasal()) {
          ocs.addPhrasalBranch(node.value(), node.children().length);
        } else if(node.isPreTerminal())
          ocs.posTags.incrementCount(node.value());
        else if(node.isLeaf()) {
          ocs.words.incrementCount(node.value());
          if(addToVocab) trainVocab.add(node.value());
        }
        for(Tree kid : node.children())
          stack.push(new Pair<Integer,Tree>(nodeDepth + 1, kid));
      }
    }

    return new Pair<Integer,Integer>(maxDepth,maxBreadth);
View Full Code Here

      BufferedReader brIn = new BufferedReader(new InputStreamReader(System.in, encoding));
      TreeReaderFactory trf = new ArabicTreeReaderFactory.ArabicRawTreeReaderFactory(true);

      int nTrees = 0;
      for(String line; (line = brIn.readLine()) != null; ++nTrees) {
        Tree tree = trf.newTreeReader(new StringReader(line)).readTree();
        List<Tree> leaves = tree.getLeaves();
        if(!morphIter.hasNext()) {
          throw new RuntimeException("Mismatch between number of morpho analyses and number of input lines.");
        }
        List<String> morphTags = morphIter.next();
        if (!lemmaIter.hasNext()) {
          throw new RuntimeException("Mismatch between number of lemmas and number of input lines.");
        }
        List<String> lemmas = lemmaIter.next();
        
        // Sanity checks
        assert morphTags.size() == lemmas.size();
        assert lemmas.size() == leaves.size();
       
        for(int i = 0; i < leaves.size(); ++i) {
          String morphTag = morphTags.get(i);
          if (pParenStripper.matcher(morphTag).find()) {
            morphTag = pParenStripper.matcher(morphTag).replaceAll("");
          }
          String newLeaf = String.format("%s%s%s%s%s", leaves.get(i).value(),
              MorphoFeatureSpecification.MORPHO_MARK,
              lemmas.get(i),
              MorphoFeatureSpecification.LEMMA_MARK,
              morphTag);
          leaves.get(i).setValue(newLeaf);
        }
        System.out.println(tree.toString());
      }
     
      // Sanity checks
      assert !morphIter.hasNext();
      assert !lemmaIter.hasNext();
View Full Code Here

    }
   
    private void primeNext() {
      try {
        if (treeReader != null) {
            Tree tree = treeReader.readTree();
            if (tree == null) {
              nextYield = null;
            } else {
              List<CoreLabel> mLabeledLeaves = tree.taggedLabeledYield();
              nextYield = new ArrayList<String>(mLabeledLeaves.size());
              for (CoreLabel label : mLabeledLeaves) {
                nextYield.add(label.tag());
              }
            }
View Full Code Here

    updateTagger(unigramTagger,t);

    //Count MWE statistics
    TregexMatcher m = pMWE.matcher(t);
    while (m.findNextMatchingNode()) {
      Tree match = m.getMatch();
      String label = match.value();
      if(RESOLVE_DUMMY_TAGS && label.equals(FrenchXMLTreeReader.MISSING_PHRASAL))
        continue;

      String preterm = Sentence.listToString(match.preTerminalYield());
      String term = Sentence.listToString(match.yield());

      labelPreterm.incrementCount(label,preterm);
      pretermLabel.incrementCount(preterm,label);
      labelTerm.incrementCount(label,term);
      termLabel.incrementCount(term, label);
View Full Code Here

  }

  public void process() throws IOException {
    SpanishXMLTreeReaderFactory trf = new SpanishXMLTreeReaderFactory();

    Tree t;
    for (File file : fileList) {
      Reader in =
        new BufferedReader(new InputStreamReader(new FileInputStream(file),
                                                 SpanishTreebankLanguagePack.STB_ENCODING));
      TreeReader tr = trf.newTreeReader(in);

      // Tree reading will implicitly perform tree normalization for us
      while ((t = tr.readTree()) != null) {
        // Update tagger with this tree
        List<CoreLabel> yield = t.taggedLabeledYield();
        for (CoreLabel leafLabel : yield) {
          if (leafLabel.tag().equals(SpanishTreeNormalizer.MW_TAG))
            continue;

          unigramTagger.incrementCount(leafLabel.word(), leafLabel.tag());
View Full Code Here

TOP

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

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.