[ 
https://issues.apache.org/jira/browse/OPENNLP-1665?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17906176#comment-17906176
 ] 

ASF GitHub Bot commented on OPENNLP-1665:
-----------------------------------------

rzo1 commented on code in PR #197:
URL: https://github.com/apache/opennlp-sandbox/pull/197#discussion_r1887426790


##########
opennlp-grpc/opennlp-grpc-service/src/main/java/opennlp/service/PosTaggerService.java:
##########
@@ -0,0 +1,201 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package opennlp.service;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.nio.file.Path;
+import java.util.Arrays;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import com.google.rpc.Code;
+import com.google.rpc.Status;
+import io.grpc.protobuf.StatusProto;
+import io.grpc.stub.StreamObserver;
+import org.slf4j.LoggerFactory;
+
+import opennlp.OpenNLPService;
+import opennlp.PosTaggerServiceGrpc;
+import opennlp.service.classpath.DirectoryModelFinder;
+import opennlp.service.exception.ServiceException;
+import opennlp.tools.commons.ThreadSafe;
+import opennlp.tools.models.ClassPathModel;
+import opennlp.tools.models.ClassPathModelEntry;
+import opennlp.tools.models.ClassPathModelLoader;
+import opennlp.tools.postag.POSModel;
+import opennlp.tools.postag.POSTagFormat;
+import opennlp.tools.postag.POSTagger;
+import opennlp.tools.postag.ThreadSafePOSTaggerME;
+
+/**
+ * The {@code PosTaggerService} class implements a gRPC service for 
Part-of-Speech (POS) tagging
+ * using Apache OpenNLP models. It extends the auto-generated gRPC base class
+ * {@link PosTaggerServiceGrpc.PosTaggerServiceImplBase}.
+ *
+ * <p>This service provides functionality for:
+ * <ul>
+ *   <li>Retrieving available POS models loaded from the classpath.</li>
+ *   <li>Performing POS tagging on input sentences.</li>
+ *   <li>Performing POS tagging with additional context.</li>
+ * </ul>
+ * </p>
+ *
+ * <p><b>Configuration:</b>
+ * <ul>
+ *   <li>{@code model.location}: Directory to search for models (default: 
"extlib").</li>
+ *   <li>{@code model.recursive}: Whether to scan subdirectories (default: 
{@code true}).</li>
+ *   <li>{@code model.pos.wildcard}: Wildcard pattern to identify POS models 
(default: "opennlp-models-pos-*.jar").</li>
+ * </ul>
+ *  </p>
+ */
+@ThreadSafe
+public class PosTaggerService extends 
PosTaggerServiceGrpc.PosTaggerServiceImplBase {
+
+  private static final org.slf4j.Logger logger =
+      LoggerFactory.getLogger(PosTaggerService.class);
+
+  private static final Map<String, ClassPathModel> MODEL_CACHE = new 
ConcurrentHashMap<>();
+  private static final Map<String, POSTagger> TAGGER_CACHE = new 
ConcurrentHashMap<>();
+
+  public PosTaggerService(Map<String, String> conf) {
+
+    try {
+      initializeModelCache(conf);
+    } catch (IOException e) {
+      logger.error(e.getLocalizedMessage(), e);
+      throw new RuntimeException(e);
+    }
+
+  }
+
+  public static void clearCaches() {

Review Comment:
   added docs



##########
opennlp-grpc/opennlp-grpc-service/src/main/java/opennlp/service/PosTaggerService.java:
##########
@@ -0,0 +1,201 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package opennlp.service;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.nio.file.Path;
+import java.util.Arrays;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import com.google.rpc.Code;
+import com.google.rpc.Status;
+import io.grpc.protobuf.StatusProto;
+import io.grpc.stub.StreamObserver;
+import org.slf4j.LoggerFactory;
+
+import opennlp.OpenNLPService;
+import opennlp.PosTaggerServiceGrpc;
+import opennlp.service.classpath.DirectoryModelFinder;
+import opennlp.service.exception.ServiceException;
+import opennlp.tools.commons.ThreadSafe;
+import opennlp.tools.models.ClassPathModel;
+import opennlp.tools.models.ClassPathModelEntry;
+import opennlp.tools.models.ClassPathModelLoader;
+import opennlp.tools.postag.POSModel;
+import opennlp.tools.postag.POSTagFormat;
+import opennlp.tools.postag.POSTagger;
+import opennlp.tools.postag.ThreadSafePOSTaggerME;
+
+/**
+ * The {@code PosTaggerService} class implements a gRPC service for 
Part-of-Speech (POS) tagging
+ * using Apache OpenNLP models. It extends the auto-generated gRPC base class
+ * {@link PosTaggerServiceGrpc.PosTaggerServiceImplBase}.
+ *
+ * <p>This service provides functionality for:
+ * <ul>
+ *   <li>Retrieving available POS models loaded from the classpath.</li>
+ *   <li>Performing POS tagging on input sentences.</li>
+ *   <li>Performing POS tagging with additional context.</li>
+ * </ul>
+ * </p>
+ *
+ * <p><b>Configuration:</b>
+ * <ul>
+ *   <li>{@code model.location}: Directory to search for models (default: 
"extlib").</li>
+ *   <li>{@code model.recursive}: Whether to scan subdirectories (default: 
{@code true}).</li>
+ *   <li>{@code model.pos.wildcard}: Wildcard pattern to identify POS models 
(default: "opennlp-models-pos-*.jar").</li>
+ * </ul>
+ *  </p>
+ */
+@ThreadSafe
+public class PosTaggerService extends 
PosTaggerServiceGrpc.PosTaggerServiceImplBase {
+
+  private static final org.slf4j.Logger logger =
+      LoggerFactory.getLogger(PosTaggerService.class);
+
+  private static final Map<String, ClassPathModel> MODEL_CACHE = new 
ConcurrentHashMap<>();
+  private static final Map<String, POSTagger> TAGGER_CACHE = new 
ConcurrentHashMap<>();
+
+  public PosTaggerService(Map<String, String> conf) {

Review Comment:
   added docs





> gRPC Backend for Multi-Language Support
> ---------------------------------------
>
>                 Key: OPENNLP-1665
>                 URL: https://issues.apache.org/jira/browse/OPENNLP-1665
>             Project: OpenNLP
>          Issue Type: New Feature
>            Reporter: Richard Zowalla
>            Assignee: Richard Zowalla
>            Priority: Major
>
> Taken from the slack discussion. Goal is to broaden the application of 
> OpenNLP and usage in different programming language.
> To do so, we can build a component based on gRPC as a module into opennlp 
> itself and implement the server side component for the most common tasks (can 
> be a growing thing, if community is going to like it) in Java using 
> [gRPC|https://grpc.io/] - with the gRPC spec for OpenNLP in place, we can 
> simply generate appropriate clients for every supported language (Python, Go, 
> etc.) - that would make it easier to maintain since we can just tell the 
> people how to generate the client based on the gRPC spec.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to