Example usage for edu.stanford.nlp.trees.tregex TregexMatcher getNodeNames

List of usage examples for edu.stanford.nlp.trees.tregex TregexMatcher getNodeNames

Introduction

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

Prototype

public Set<String> getNodeNames() 

Source Link

Usage

From source file:org.ets.research.nlp.stanford_thrift.tregex.StanfordTregexThrift.java

License:Open Source License

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());
        }/*from w  w  w . j av  a  2 s .c  o m*/
    }

    return foundMatches;
}

From source file:org.lambda3.text.simplification.discourse.runner.discourse_tree.extraction.utils.TregexUtils.java

License:Open Source License

public static List<MyMatch> sortedFindAt(Tree parseTree, TregexPattern p, List<String> groupsToOrder) {
    List<MyMatch> res = new ArrayList<>();

    TregexMatcher matcher = p.matcher(parseTree);
    while (matcher.findAt(parseTree)) {
        HashMap<String, Tree> groups = new HashMap<>();
        for (String name : matcher.getNodeNames()) {
            groups.put(name, matcher.getNode(name));
        }//www .  j a  va  2s.c  o m
        res.add(new MyMatch(groups));
    }

    // sort groups
    res.sort(new MyMatch.Comparator(parseTree, groupsToOrder));

    return res;
}

From source file:org.lambda3.text.simplification.discourse.runner.discourse_tree.extraction.utils.TregexUtils.java

License:Open Source License

public static List<MyMatch> sortedFind(Tree parseTree, TregexPattern p, List<String> groupsToOrder) {
    List<MyMatch> res = new ArrayList<>();

    TregexMatcher matcher = p.matcher(parseTree);
    while (matcher.find()) {
        HashMap<String, Tree> groups = new HashMap<>();
        for (String name : matcher.getNodeNames()) {
            groups.put(name, matcher.getNode(name));
        }//from  www.  j  a v a  2  s.c  om
        res.add(new MyMatch(groups));
    }

    // sort groups
    res.sort(new MyMatch.Comparator(parseTree, groupsToOrder));

    return res;
}