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


Java TregexMatcher类代码示例

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


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

示例1: findAntecendentInPredicateNominativeConstruction

import edu.stanford.nlp.trees.tregex.TregexMatcher; //导入依赖的package包/类
/**
 * returns the antecedent NP or null
 * The way this method is called could be made more efficient.  
 * It doesn't really need to get called for every mention
 * 
 */
private static Mention findAntecendentInPredicateNominativeConstruction(Mention m, Document d) {
	Tree root = m.getSentence().rootNode();
	Tree node = m.node();
	
	TregexPattern pat = TregexPatternFactory.getPattern("S < NP=np1 <+(VP) (VP < (/^VB.*/ < be|is|was|were|are|being|been) < NP=np2)");
	TregexMatcher matcher = pat.matcher(root);
	while (matcher.find()) {
		if(matcher.getNode("np2") == node){
			Tree ante  = matcher.getNode("np1");
			for(Mention m2: d.mentions()){
				if(ante == m2.node()){
					return m2;
				}
			}
		}
	}
	
	return null;
}
 
开发者ID:hltfbk,项目名称:Excitement-TDMLEDA,代码行数:26,代码来源:Resolve.java

示例2: match

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

  boolean result = super.match(matcher, tregexMatcher, tree);
  if (result) {
    List<Tree> children = matcher.getMatch().getChildrenAsList();
    int triggerIndex = children.indexOf(matcher.trigger);
    int argIndex = children.indexOf(matcher.argument);

    matcher.matched = tregexMatcher.getMatch().deepCopy();
    children = matcher.matched.getChildrenAsList();

    matcher.trigger = children.get(triggerIndex);

    TreeFactory tf = matcher.matched.treeFactory();
    matcher.argument = tf.newTreeNode(
        "NP",
        children.subList(argIndex, children.size()));
  }
  return result;
}
 
开发者ID:leebird,项目名称:legonlp,代码行数:23,代码来源:VadjArg.java

示例3: match

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

  boolean result = super.match(matcher, tregexMatcher, tree);
  if (result) {
    List<Tree> children = matcher.getMatch().getChildrenAsList();

    int argIndex = children.indexOf(matcher.argument);

    matcher.matched = tregexMatcher.getMatch().deepCopy();
    children = matcher.matched.getChildrenAsList();

    matcher.trigger = matcher.matched;

    TreeFactory tf = matcher.matched.treeFactory();
    matcher.argument = tf
        .newTreeNode("NP", children.subList(0, argIndex + 1));
  }
  return result;
}
 
开发者ID:leebird,项目名称:legonlp,代码行数:22,代码来源:ArgLocus.java

示例4: rightMostVp

import edu.stanford.nlp.trees.tregex.TregexMatcher; //导入依赖的package包/类
public static Tree rightMostVp(Tree vp) {
  TregexMatcher m1 = p1.matcher(vp);
  if (find(m1, vp)) {
    return rightMostVp(m1.getNode("vp"));
  }

  List<Tree> children = vp.getChildrenAsList();
  for (int i = children.size() - 1; i >= 0; i--) {
    Tree child = children.get(i);
    if (child.value().startsWith("VP")) {
      return rightMostVp(child);
    }
    if (child.value().startsWith("ADJP")) {
      Tree foundVp = rightMostAdjp(child);
      if (foundVp != null) {
        return foundVp;
      }
    }
  }
  return vp;
}
 
开发者ID:leebird,项目名称:legonlp,代码行数:22,代码来源:RightMostVp.java

示例5: through

import edu.stanford.nlp.trees.tregex.TregexMatcher; //导入依赖的package包/类
private boolean through(ExtractorMatcher matcher) {
  Tree rightMostVp = RightMostVp.rightMostVp(matcher.trigger);
  TregexMatcher m = through1.matcher(rightMostVp);
  
  if (m.find()) {
    matcher.trigger = m.getNode("tr");
    return true;
  }
  m = through2.matcher(rightMostVp);
  if (m.find()) {
    matcher.trigger = m.getNode("tr");
    return true;
  }
  m = through3.matcher(rightMostVp);
  if (m.find()) {
    matcher.trigger = m.getNode("tr");
    return true;
  }
  return false;
}
 
开发者ID:leebird,项目名称:legonlp,代码行数:21,代码来源:ThroughVion.java

示例6: find

import edu.stanford.nlp.trees.tregex.TregexMatcher; //导入依赖的package包/类
@Override
public boolean find() {

  List<SimplificationPattern> list = SimplificationTregexReader
      .getTregex(SimplificationTregexReader.Apposition);

  for (SimplificationPattern p : list) {
    TregexMatcher m = p.getTregexPattern().matcher(root);
    if (m.find()) {
      for (TOperationPattern oPattern : p.getOperations()) {
        try {
          Tree newTree = oPattern.evaluate(root, p.getTregexPattern());
          simplifiedTrees.add(newTree);
        } catch (NullPointerException e) {
          System.err.println(p);
          e.printStackTrace();
          System.exit(1);
        }
      }
      return true;
    }
  }

  return false;
}
 
