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


Java TregexPattern类代码示例

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


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

示例1: findAntecendentInPredicateNominativeConstruction

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

import edu.stanford.nlp.trees.tregex.TregexPattern; //导入依赖的package包/类
@Override
protected void compile() {
  super.compile();
  by1 = TregexPattern
      .compile("VP <-1 (PP <<, /by|via|through/ <2 (S <1 (VP <1 VBG=tr)))");
  
  by2 = TregexPattern
      .compile("VP <-1 (PP <<, /by|via|through/ <2 (S <1 ADVP <2 (VP <1 VBG=tr)))");
  
  by3 = TregexPattern
          .compile("VP <-1 (PP <<, /by|via|through/ <2 (S <1 (VP <1 ADVP <2 VBG=tr)))");
  
  by4 = TregexPattern
      .compile("VP <-1 (NP <- (PP <<, /by|via|through/ <2 (NP <+(NP) (NN=tr <, /ing$/))))");
  
  by5 = TregexPattern.compile("VP <-1  (PP <<, /by|via|through/ <2 (NP <+(NP) (NN=tr <, /ing$/)))");
  
  
  by6 = TregexPattern
          .compile("VP <-1 (PP <1 ADVP <2 (IN <<, /by|via|through/) <3 (S <1 (VP <1 VBG=tr)))");
}
 
开发者ID:leebird,项目名称:legonlp,代码行数:22,代码来源:ByVbg.java

示例3: compile

import edu.stanford.nlp.trees.tregex.TregexPattern; //导入依赖的package包/类
@Override
protected void compile() {
  super.compile();
  //vadj = TregexPattern.compile("VP <1 /VB.*/ <2 (ADJP=tr)");
  
  // a is JJ
  vadjs = new ArrayList<TregexPattern>();
  vadj = TregexPattern.compile("VP <1 AUX < ADJP|VP=tr");
  vadjs.add(vadj);
  //vadj = TregexPattern.compile("VP <1 AUX < ADVP < ADJP|VP=tr");
  //vadjs.add(vadj);
  vadj = TregexPattern.compile("VP=tr <1 VBN");
  vadjs.add(vadj);
  vadj = TregexPattern.compile("VBN|JJ=tr");
  vadjs.add(vadj);
}
 
开发者ID:leebird,项目名称:legonlp,代码行数:17,代码来源:ArgVadj.java

示例4: processPatternsOnTree

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

示例5: getRelatedNodes

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

示例6: UCPtransform

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

示例7: processPatternsOnTree

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

示例8: getRelatedNodes

import edu.stanford.nlp.trees.tregex.TregexPattern; //导入依赖的package包/类
/** Given a {@code Tree} node {@code t}, attempts to
 *  return a list of nodes to which node {@code t} has this
 *  grammatical relation, with {@code t} as the governor.
 *
 *  @param t Target for finding dependents of t related by this GR
 *  @param root The root of the Tree
 *  @return A Collection of dependent nodes to which t bears this GR
 */
public Collection<Tree> getRelatedNodes(Tree t, Tree root) {
  Set<Tree> nodeList = new ArraySet<Tree>();
  for (TregexPattern p : targetPatterns) {    // cdm: I deleted: && nodeList.isEmpty()
    TregexMatcher m = p.matcher(root);
    while (m.findAt(t)) {
      nodeList.add(m.getNode("target"));
      if (DEBUG) {
        System.err.println("found " + this + "(" + t + ", " + m.getNode("target") + ") using pattern " + p);
        for (String nodeName : m.getNodeNames()) {
          if (nodeName.equals("target"))
            continue;
          System.err.println("  node " + nodeName + ": " + m.getNode(nodeName));
        }
      }
    }
  }
  return nodeList;
}
 
开发者ID:paulirwin,项目名称:Stanford.NER.Net,代码行数:27,代码来源:GrammaticalRelation.java

示例9: UCPtransform

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

示例10: extractNPorPRP

import edu.stanford.nlp.trees.tregex.TregexPattern; //导入依赖的package包/类
protected void extractNPorPRP(CoreMap s, List<Mention> mentions, Set<IntPair> mentionSpanSet, Set<IntPair> namedEntitySpanSet) {
  List<CoreLabel> sent = s.get(CoreAnnotations.TokensAnnotation.class);
  Tree tree = s.get(TreeCoreAnnotations.TreeAnnotation.class);
  tree.indexLeaves();
  SemanticGraph dependency = s.get(SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation.class);

  final String mentionPattern = "/^(?:NP|PRP)/";
  TregexPattern tgrepPattern = TregexPattern.compile(mentionPattern);
  TregexMatcher matcher = tgrepPattern.matcher(tree);
  while (matcher.find()) {
    Tree t = matcher.getMatch();
    List<Tree> mLeaves = t.getLeaves();
    int beginIdx = ((CoreLabel)mLeaves.get(0).label()).get(CoreAnnotations.IndexAnnotation.class)-1;
    int endIdx = ((CoreLabel)mLeaves.get(mLeaves.size()-1).label()).get(CoreAnnotations.IndexAnnotation.class);
    IntPair mSpan = new IntPair(beginIdx, endIdx);
    if(!mentionSpanSet.contains(mSpan) && !insideNE(mSpan, namedEntitySpanSet)) {
      int mentionID = assignIds? ++maxID:-1;
      Mention m = new Mention(mentionID, beginIdx, endIdx, dependency, new ArrayList<CoreLabel>(sent.subList(beginIdx, endIdx)), t);
      mentions.add(m);
      mentionSpanSet.add(mSpan);
    }
  }
}
 
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:24,代码来源:RuleBasedCorefMentionFinder.java

