Module bus.extra

Class NLPFactory

java.lang.Object
org.miaixz.bus.extra.nlp.NLPFactory

public class NLPFactory extends Object
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 Details

    • NLPFactory

      public NLPFactory()
  • Method Details

    • getEngine

      public static NLPProvider 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

      public static 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 NLPProvider instance.
      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 NLPProvider instance 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.