开发者ID:leebird,项目名称:legonlp,代码行数:26,代码来源:AppositionSimplifier.java

示例7: find

import edu.stanford.nlp.trees.tregex.TregexMatcher; //导入依赖的package包/类
@Override
public boolean find() {

  for (SimplificationPattern p : list) {
    if (p.getTregexPattern().toString()
        .startsWith("Root (NP=p < (NP=np1 $+ (PP <1 (JJ <: /such/ )")) {
      // System.err.println();
    }
    TregexMatcher m = p.getTregexPattern().matcher(root);
    if (m.find()) {
      for (TOperationPattern oPattern : p.getOperations()) {
        try {
          Tree newTree = oPattern.evaluate(root, p.getTregexPattern());
          simplifiedTrees.add(newTree);
        } catch (NullPointerException e) {
          System.err.println(p);
          e.printStackTrace();
          System.exit(1);
        }
      }
      return true;
    }
  }
  return false;
}
 
开发者ID:leebird,项目名称:legonlp,代码行数:26,代码来源:OtherSimplifier.java

示例8: evaluate

import edu.stanford.nlp.trees.tregex.TregexMatcher; //导入依赖的package包/类
Pair<Tree,Integer> evaluate(Tree t, TregexMatcher tm) {
  int newIndex = -1;
  Tree parent = null;
  Tree relativeNode = p.evaluate(t,tm);
  Matcher m = daughterPattern.matcher(relation);
  if (m.matches()) {
    newIndex = Integer.parseInt(m.group(1))-1;
    parent = relativeNode;
    if(relation.charAt(1)=='-') // backwards.
      newIndex = parent.children().length - newIndex;
  } else {
    parent = relativeNode.parent(t);
    if (parent == null) {
      throw new RuntimeException("Error: looking for a non-existent parent in tree " + t + " for \"" + toString() + "\"");
    }
    int index = parent.indexOf(relativeNode);
    if (relation.equals("$+")) {
      newIndex = index;
    } else if (relation.equals("$-")) {
      newIndex = index+1;
    } else {
      throw new RuntimeException("Error: Haven't dealt with relation " + relation + " yet.");
    }
  }
  return new Pair<Tree,Integer>(parent,newIndex);
}
 
开发者ID:FabianFriedrich,项目名称:Text2Process,代码行数:27,代码来源:TreeLocation.java

示例9: evaluate

import edu.stanford.nlp.trees.tregex.TregexMatcher; //导入依赖的package包/类
@Override
public Tree evaluate(Tree t, TregexMatcher m) {
  Tree targetNode = children[0].evaluate(t,m);
  Tree parent = targetNode.parent(t);
  AuxiliaryTree ft = adjunctionTree.copy(this);
  // System.err.println("ft=" + ft + "; ft.foot=" + ft.foot + "; ft.tree=" + ft.tree);
  Tree parentOfFoot = ft.foot.parent(ft.tree);
  if(parentOfFoot == null) {
    System.err.println("Warning: adjoin to foot for depth-1 auxiliary tree has no effect.");
    return t;
  }
  int i = parentOfFoot.indexOf(ft.foot);
  if(parent==null) {
    parentOfFoot.setChild(i,targetNode);
    return ft.tree;
  }
  else {
    int j = parent.indexOf(targetNode);
    parent.setChild(j,ft.tree);
    parentOfFoot.setChild(i,targetNode);
    return t;
  }
}
 
开发者ID:FabianFriedrich,项目名称:Text2Process,代码行数:24,代码来源:AdjoinToFootNode.java

示例10: evaluate

import edu.stanford.nlp.trees.tregex.TregexMatcher; //导入依赖的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

示例11: processPatternsOnTree

import edu.stanford.nlp.trees.tregex.TregexMatcher; //导入依赖的package包/类
public static Tree processPatternsOnTree(List<Pair<TregexPattern, TsurgeonPattern>> ops, Tree t) {
  matchedOnTree = false;
  for (Pair<TregexPattern,TsurgeonPattern> op : ops) {
    try {
      TregexMatcher m = op.first().matcher(t);
      while (m.find()) {
        matchedOnTree = true;
        t = op.second().evaluate(t,m);
        if (t == null) {
          return null;
        }
        m = op.first().matcher(t);
      }
    } catch (NullPointerException npe) {
      throw new RuntimeException("Tsurgeon.processPatternsOnTree failed to match label for pattern: " + op.first() + ", " + op.second(), npe);
    }
  }
  return t;
}
 