示例11: findTreePattern

import edu.stanford.nlp.trees.tregex.TregexPattern; //导入依赖的package包/类
/** Find syntactic pattern in a sentence by tregex */
private void findTreePattern(Tree tree, String pattern, Set<Pair<Integer, Integer>> foundPairs) {
  try {
    TregexPattern tgrepPattern = TregexPattern.compile(pattern);
    TregexMatcher m = tgrepPattern.matcher(tree);
    while (m.find()) {
      Tree t = m.getMatch();
      Tree np1 = m.getNode("m1");
      Tree np2 = m.getNode("m2");
      Tree np3 = null;
      if(pattern.contains("m3")) np3 = m.getNode("m3");
      addFoundPair(np1, np2, t, foundPairs);
      if(np3!=null) addFoundPair(np2, np3, t, foundPairs);
    }
  } catch (Exception e) {
    // shouldn't happen....
    throw new RuntimeException(e);
  }
}
 
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:20,代码来源:MentionExtractor.java

示例12: ArabicTreeNormalizer

import edu.stanford.nlp.trees.tregex.TregexPattern; //导入依赖的package包/类
public ArabicTreeNormalizer(boolean retainNPTmp, boolean markPRDverb, boolean changeNoLabels,
    boolean retainNPSbj, boolean retainPPClr) {
  super(new ArabicTreebankLanguagePack());
  this.retainNPTmp = retainNPTmp;
  this.retainNPSbj = retainNPSbj;
  this.markPRDverb = markPRDverb;
  this.changeNoLabels = changeNoLabels;
  this.retainPPClr = retainPPClr;

  rootLabel = tlp.startSymbol();

  prdVerbPattern  = TregexPattern.compile("/^V[^P]/ > VP $ /-PRD$/=prd");

  prdPattern = Pattern.compile("^[A-Z]+-PRD");

  //Marks NP subjects that *do not* occur in verb-initial clauses
  npSbjPattern = TregexPattern.compile("/^NP-SBJ/ !> @VP");

  emptyFilter = new ArabicEmptyFilter();
}
 
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:21,代码来源:ArabicTreeNormalizer.java

示例13: getRelatedNodes

import edu.stanford.nlp.trees.tregex.TregexPattern; //导入依赖的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.findAt(t)) {
      nodeList.add(m.getNode("target"));
      if (DEBUG) {
        System.err.println("found " + this + "(" + t + ", " + m.getNode("target") + ") using pattern " + p);
        for (String nodeName : m.getNodeNames()) {
          if (nodeName.equals("target")) 
            continue;
          System.err.println("  node " + nodeName + ": " + m.getNode(nodeName));
        }
      }
    }
  }
  return nodeList;
}
 
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:30,代码来源:GrammaticalRelation.java

示例14: evaluateTregexPattern

import edu.stanford.nlp.trees.tregex.TregexPattern; //导入依赖的package包/类
public List<String> evaluateTregexPattern(String parseTree, String tregexPattern)
{
    List<String> foundMatches = new ArrayList<String>();

    TregexPattern pattern = TregexPattern.compile(tregexPattern);
    TregexMatcher matches = pattern.matcher(Tree.valueOf(parseTree));
    Set<String> nodes = matches.getNodeNames();
    while (matches.find())
    {
        foundMatches.add(matches.getMatch().pennString());
        for (String node : nodes)
        {
            foundMatches.add(matches.getNode(node).pennString());
        }
    }

    return foundMatches;
}
 
开发者ID:dmnapolitano,项目名称:stanford-thrift,代码行数:19,代码来源:StanfordTregexThrift.java

示例15: ArabicTreeNormalizer

import edu.stanford.nlp.trees.tregex.TregexPattern; //导入依赖的package包/类
public ArabicTreeNormalizer(boolean retainNPTmp, boolean markPRDverb, boolean changeNoLabels,
    boolean retainNPSbj, boolean retainPPClr) {
  super(new ArabicTreebankLanguagePack());
  this.retainNPTmp = retainNPTmp;
  this.retainNPSbj = retainNPSbj;
  this.markPRDverb = markPRDverb;
  this.changeNoLabels = changeNoLabels;
  this.retainPPClr = retainPPClr;

  rootLabel = tlp.startSymbol();

  prdVerbPattern  = TregexPattern.compile("/^V[^P]/ > VP $ /-PRD$/=prd");
  
  prdPattern = Pattern.compile("^[A-Z]+-PRD");
  
  //Marks NP subjects that *do not* occur in verb-initial clauses
  npSbjPattern = TregexPattern.compile("/^NP-SBJ/ !> @VP");
  
  emptyFilter = new ArabicEmptyFilter();
}
 
开发者ID:amark-india,项目名称:eventspotter,代码行数:21,代码来源:ArabicTreeNormalizer.java


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