• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Trees类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中edu.stanford.nlp.trees.Trees的典型用法代码示例。如果您正苦于以下问题:Java Trees类的具体用法?Java Trees怎么用?Java Trees使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Trees类属于edu.stanford.nlp.trees包,在下文中一共展示了Trees类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: readTreebank

import edu.stanford.nlp.trees.Trees; //导入依赖的package包/类
public MemoryTreebank readTreebank() {
  MemoryTreebank treebank = new MemoryTreebank(trf);
  if (!new File(filename).isFile()) {
    return treebank;
  }
  treebank.loadPath(filename);
  // remove Parse failed
  Iterator<Tree> itr = treebank.iterator();
  while (itr.hasNext()) {
    Tree t = itr.next();
    
    Tree firstLeaf = Trees.getLeaf(t, 0);
    if (firstLeaf.value().equals("Parse")) {
      itr.remove();
    }
  }
  return treebank;
}
 
开发者ID:leebird,项目名称:legonlp,代码行数:19,代码来源:PtbReader.java


示例2: evaluate

import edu.stanford.nlp.trees.Trees; //导入依赖的package包/类
@Override
public Tree evaluate(Tree t, TregexMatcher m) {
  Tree topNode = children[0].evaluate(t,m);
  Tree bottomNode = children[1].evaluate(t,m);
  if(Tsurgeon.verbose) {
    System.err.println("Excising...original tree:");
    t.pennPrint(System.err);
    System.err.println("top: " + topNode + "\nbottom:" + bottomNode);
  }
  if(topNode==t)
    return null;
  Tree parent = topNode.parent(t);
  if(Tsurgeon.verbose)
    System.err.println("Parent: " + parent);
  int i = Trees.objectEqualityIndexOf(parent,topNode);
  parent.removeChild(i);
  for(Tree child : bottomNode.children()) {
    parent.addChild(i,child);
    i++;
  }
  if(Tsurgeon.verbose)
    t.pennPrint(System.err);
  return t;
}
 
开发者ID:FabianFriedrich,项目名称:Text2Process,代码行数:25,代码来源:ExciseNode.java


示例3: lexicalize_parse_tree

import edu.stanford.nlp.trees.Trees; //导入依赖的package包/类
/** If one were to call any of these other methods to get a parse tree for some input sentence
 * with the -outputFormatOptions flag of "lexicalize", they would receive their parse tree,
 * in the -outputFormat of their choice, with every leaf marked with it's head word.
 * This function does exactly that on an existing parse tree.
 * NOTE that this WILL re-lexicalize a pre-lexicalized tree, so don't pass in a tree that
 * has been lexicalized and expect to get back the same thing as what you passed in.
 */
public String lexicalize_parse_tree(String tree) throws TApplicationException
{
    try
    {
        Tree parseTree = Tree.valueOf(tree);
        Tree lexicalizedTree = Trees.lexicalize(parseTree, tlp.headFinder());
        treePrinter = ParserUtil.setOptions(null, tlp); // use defaults
        Function<Tree, Tree> a = TreeFunctions.getLabeledToDescriptiveCoreLabelTreeFunction();
        lexicalizedTree = a.apply(lexicalizedTree);
        return ParserUtil.TreeObjectToString(lexicalizedTree, treePrinter);
    }
    catch (Exception e)
    {
        // FIXME
        throw new TApplicationException(TApplicationException.INTERNAL_ERROR, e.getMessage());
    }
}
 
开发者ID:dmnapolitano,项目名称:stanford-thrift,代码行数:25,代码来源:StanfordParserThrift.java


示例4: annotatePhraseStructureRecursively

import edu.stanford.nlp.trees.Trees; //导入依赖的package包/类
/**
 * Generate a SyntaxTreeNode Annotation corresponding to this Tree. Work
 * recursively so that the annotations are actually generated from the bottom
 * up, in order to build the consists list of annotation IDs.
 * 
 * @param tree
 *          the current subtree
 * @param rootTree
 *          the whole sentence, used to find the span of the current subtree
 * @return a GATE Annotation of type "SyntaxTreeNode"
 */
