Example usage for edu.stanford.nlp.trees.tregex TregexPattern pattern

List of usage examples for edu.stanford.nlp.trees.tregex TregexPattern pattern

Introduction

In this page you can find the example usage for edu.stanford.nlp.trees.tregex TregexPattern pattern.

Prototype

public String pattern() 

Source Link

Usage

From source file:info.mhaas.ma.Evaluation.ContrastiveConjunctions.java

public void matchPattern(TregexPattern pat) {

    System.err.println("matchPattern called: " + pat.pattern());
    int treesFound = 0;
    for (int i = 0; i < this.parses.size(); i++) {
        //System.out.println("Tree number " + i);
        Tree currentParse = this.parses.get(i);
        TregexMatcher matcher = pat.matcher(currentParse);

        if (!matcher.find()) {
            // no match here. let's try the next tree!
            continue;
        }/*from w  w  w  . j a  v  a2s .com*/
        if (this.matchedTrees.contains(i)) {
            System.err.println("Already seen tree, skipping: " + i);
            continue;
        } else {
            this.matchedTrees.add(i);
        }
        treesFound++;
        // Tree subTree = matcher.getMatch();
        // Cool, we got a match.
        // Let's get left and right trees.
        Tree left = matcher.getNode("left");
        Tree right = matcher.getNode("right");

        int leftIdx = left.nodeNumber(currentParse);
        int rightIdx = right.nodeNumber(currentParse);

        Tree currentPred = this.predicted.get(i);
        Tree currentGold = this.gold.get(i);

        CCMatchObject mo = new CCMatchObject(currentPred, currentGold, currentParse, i, leftIdx, rightIdx);
        this.matches.add(mo);

    }
    System.err.println("Matched " + treesFound + " trees.");

}

From source file:knu.univ.lingvo.coref.MentionExtractor.java

License:Open Source License

private void findTreePattern(Tree tree, TregexPattern tgrepPattern, Set<Pair<Integer, Integer>> foundPairs) {
    try {//w w w .j a v  a  2s  . com
        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 (tgrepPattern.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);
    }
}