开发者ID:FabianFriedrich,项目名称:Text2Process,代码行数:20,代码来源:Tsurgeon.java

示例12: getRelatedNodes

import edu.stanford.nlp.trees.tregex.TregexMatcher; //导入依赖的package包/类
/** Given a <code>Tree</code> node <code>t</code>, attempts to
 *  return a list of nodes to which node <code>t</code> has this
 *  grammatical relation.
 *
 *  @param t Target for finding governors of t related by this GR
 *  @param root The root of the Tree
 *  @return Governor nodes to which t bears this GR
 */
public Collection<Tree> getRelatedNodes(Tree t, Tree root) {
  if (root.value() == null) {
    root.setValue("ROOT");  // todo: cdm: it doesn't seem like this line should be here
  }
  Set<Tree> nodeList = new LinkedHashSet<Tree>();
  for (TregexPattern p : targetPatterns) {    // cdm: I deleted: && nodeList.isEmpty()
    TregexMatcher m = p.matcher(root);
    while (m.find()) {
      if (m.getMatch() == t) {
        nodeList.add(m.getNode("target"));
        //System.out.println("found " + this + "(" + t + ", " + m.getNode("target") + ")");
      }
    }
  }
  return nodeList;
}
 
开发者ID:FabianFriedrich,项目名称:Text2Process,代码行数:25,代码来源:GrammaticalRelation.java

示例13: evaluate

import edu.stanford.nlp.trees.tregex.TregexMatcher; //导入依赖的package包/类
@Override
public Tree evaluate(Tree t, TregexMatcher m) {
  // find match and get its parent
  Tree targetNode = children[0].evaluate(t,m);
  Tree parent = targetNode.parent(t);
  // put children underneath target in foot of auxilary tree
  AuxiliaryTree ft = adjunctionTree.copy(this);
  ft.foot.setChildren(targetNode.getChildrenAsList());
  // replace match with root of auxiliary tree
  if (parent==null) {
    return ft.tree;
  } else {
    int i = parent.objectIndexOf(targetNode);
    parent.setChild(i,ft.tree);
    return t;
  }
}
 
开发者ID:paulirwin,项目名称:Stanford.NER.Net,代码行数:18,代码来源:AdjoinNode.java

示例14: evaluate

import edu.stanford.nlp.trees.tregex.TregexMatcher; //导入依赖的package包/类
@Override
public Tree evaluate(Tree t, TregexMatcher m) {
  // find match and get its parent
  Tree targetNode = children[0].evaluate(t,m);
  Tree parent = targetNode.parent(t);
  // substitute original node for foot of auxiliary tree.  Foot node is ignored
  AuxiliaryTree ft = adjunctionTree().copy(this);
  // System.err.println("ft=" + ft + "; ft.foot=" + ft.foot + "; ft.tree=" + ft.tree);
  Tree parentOfFoot = ft.foot.parent(ft.tree);
  if (parentOfFoot == null) {
    System.err.println("Warning: adjoin to foot for depth-1 auxiliary tree has no effect.");
    return t;
  }
  int i = parentOfFoot.objectIndexOf(ft.foot);
  if (parent==null) {
    parentOfFoot.setChild(i,targetNode);
    return ft.tree;
  } else {
    int j = parent.objectIndexOf(targetNode);
    parent.setChild(j,ft.tree);
    parentOfFoot.setChild(i,targetNode);
    return t;
  }
}
 
开发者ID:paulirwin,项目名称:Stanford.NER.Net,代码行数:25,代码来源:AdjoinToFootNode.java

示例15: processPatternsOnTree

import edu.stanford.nlp.trees.tregex.TregexMatcher; //导入依赖的package包/类
public static Tree processPatternsOnTree(List<Pair<TregexPattern, TsurgeonPattern>> ops, Tree t) {
  matchedOnTree = false;
  for (Pair<TregexPattern,TsurgeonPattern> op : ops) {
    try {
      if (DEBUG) {
        System.err.println("Running pattern " + op.first());
      }
      TregexMatcher m = op.first().matcher(t);
      while (m.find()) {
        matchedOnTree = true;
        t = op.second().evaluate(t,m);
        if (t == null) {
          return null;
        }
        m = op.first().matcher(t);
      }
    } catch (NullPointerException npe) {
      throw new RuntimeException("Tsurgeon.processPatternsOnTree failed to match label for pattern: " + op.first() + ", " + op.second(), npe);
    }
  }
  return t;
}
 
开发者ID:paulirwin,项目名称:Stanford.NER.Net,代码行数:23,代码来源:Tsurgeon.java


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