Search in sources :

Example 6 with TokenSequencePattern

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

the class ProcessTokensRegexRequest method processRequest.

public static CoreNLPProtos.TokensRegexResponse processRequest(CoreNLPProtos.TokensRegexRequest request) {
    ProtobufAnnotationSerializer serializer = new ProtobufAnnotationSerializer();
    CoreNLPProtos.TokensRegexResponse.Builder responseBuilder = CoreNLPProtos.TokensRegexResponse.newBuilder();
    List<TokenSequencePattern> patterns = request.getPatternList().stream().map(TokenSequencePattern::compile).collect(Collectors.toList());
    Annotation annotation = serializer.fromProto(request.getDoc());
    List<CoreMap> sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class);
    for (TokenSequencePattern pattern : patterns) {
        CoreNLPProtos.TokensRegexResponse.PatternMatch match = matchPattern(pattern, sentences);
        responseBuilder.addMatch(match);
    }
    return responseBuilder.build();
}
Also used : ProtobufAnnotationSerializer(edu.stanford.nlp.pipeline.ProtobufAnnotationSerializer) CoreAnnotations(edu.stanford.nlp.ling.CoreAnnotations) CoreMap(edu.stanford.nlp.util.CoreMap) TokenSequencePattern(edu.stanford.nlp.ling.tokensregex.TokenSequencePattern) Annotation(edu.stanford.nlp.pipeline.Annotation)

Aggregations

TokenSequencePattern (edu.stanford.nlp.ling.tokensregex.TokenSequencePattern)6 CoreLabel (edu.stanford.nlp.ling.CoreLabel)4 CoreAnnotations (edu.stanford.nlp.ling.CoreAnnotations)3 Annotation (edu.stanford.nlp.pipeline.Annotation)3 CoreMap (edu.stanford.nlp.util.CoreMap)3 SequenceMatchResult (edu.stanford.nlp.ling.tokensregex.SequenceMatchResult)2 TokenSequenceMatcher (edu.stanford.nlp.ling.tokensregex.TokenSequenceMatcher)2 StanfordCoreNLP (edu.stanford.nlp.pipeline.StanfordCoreNLP)2 SemgrexPattern (edu.stanford.nlp.semgraph.semgrex.SemgrexPattern)2 TwoDimensionalCounter (edu.stanford.nlp.stats.TwoDimensionalCounter)2 ArrayList (java.util.ArrayList)2 Span (edu.stanford.nlp.ie.machinereading.structure.Span)1 RelationTriple (edu.stanford.nlp.ie.util.RelationTriple)1 IndexedWord (edu.stanford.nlp.ling.IndexedWord)1 Env (edu.stanford.nlp.ling.tokensregex.Env)1 ApplyDepPatterns (edu.stanford.nlp.patterns.dep.ApplyDepPatterns)1 ProtobufAnnotationSerializer (edu.stanford.nlp.pipeline.ProtobufAnnotationSerializer)1 SemanticGraphEdge (edu.stanford.nlp.semgraph.SemanticGraphEdge)1 SemgrexMatcher (edu.stanford.nlp.semgraph.semgrex.SemgrexMatcher)1 CollectionValuedMap (edu.stanford.nlp.util.CollectionValuedMap)1