@@ -79,31 +79,8 @@ public static CoreNLPProtos.SemgrexResponse.SemgrexResult matchSentence(SemgrexP
7979 return semgrexResultBuilder .build ();
8080 }
8181
82- /**
83- * For a single request, iterate through the SemanticGraphs it
84- * includes, and add the results of each Semgrex operation included
85- * in the request.
86- */
87- public static CoreNLPProtos .SemgrexResponse processRequest (CoreNLPProtos .SemgrexRequest request ) {
88- ProtobufAnnotationSerializer serializer = new ProtobufAnnotationSerializer ();
82+ public static CoreNLPProtos .SemgrexResponse processRequest (List <CoreMap > sentences , List <SemgrexPattern > patterns ) {
8983 CoreNLPProtos .SemgrexResponse .Builder responseBuilder = CoreNLPProtos .SemgrexResponse .newBuilder ();
90-
91- List <CoreMap > sentences = new ArrayList <>();
92- for (CoreNLPProtos .SemgrexRequest .Dependencies sentence : request .getQueryList ()) {
93- final List <CoreLabel > tokens ;
94- if (sentence .getGraph ().getTokenList ().size () > 0 ) {
95- tokens = sentence .getGraph ().getTokenList ().stream ().map (serializer ::fromProto ).collect (Collectors .toList ());
96- } else {
97- tokens = sentence .getTokenList ().stream ().map (serializer ::fromProto ).collect (Collectors .toList ());
98- }
99- SemanticGraph graph = ProtobufAnnotationSerializer .fromProto (sentence .getGraph (), tokens , "semgrex" );
100- CoreMap coremap = new ArrayCoreMap ();
101- coremap .set (SemanticGraphCoreAnnotations .BasicDependenciesAnnotation .class , graph );
102- coremap .set (CoreAnnotations .TokensAnnotation .class , tokens );
103- sentences .add (coremap );
104- }
105-
106- List <SemgrexPattern > patterns = request .getSemgrexList ().stream ().map (SemgrexPattern ::compile ).collect (Collectors .toList ());
10784 List <Pair <CoreMap , List <Pair <SemgrexPattern , List <SemgrexMatch >>>>> allMatches = new ArrayList <>();
10885 for (CoreMap sentence : sentences ) {
10986 allMatches .add (new Pair <>(sentence , new ArrayList <>()));
@@ -134,6 +111,33 @@ public static CoreNLPProtos.SemgrexResponse processRequest(CoreNLPProtos.Semgrex
134111 return responseBuilder .build ();
135112 }
136113
114+ /**
115+ * For a single request, iterate through the SemanticGraphs it
116+ * includes, and add the results of each Semgrex operation included
117+ * in the request.
118+ */
119+ public static CoreNLPProtos .SemgrexResponse processRequest (CoreNLPProtos .SemgrexRequest request ) {
120+ ProtobufAnnotationSerializer serializer = new ProtobufAnnotationSerializer ();
121+
122+ List <CoreMap > sentences = new ArrayList <>();
123+ for (CoreNLPProtos .SemgrexRequest .Dependencies sentence : request .getQueryList ()) {
124+ final List <CoreLabel > tokens ;
125+ if (sentence .getGraph ().getTokenList ().size () > 0 ) {
126+ tokens = sentence .getGraph ().getTokenList ().stream ().map (serializer ::fromProto ).collect (Collectors .toList ());
127+ } else {
128+ tokens = sentence .getTokenList ().stream ().map (serializer ::fromProto ).collect (Collectors .toList ());
129+ }
130+ SemanticGraph graph = ProtobufAnnotationSerializer .fromProto (sentence .getGraph (), tokens , "semgrex" );
131+ CoreMap coremap = new ArrayCoreMap ();
132+ coremap .set (SemanticGraphCoreAnnotations .BasicDependenciesAnnotation .class , graph );
133+ coremap .set (CoreAnnotations .TokensAnnotation .class , tokens );
134+ sentences .add (coremap );
135+ }
136+
137+ List <SemgrexPattern > patterns = request .getSemgrexList ().stream ().map (SemgrexPattern ::compile ).collect (Collectors .toList ());
138+ return processRequest (sentences , patterns );
139+ }
140+
137141 /**
138142 * Reads a single request from the InputStream, then writes back a single response.
139143 */
0 commit comments