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();
}
Aggregations