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



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@opennlp.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to