当前位置: 首页>>代码示例>>Java>>正文


Java TreeFactory.newLeaf方法代码示例

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


在下文中一共展示了TreeFactory.newLeaf方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: match

import edu.stanford.nlp.trees.TreeFactory; //导入方法依赖的package包/类
@Override
protected boolean match(ExtractorMatcher matcher,
    TregexMatcher tregexMatcher, Tree tree) {

  Tree leaf = tregexMatcher.getMatch().getChild(0);
  if (!leaf.isLeaf()) {
    return false;
  }

  OffsetLabel label = (OffsetLabel) leaf.label();
  int dash = label.value().lastIndexOf('-');
  if (dash == -1 || dash == 0) {
    return false;
  }

  matcher.matched = leaf.parent(tree).deepCopy();

  TreeFactory tf = matcher.matched.treeFactory();

  OffsetLabel newLeafLabel = new OffsetLabel(label.value()
      .substring(dash + 1));
  newLeafLabel.setBeginPosition(dash + 1 + label.beginPosition());
  newLeafLabel.setEndPosition(label.endPosition());
  
  leaf = tf.newLeaf(newLeafLabel);
  matcher.trigger = tf.newTreeNode("NP", Collections.singletonList(leaf));
  
  newLeafLabel = new OffsetLabel(label.value()
      .substring(0, dash));
  newLeafLabel.setBeginPosition(label.beginPosition());
  newLeafLabel.setEndPosition(label.beginPosition() + dash);
  
  leaf = tf.newLeaf(newLeafLabel);
  matcher.argument = tf.newTreeNode("NP", Collections.singletonList(leaf));

  matcher.matched.removeChild(0);
  matcher.matched.addChild(matcher.argument);
  matcher.matched.addChild(matcher.trigger);
  return true;
}
 
开发者ID:leebird,项目名称:legonlp,代码行数:41,代码来源:ArgDashExpressing.java

示例2: xTree

import edu.stanford.nlp.trees.TreeFactory; //导入方法依赖的package包/类
/**
 * Construct a fall through tree in case we can't parse this sentence
 * @param words
 * @return a tree with X for all the internal nodes
 */
public static Tree xTree(List<? extends HasWord> words) {
  TreeFactory lstf = new LabeledScoredTreeFactory();
  List<Tree> lst2 = new ArrayList<Tree>();
  for (HasWord obj : words) {
    String s = obj.word();
    Tree t = lstf.newLeaf(s);
    Tree t2 = lstf.newTreeNode("X", Collections.singletonList(t));
    lst2.add(t2);
  }
  return lstf.newTreeNode("X", lst2);
}
 
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:17,代码来源:ParserAnnotatorUtils.java

示例3: match

import edu.stanford.nlp.trees.TreeFactory; //导入方法依赖的package包/类
@Override
protected boolean match(ExtractorMatcher matcher,
    TregexMatcher tregexMatcher, Tree tree) {

  Tree leaf = tregexMatcher.getMatch().getChild(0);
  if (!leaf.isLeaf()) {
    return false;
  }

  OffsetLabel label = (OffsetLabel) leaf.label();
  if (label.value().contains("-RRB-")) {
    return false;
  }
  Matcher m = p.matcher(label.value());
  if (!m.find()) {
    return false;
  }

  matcher.matched = leaf.parent(tree).deepCopy();
  
  TreeFactory tf = matcher.matched.treeFactory();

  OffsetLabel newLeafLabel = new OffsetLabel(m.group(2));
  newLeafLabel.setBeginPosition(m.start(2) + label.beginPosition());
  newLeafLabel.setEndPosition(m.end(2) + label.beginPosition());
  
  leaf = tf.newLeaf(newLeafLabel);
  matcher.trigger = tf.newTreeNode(matcher.matched.value(), Collections.singletonList(leaf));
  
  newLeafLabel = new OffsetLabel(m.group(1));
  newLeafLabel.setBeginPosition(m.start(1) + label.beginPosition());
  newLeafLabel.setEndPosition(m.end(1) + label.beginPosition());
  
  leaf = tf.newLeaf(newLeafLabel);
  matcher.argument = tf.newTreeNode(matcher.matched.value(), Collections.singletonList(leaf));

  matcher.matched.removeChild(0);
  matcher.matched.addChild(matcher.argument);
  matcher.matched.addChild(matcher.trigger);
  return true;
}
 
开发者ID:leebird,项目名称:legonlp,代码行数:42,代码来源:ArgDashVnorm.java


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