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


Java Tsurgeon.processPattern方法代码示例

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


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

示例1: getChunkVector

import edu.stanford.nlp.trees.tregex.tsurgeon.Tsurgeon; //导入方法依赖的package包/类
/**
   * Extract chunks. 
   * 
   * @param tree
   * @return
   */
  private static int[] getChunkVector(Tree tree) {
    String[] iobVector = new String[tree.yield().size()];
    Arrays.fill(iobVector, "O");
    
    // Yield patterns
//    TregexPattern baseNPPattern = TregexPattern.compile("@NP < (/NN/ < (__ !< __)) !< @NP");
    TregexPattern baseXPPattern = TregexPattern.compile("__ < (__ < (__ !< __)) !< (__ < (__ < __))");
    TregexPattern basePPPattern = TregexPattern.compile("@PP <, @IN !<< @NP >! @PP");
    TregexMatcher tregexMatcher = baseXPPattern.matcher(tree);
    fillVectorWithYield(iobVector, tregexMatcher);
    tregexMatcher = basePPPattern.matcher(tree);
    fillVectorWithYield(iobVector, tregexMatcher);
    
    // Edge patterns
    TregexPattern vpPattern = TregexPattern.compile("@VP >! @VP");
    TregexPattern argumentPattern = TregexPattern.compile("[email protected]=node > @VP !< (__ !< __)");
    TregexPattern puncPattern = TregexPattern.compile("/^[^a-zA-Z0-9]+$/=node < __ ");
    TsurgeonPattern p = Tsurgeon.parseOperation("delete node");
    tregexMatcher = vpPattern.matcher(tree);
    while (tregexMatcher.find()) {
      Tree match = tregexMatcher.getMatch();
      Tsurgeon.processPattern(argumentPattern, p, match);
      Tsurgeon.processPattern(puncPattern, p, match);
      List<Tree> leaves = match.getLeaves();
      if (leaves.size() == 1) continue;
      boolean seenStart = false;
      int lastIndex = -1;
      for (Tree leaf : leaves) {
        int index = ((HasIndex) leaf.label()).index() - 1;
        if (index < 0 || index >= iobVector.length) {
          System.err.println("ERROR: Mangled subtree: " + match.toString());
          continue;
        }
        if (lastIndex > 0 && index - lastIndex != 1) break;
        if ( ! iobVector[index].equals("O")) break;
        iobVector[index] = seenStart ? "I" : "B";
        seenStart = true;
        lastIndex = index;
      }
    }
    int[] indexVector = iobToIndices(iobVector);
    return indexVector;
  }
 
开发者ID:stanfordnlp,项目名称:phrasal,代码行数:50,代码来源:CoreNLPToJSON.java


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