Package opennlp.tools.models.simple
Class SimpleClassPathModelFinder
java.lang.Object
opennlp.tools.models.AbstractClassPathModelFinder
opennlp.tools.models.simple.SimpleClassPathModelFinder
- All Implemented Interfaces:
ClassPathModelFinder
public class SimpleClassPathModelFinder
extends AbstractClassPathModelFinder
implements ClassPathModelFinder
Enables the detection of OpenNLP models in the classpath via JDK classes
By default, this class will search for JAR files starting with "opennlp-models-*".
This wildcard pattern can be adjusted by using the alternative constructor of this class.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final charprivate static final charFields inherited from class opennlp.tools.models.AbstractClassPathModelFinder
JARFields inherited from interface opennlp.tools.models.ClassPathModelFinder
OPENNLP_MODEL_JAR_PREFIX -
Constructor Summary
ConstructorsConstructorDescriptionBy default, it scans forClassPathModelFinder.OPENNLP_MODEL_JAR_PREFIX.SimpleClassPathModelFinder(String modelJarPrefix) -
Method Summary
Modifier and TypeMethodDescriptionAttempts to obtainURLsfrom the classpath in the following order:protected ObjectgetMatchingURIs(String wildcardPattern, Object context) Retrieve matching classpathURIsfor the givenwildcardPattern.private URL[]getURLs(ClassLoader classLoader) (package private) String[]splitClassPath(String classPath, boolean isWindows) SplitsclassPathon the platform's path separator,;on Windows and:elsewhere.Methods inherited from class opennlp.tools.models.AbstractClassPathModelFinder
findModels, getJarModelPrefix, getMatchingJarEntryURIs, getURIsFromJar, isWindows, jarPathsMatch, matchesWildcard, parseJarURI, toURLMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface opennlp.tools.models.ClassPathModelFinder
findModels
-
Field Details
-
CLASSPATH_SEPARATOR_WINDOWS
private static final char CLASSPATH_SEPARATOR_WINDOWS- See Also:
-
CLASSPATH_SEPARATOR_UNIX
private static final char CLASSPATH_SEPARATOR_UNIX- See Also:
-
-
Constructor Details
-
SimpleClassPathModelFinder
public SimpleClassPathModelFinder()By default, it scans forClassPathModelFinder.OPENNLP_MODEL_JAR_PREFIX. -
SimpleClassPathModelFinder
- Parameters:
modelJarPrefix- The leafnames of the jars that should be scanned (e.g. "opennlp.jar"). May contain a wildcard glob ("opennlp-*.jar"). It must not benull.- Throws:
IllegalArgumentException- Thrown ifmodelJarPrefixisnull.
-
-
Method Details
-
getContext
- Specified by:
getContextin classAbstractClassPathModelFinder- Returns:
- Always
nullas it is not needed for the simple case.
-
getMatchingURIs
Description copied from class:AbstractClassPathModelFinderRetrieve matching classpathURIsfor the givenwildcardPattern.- Specified by:
getMatchingURIsin classAbstractClassPathModelFinder- Parameters:
wildcardPattern- The pattern to use for scanning. Must not benull.context- An object holding context information. It might benull. It is unused within this implementation.- Returns:
- A list of matching classpath
URIs. It may be an empty list if nothing is found.
-
getClassPathElements
Attempts to obtainURLsfrom the classpath in the following order:- Try to see if we have a
URLClassLoaderavailable in the current thread. - Try to obtain URLs via the build in classloader via reflections.
(requires--add-opens java.base/jdk.internal.loader=ALL-UNNAMEDas JVM argument) - Try to use the bootstrap classpath via
java.class.path.
- Returns:
- A list of
URLswithin the classpath.
- Try to see if we have a
-
getClassPathUrlsFromSystemProperty
-
splitClassPath
SplitsclassPathon the platform's path separator,;on Windows and:elsewhere. Empty entries, from leading, trailing, or repeated separators, are skipped, since they name no jar file.- Parameters:
classPath- The class path value to split. Must not benull.isWindows-trueto split on;,falseto split on:.- Returns:
- The non-empty class path entries in order.
- Throws:
IllegalArgumentException- Thrown ifclassPathisnull.
-
getURLs
-