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

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

rzo1 commented on code in PR #606:
URL: https://github.com/apache/opennlp/pull/606#discussion_r1639453973


##########
opennlp-tools-models/src/main/java/opennlp/tools/models/ClasspathModelFinder.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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.tools.models;
+
+import java.net.URI;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+
+import io.github.classgraph.ClassGraph;
+import io.github.classgraph.ResourceList;
+import io.github.classgraph.ScanResult;
+
+
+/**
+ * Enables the detection of OpenNLP models in the classpath.
+ */
+public class ClasspathModelFinder {
+
+  private static final String OPENNLP_MODEL_JAR_PREFIX = 
"opennlp-models-*.jar";
+  private final String jarModelPrefix;
+  private Set<ClassPathModelEntry> models;
+
+  /**
+   * By default, it scans for "opennlp-models-*.jar".
+   */
+  public ClasspathModelFinder() {
+    this(OPENNLP_MODEL_JAR_PREFIX);
+  }
+
+  /**
+   * @param modelJarPrefix The leafnames of the jars that should be canned 
(e.g. "opennlp.jar").
+   *                      May contain a wildcard glob ("opennlp-*.jar"). It 
must not be {@code null}.
+   */
+  public ClasspathModelFinder(String modelJarPrefix) {
+    Objects.requireNonNull(modelJarPrefix, "modelJarPrefix must not be null");
+    this.jarModelPrefix = modelJarPrefix;
+  }
+
+  /**
+   * Finds OpenNLP models within the classpath.
+   *
+   * @param reloadCache {@code true}, if the internal cache should explicitly 
be reloaded
+   * @return A Set of {@link ClassPathModelEntry ClassPathModelEntries}. It 
might be empty.
+   */
+  public Set<ClassPathModelEntry> findModels(boolean reloadCache) {
+
+    if (this.models == null || reloadCache) {
+      try (ScanResult sr = new 
ClassGraph().acceptJars(jarModelPrefix).disableDirScanning().scan()) {

Review Comment:
   This is discussed in the comment above. Resolving this extra conversation.





> OpenNLP Models: Provide a Finder / Loader Implementation
> --------------------------------------------------------
>
>                 Key: OPENNLP-1567
>                 URL: https://issues.apache.org/jira/browse/OPENNLP-1567
>             Project: OpenNLP
>          Issue Type: New Feature
>            Reporter: Richard Zowalla
>            Assignee: Richard Zowalla
>            Priority: Major
>             Fix For: 2.3.4, 2.4.0
>
>
> as the title says



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

Reply via email to