protected Annotation annotatePhraseStructureRecursively(
    AnnotationSet annotationSet, StanfordSentence stanfordSentence,
    Tree tree, Tree rootTree) {
  Annotation annotation = null;
  Annotation child;
  String label = tree.value();
  List<Tree> children = tree.getChildrenAsList();
  if(children.size() == 0) { return null; }
  /* implied else */
  /*
   * following line generates ClassCastException IntPair span =
   * tree.getSpan(); edu.stanford.nlp.ling.CategoryWordTag at
   * edu.stanford.nlp.trees.Tree.getSpan(Tree.java:393) but I think it's a bug
   * in the parser, so I'm hacking around it as follows.
   */
  int startPos = Trees.leftEdge(tree, rootTree);
  int endPos = Trees.rightEdge(tree, rootTree);
  Long startNode = stanfordSentence.startPos2offset(startPos);
  Long endNode = stanfordSentence.endPos2offset(endPos);
  List<Integer> consists = new ArrayList<Integer>();
  Iterator<Tree> childIter = children.iterator();
  while(childIter.hasNext()) {
    child =
        annotatePhraseStructureRecursively(annotationSet, stanfordSentence,
            childIter.next(), rootTree);
    if((child != null) && (!child.getType().equals(inputTokenType))) {
      consists.add(child.getId());
    }
  }
  annotation =
      annotatePhraseStructureConstituent(annotationSet, startNode, endNode,
          label, consists, tree.depth());
  return annotation;
}
 
开发者ID:GateNLP,项目名称:gateplugin-Stanford_CoreNLP,代码行数:46,代码来源:Parser.java


示例5: annotatePhraseStructureRecursively

import edu.stanford.nlp.trees.Trees; //导入依赖的package包/类
/**
 * Generate a SyntaxTreeNode Annotation corresponding to this Tree.  Work 
 * recursively so that the annotations are actually generated from the 
 * bottom up, in order to build the consists list of annotation IDs.
 * 
 * @param tree  the current subtree
 * @param rootTree  the whole sentence, used to find the span of the current subtree
 * @return a GATE Annotation of type "SyntaxTreeNode"
 */
protected Annotation annotatePhraseStructureRecursively(AnnotationSet annotationSet, StanfordSentence stanfordSentence, Tree tree, Tree rootTree) {
  Annotation annotation = null;
  Annotation child;
  String label   = tree.value();

  List<Tree> children = tree.getChildrenAsList();

  if (children.size() == 0) {
    return null;
  }
  /* implied else */

  /* following line generates ClassCastException
   * 		IntPair span = tree.getSpan();
   * edu.stanford.nlp.ling.CategoryWordTag
   * at edu.stanford.nlp.trees.Tree.getSpan(Tree.java:393)
   * but I think it's a bug in the parser, so I'm hacking 
   * around it as follows. */
  int startPos = Trees.leftEdge(tree, rootTree);
  int endPos   = Trees.rightEdge(tree, rootTree);
  
  Long startNode = stanfordSentence.startPos2offset(startPos);
  Long endNode   = stanfordSentence.endPos2offset(endPos);

  List<Integer> consists = new ArrayList<Integer>();

  Iterator<Tree> childIter = children.iterator();
  while (childIter.hasNext()) {
    child = annotatePhraseStructureRecursively(annotationSet, stanfordSentence, childIter.next(), rootTree);
    if  ( (child != null)  &&
      (! child.getType().equals(inputTokenType) )) {
      consists.add(child.getId());
    }
  }
  annotation = annotatePhraseStructureConstituent(annotationSet, startNode, endNode, label, consists, tree.depth());

  return annotation;
}
 
开发者ID:vita-us,项目名称:ViTA,代码行数:48,代码来源:Parser.java


示例6: pruneHelper

import edu.stanford.nlp.trees.Trees; //导入依赖的package包/类
private static Tree pruneHelper(Tree root, Tree nodeToPrune) {
  if(nodeToPrune==root)
    return null;
  Tree parent = nodeToPrune.parent(root);
  parent.removeChild(Trees.objectEqualityIndexOf(parent,nodeToPrune));
  if(parent.children().length==0)
    return pruneHelper(root,parent);
  return root;
}
 
