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

Java Tsurgeon类代码示例

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

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



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

示例1: parseOperation

import edu.stanford.nlp.trees.tregex.tsurgeon.Tsurgeon; //导入依赖的package包/类
public static TOperationPattern parseOperation(String line) {
  String operations[] = line.split("[,]+");
  TOperationPattern top = new TOperationPattern();
  for (String operation : operations) {
    String toks[] = operation.trim().split("[ ]+");
    if (toks[0].equals("prune")
        || toks[0].equals("replace")
        || toks[0].equals("insert")
        || toks[0].equals("move")
        || toks[0].equals("relabel")) {
      top.operations.add(Tsurgeon.parseOperation(operation));
    } else if (toks[0].equals("new")) {
      top.operations.add(NewNode.parseOperation(operation));
    } else {
      throw new TsurgeonParseException("Error parsing Tsurgeon expression: "
          + toks[0]
          + ":"
          + line, null);
    }
  }
  return top;
}
 
开发者ID:leebird,项目名称:legonlp,代码行数:23,代码来源:TOperationPattern.java


示例2: UCPtransform

import edu.stanford.nlp.trees.tregex.tsurgeon.Tsurgeon; //导入依赖的package包/类
/**
 * Transforms t if it contains an UCP, it will change the UCP tag
 * into the phrasal tag of the first word of the UCP
 * (UCP (JJ electronic) (, ,) (NN computer) (CC and) (NN building))
 * will become
 * (ADJP (JJ electronic) (, ,) (NN computer) (CC and) (NN building))
 *
 * @param t a tree to be transformed
 * @return t transformed
 */
public static Tree UCPtransform(Tree t) {
  Tree firstChild = t.firstChild();
  if (firstChild != null) {
    List<Pair<TregexPattern,TsurgeonPattern>> ops = Generics.newArrayList();

    for (int i = 0; i < operations.length; i++) {
      for (TregexPattern pattern : matchPatterns[i]) {
        ops.add(Generics.newPair(pattern, operations[i]));
      }
    }

    return Tsurgeon.processPatternsOnTree(ops, t);
  } else {
    return t;
  }
}
 
开发者ID:FabianFriedrich,项目名称:Text2Process,代码行数:27,代码来源:CoordinationTransformer.java


示例3: UCPtransform

import edu.stanford.nlp.trees.tregex.tsurgeon.Tsurgeon; //导入依赖的package包/类
/**
 * Transforms t if it contains an UCP, it will change the UCP tag
 * into the phrasal tag of the first word of the UCP
 * (UCP (JJ electronic) (, ,) (NN computer) (CC and) (NN building))
 * will become
 * (ADJP (JJ electronic) (, ,) (NN computer) (CC and) (NN building))
 *
 * @param t a tree to be transformed
 * @return t transformed
 */
public static Tree UCPtransform(Tree t) {
  if (t == null) {
    return null;
  }
  Tree firstChild = t.firstChild();
  if (firstChild != null) {
    List<Pair<TregexPattern,TsurgeonPattern>> ops = Generics.newArrayList();

    for (int i = 0; i < operations.length; i++) {
      for (TregexPattern pattern : matchPatterns[i]) {
        ops.add(Generics.newPair(pattern, operations[i]));
      }
    }

    return Tsurgeon.processPatternsOnTree(ops, t);
  } else {
    return t;
  }
}
 
开发者ID:paulirwin,项目名称:Stanford.NER.Net,代码行数:30,代码来源:CoordinationTransformer.java


示例4: loadOps

import edu.stanford.nlp.trees.tregex.tsurgeon.Tsurgeon; //导入依赖的package包/类
private List<Pair<TregexPattern, TsurgeonPattern>> loadOps() {
  List<Pair<TregexPattern,TsurgeonPattern>> ops = new ArrayList<Pair<TregexPattern,TsurgeonPattern>>();
  
  String line = null;
  try {
    BufferedReader br = new BufferedReader(new StringReader(editStr));
    List<TsurgeonPattern> tsp = new ArrayList<TsurgeonPattern>();
    while ((line = br.readLine()) != null) {
      if (DEBUG) System.err.print("Pattern is " + line);
      TregexPattern matchPattern = TregexPattern.compile(line);
      if (DEBUG) System.err.println(" [" + matchPattern + "]");
      tsp.clear();
      while (continuing(line = br.readLine())) {
        TsurgeonPattern p = Tsurgeon.parseOperation(line);
        if (DEBUG) System.err.println("Operation is " + line + " [" + p + "]");
        tsp.add(p);
      }
      if ( ! tsp.isEmpty()) {
        TsurgeonPattern tp = Tsurgeon.collectOperations(tsp);
        ops.add(new Pair<TregexPattern,TsurgeonPattern>(matchPattern, tp));
      }
    } // while not at end of file
  } catch (IOException ioe) {
    ioe.printStackTrace();
  }
  
  return ops;
}
 
开发者ID:amark-india,项目名称:eventspotter,代码行数:29,代码来源:MWETreeVisitor.java


示例5: 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


示例6: stripEmptyNode

import edu.stanford.nlp.trees.tregex.tsurgeon.Tsurgeon; //导入依赖的package包/类
protected static Tree stripEmptyNode(Tree t) {
  List<Pair<TregexPattern, TsurgeonPattern>> ops = Generics.newArrayList();
  ops.add(Generics.newPair(matchPattern, operation));
  return Tsurgeon.processPatternsOnTree(ops, t);
}
 
开发者ID:FabianFriedrich,项目名称:Text2Process,代码行数:6,代码来源:DependencyTreeTransformer.java


示例7: visitTree

import edu.stanford.nlp.trees.tregex.tsurgeon.Tsurgeon; //导入依赖的package包/类
public void visitTree(Tree t) {
  Tsurgeon.processPatternsOnTree(ops, t);
}
 
开发者ID:amark-india,项目名称:eventspotter,代码行数:4,代码来源:MWETreeVisitor.java


示例8: transformTree

import edu.stanford.nlp.trees.tregex.tsurgeon.Tsurgeon; //导入依赖的package包/类
public Tree transformTree(Tree t) {
  return Tsurgeon.processPatternsOnTree(ops, t);
}
 
开发者ID:amark-india,项目名称:eventspotter,代码行数:4,代码来源:ATBCorrector.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Java PagingState类代码示例发布时间:2022-05-22
下一篇:
Java JideButton类代码示例发布时间: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