Skip to content

Commit fa05983

Browse files
committed
Allow for reading the tokens directly off the DependencyGraph in the protobuf semgrex processing
1 parent 88a997b commit fa05983

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/edu/stanford/nlp/semgraph/semgrex/ProcessSemgrexRequest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,12 @@ public static CoreNLPProtos.SemgrexResponse processRequest(CoreNLPProtos.Semgrex
8888
for (CoreNLPProtos.SemgrexRequest.Dependencies sentence : request.getQueryList()) {
8989
CoreNLPProtos.SemgrexResponse.GraphResult.Builder graphResultBuilder = CoreNLPProtos.SemgrexResponse.GraphResult.newBuilder();
9090

91-
List<CoreLabel> tokens = sentence.getTokenList().stream().map(serializer::fromProto).collect(Collectors.toList());
91+
final List<CoreLabel> tokens;
92+
if (sentence.getGraph().getTokenList().size() > 0) {
93+
tokens = sentence.getGraph().getTokenList().stream().map(serializer::fromProto).collect(Collectors.toList());
94+
} else {
95+
tokens = sentence.getTokenList().stream().map(serializer::fromProto).collect(Collectors.toList());
96+
}
9297
SemanticGraph graph = ProtobufAnnotationSerializer.fromProto(sentence.getGraph(), tokens, "semgrex");
9398
int patternIdx = 0;
9499
for (SemgrexPattern pattern : patterns) {

0 commit comments

Comments
 (0)