开发者ID:FabianFriedrich,项目名称:Text2Process,代码行数:10,代码来源:PruneNode.java


示例7: evaluate

import edu.stanford.nlp.trees.Trees; //导入依赖的package包/类
@Override
public Tree evaluate(Tree t, TregexMatcher m) {
  Tree result = t;
  for (TsurgeonPattern child : children) {
    Tree nodeToDelete = child.evaluate(t, m);
    if (nodeToDelete == t) {
      result = null;
    }
    Tree parent = nodeToDelete.parent(t);
    parent.removeChild(Trees.objectEqualityIndexOf(parent,nodeToDelete));
  }
  return result;
}
 
开发者ID:FabianFriedrich,项目名称:Text2Process,代码行数:14,代码来源:DeleteNode.java


示例8: evaluate

import edu.stanford.nlp.trees.Trees; //导入依赖的package包/类
@Override
public Tree evaluate(Tree t, TregexMatcher m) {
  Tree nodeToMove = children[0].evaluate(t,m);
  Tree oldParent = nodeToMove.parent(t);
  oldParent.removeChild(Trees.objectEqualityIndexOf(oldParent,nodeToMove));
  Pair<Tree,Integer> position = l.evaluate(t,m);
  position.first().insertDtr(nodeToMove,position.second());
  return t;
}
 
开发者ID:FabianFriedrich,项目名称:Text2Process,代码行数:10,代码来源:MoveNode.java


示例9: firstLeaf

import edu.stanford.nlp.trees.Trees; //导入依赖的package包/类
public static Tree firstLeaf(Tree t) {
  return Trees.getLeaf(t, 0);
}
 
开发者ID:leebird,项目名称:legonlp,代码行数:4,代码来源:Utils.java


示例10: satisfies

import edu.stanford.nlp.trees.Trees; //导入依赖的package包/类
@Override
boolean satisfies(Tree t1, Tree t2, Tree root) {
  return Trees.rightEdge(t1, root) <= Trees.leftEdge(t2, root);
}
 
开发者ID:FabianFriedrich,项目名称:Text2Process,代码行数:5,代码来源:Relation.java


示例11: getNext

import edu.stanford.nlp.trees.Trees; //导入依赖的package包/类
private List<ScoredObject<Tree>> getNext()
{
  try {
    String line;
    int parsesExpected = 0;
    int sentenceId = lastSentenceId;
    ScoredObject<Tree> curParse = null;
    List<ScoredObject<Tree>> curParses = null;
    while ((line = br.readLine()) != null) {
      line = line.trim();
      if (line.length() > 0) {
        if (parsesExpected == 0) {
          // Finished processing parses
          String[] fields = wsDelimiter.split(line, 2);
          parsesExpected = Integer.parseInt(fields[0]);
          sentenceId = Integer.parseInt(fields[1]);
          if (expectConsecutiveSentenceIds) {
           if (sentenceId != lastSentenceId+1) {
              if (lastSentenceId < sentenceId) {
                StringBuilder sb = new StringBuilder("Missing sentences");
                for (int i = lastSentenceId+1; i < sentenceId; i++) {
                  sb.append(" ").append(i);
                }
                logger.warning(sb.toString());
              } else {
                logger.warning("sentenceIds are not increasing (last="
                      + lastSentenceId + ", curr=" + sentenceId + ")");
              }
            }
          }
          lastSentenceId = sentenceId;
          curParses = new ArrayList<ScoredObject<Tree>>(parsesExpected);
        } else {
          if (curParse == null) {
            // read score
            double score = Double.parseDouble(line);
            curParses.add(curParse = new ScoredObject<Tree>(null, score));
          } else {
            // Reading a parse
            curParse.setObject(Trees.readTree(line));
            curParse = null;
            parsesExpected--;
            if (parsesExpected == 0) {
              return curParses;
            }
          }
        }
      }
    }
  } catch (IOException ex) {
    throw new RuntimeException(ex);
  }
  return null;
}
 
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:55,代码来源:CharniakScoredParsesReaderWriter.java



注:本文中的edu.stanford.nlp.trees.Trees类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java InodeTree类代码示例发布时间:2022-05-22
下一篇:
Java ColumnSerializer类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap