Search in sources :

Example 6 with TokenSequenceMatcher

use of edu.stanford.nlp.ling.tokensregex.TokenSequenceMatcher in project CoreNLP by stanfordnlp.

the class Sentence method find.

/**
   * Apply a TokensRegex pattern to the sentence.
   *
   * @param pattern The TokensRegex pattern to match against.
   * @param fn The action to do on each match.
   * @return the list of matches, after run through the function.
   */
public <T> List<T> find(TokenSequencePattern pattern, Function<TokenSequenceMatcher, T> fn) {
    TokenSequenceMatcher matcher = pattern.matcher(asCoreLabels());
    List<T> lst = new ArrayList<>();
    while (matcher.find()) {
        lst.add(fn.apply(matcher));
    }
    return lst;
}
Also used : TokenSequenceMatcher(edu.stanford.nlp.ling.tokensregex.TokenSequenceMatcher)

Aggregations

TokenSequenceMatcher (edu.stanford.nlp.ling.tokensregex.TokenSequenceMatcher)6 CoreLabel (edu.stanford.nlp.ling.CoreLabel)4 CoreAnnotations (edu.stanford.nlp.ling.CoreAnnotations)3 IndexedWord (edu.stanford.nlp.ling.IndexedWord)2 TokenSequencePattern (edu.stanford.nlp.ling.tokensregex.TokenSequencePattern)2 SemgrexMatcher (edu.stanford.nlp.semgraph.semgrex.SemgrexMatcher)2 Span (edu.stanford.nlp.ie.machinereading.structure.Span)1 RelationTriple (edu.stanford.nlp.ie.util.RelationTriple)1 SemanticGraph (edu.stanford.nlp.semgraph.SemanticGraph)1 SemanticGraphCoreAnnotations (edu.stanford.nlp.semgraph.SemanticGraphCoreAnnotations)1 SemanticGraphEdge (edu.stanford.nlp.semgraph.SemanticGraphEdge)1 SemgrexPattern (edu.stanford.nlp.semgraph.semgrex.SemgrexPattern)1 TwoDimensionalCounter (edu.stanford.nlp.stats.TwoDimensionalCounter)1 CollectionValuedMap (edu.stanford.nlp.util.CollectionValuedMap)1 Triple (edu.stanford.nlp.util.Triple)1 Matcher (java.util.regex.Matcher)1