Package edu.stanford.nlp.trees.tregex

Examples of edu.stanford.nlp.trees.tregex.TregexMatcher.find()


      }

      Tree tree = treeMap.get(id);
      TregexMatcher m = pBadTree.matcher(tree);
      TregexMatcher m2 = pBadTree2.matcher(tree);
      if(m.find() || m2.find()) {
        System.err.println("Discarding tree: " + tree.toString());
        continue;
      }
     
      // Punctuation normalization, etc.
View Full Code Here


  static final TregexPattern tregexMonthYear = TregexPatternCompiler.defaultCompiler.compile("NP=root <1 (NP <: (NNP=month <: /" + MONTH_REGEX + "/)) <2 (NP=yearnp <: (CD=year <: __)) : =root <- =yearnp");
  static final TregexPattern tregexMonthDayYear = TregexPatternCompiler.defaultCompiler.compile("NP=root <1 (NP=monthdayroot <1 (NNP=month <: /" + MONTH_REGEX +"/) <2 (CD=day <: __)) <2 (/^,$/=comma <: /^,$/) <3 (NP=yearroot <: (CD=year <: __)) : (=root <- =yearroot) : (=monthdayroot <- =day)");

  public Tree transformTree(Tree t) {
    TregexMatcher matcher = tregexMonthYear.matcher(t);
    while (matcher.find()) {
      Tree root = matcher.getNode("root");
      Tree month = matcher.getNode("month");
      Tree year = matcher.getNode("year");
      Tree[] children = new Tree[] {month, year};
      root.setChildren(children);
View Full Code Here

      Tree[] children = new Tree[] {month, year};
      root.setChildren(children);
      matcher = tregexMonthYear.matcher(t);
    }
    matcher = tregexMonthDayYear.matcher(t);
    while (matcher.find()) {
      Tree root = matcher.getNode("root");
      Tree month = matcher.getNode("month");
      Tree day = matcher.getNode("day");
      Tree comma = matcher.getNode("comma");
      Tree year = matcher.getNode("year");
View Full Code Here

      final String enumerationPattern = "NP < (NP=tmp $.. (/,|CC/ $.. NP))";

      TregexPattern tgrepPattern = TregexPattern.compile(enumerationPattern);
      TregexMatcher m = tgrepPattern.matcher(this.mentionSubTree);
      while (m.find()) {
        //        Tree t = m.getMatch();
        if(this.mentionSubTree==m.getNode("tmp")
           && this.spanToString().toLowerCase().contains(" and ")) {
          number = Number.PLURAL;
        }
View Full Code Here

   * @return t, which has been surgically modified.
   */
  public static Tree processPattern(TregexPattern matchPattern, TsurgeonPattern p, Tree t) {
    TregexMatcher m = matchPattern.matcher(t);
    TsurgeonMatcher tsm = p.matcher();
    while (m.find()) {
      t = tsm.evaluate(t, m);
      if (t==null) {
        break;
      }
      m = matchPattern.matcher(t);
View Full Code Here

        if (DEBUG) {
          System.err.println("Running pattern " + op.first());
        }
        TregexMatcher m = op.first().matcher(t);
        TsurgeonMatcher tsm = op.second().matcher();
        while (m.find()) {
          matchedOnTree = true;
          t = tsm.evaluate(t,m);
          if (t == null) {
            return null;
          }
View Full Code Here

    public void visitTree(Tree t) {
      int numMatches = 0;
      TregexMatcher match = p.matcher(t);
      List<Tree> matchedPartList = null; // initialize lazily, since usually most trees don't match!
      while (match.find()) {
        Tree curMatch = match.getMatch();
        //System.out.println("Found match is: " + curMatch);
        if (matchedPartList == null) matchedPartList = new ArrayList<Tree>();
        matchedPartList.add(curMatch);
        numMatches++;
View Full Code Here

    for (TregexPattern p : targetPatterns) {    // cdm: I deleted: && nodeList.isEmpty()
      if (root.value() == null) {
        root.setValue("ROOT");
      }
      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") + ")");
        }
      }
View Full Code Here

   * @param t the {@link Tree} to match against and perform surgery on.
   * @return t, which has been surgically modified.
   */
  public static Tree processPattern(TregexPattern matchPattern, TsurgeonPattern p, Tree t) {
    TregexMatcher m = matchPattern.matcher(t);
    while(m.find()) {
      t = p.evaluate(t,m);
      if(t==null)
        break;
      m = matchPattern.matcher(t);
    }
View Full Code Here

  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;
          }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.