java.lang.Object
org.miaixz.bus.extra.nlp.NLPFactory
Factory class for creating and managing Natural Language Processing (NLP) word segmentation engines. This factory
automatically detects and instantiates appropriate
NLPProvider implementations based on available JARs or
explicit engine names, providing a unified access point for NLP services.- Since:
- Java 17+
- Author:
- Kimi Liu
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic NLPProviderAutomatically creates a new instance of the corresponding word segmentation engine object.static NLPProvidercreateEngine(String engineName) Creates a custom word segmentation engine object by its name.static NLPProviderAutomatically creates and retrieves a singleton instance of the corresponding word segmentation engine object.
-
Constructor Details
-
NLPFactory
public NLPFactory()
-
-
Method Details
-
getEngine
Automatically creates and retrieves a singleton instance of the corresponding word segmentation engine object. The engine is determined based on the NLP engine JARs introduced by the user via SPI mechanism. The chosen engine's simple name (without "Engine" suffix) is logged for informational purposes.- Returns:
- A singleton instance of
NLPProvider.
-
createEngine
Automatically creates a new instance of the corresponding word segmentation engine object. The engine is determined based on the NLP engine JARs introduced by the user via SPI mechanism.- Returns:
- A new
NLPProviderinstance. - Throws:
org.miaixz.bus.core.lang.exception.InternalException- if no tokenizer implementation is found on the classpath.
-
createEngine
public static NLPProvider createEngine(String engineName) throws org.miaixz.bus.core.lang.exception.InternalException Creates a custom word segmentation engine object by its name. The engine name is case-insensitive and can optionally include the "Engine" suffix. Supported engine names include, but are not limited to: `Analysis`, `Ansj`, `HanLP`, `IKAnalyzer`, `Jcseg`, `Jieba`, `Mmseg`, `Mynlp`, `Word`.- Parameters:
engineName- The name of the engine to create (e.g., `Analysis`, `Ansj`).- Returns:
- An
NLPProviderinstance corresponding to the given engine name. - Throws:
org.miaixz.bus.core.lang.exception.InternalException- if no engine with the corresponding name is found via SPI.
-