Module bus.extra

Class HanLPProvider

java.lang.Object
org.miaixz.bus.extra.nlp.provider.hanlp.HanLPProvider
All Implemented Interfaces:
Serializable, org.miaixz.bus.core.Provider, NLPProvider

public class HanLPProvider extends Object implements NLPProvider
HanLP word segmentation engine implementation. This class serves as a concrete NLPProvider for the HanLP NLP library, adapting its word segmentation capabilities to the common NLP interface. The underlying Segment.seg(String) method is thread-safe. Project homepage: https://github.com/hankcs/HanLP
Since:
Java 17+
Author:
Kimi Liu
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new HanLPProvider instance with a default HanLP segmenter, created via HanLP.newSegment().
    HanLPProvider(com.hankcs.hanlp.seg.Segment seg)
    Constructs a new HanLPProvider instance with a custom HanLP Segment implementation.
  • Method Summary

    Modifier and Type
    Method
    Description
    Performs word segmentation on the given text using the configured HanLP Segment instance.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.miaixz.bus.extra.nlp.NLPProvider

    type
  • Constructor Details

    • HanLPProvider

      public HanLPProvider()
      Constructs a new HanLPProvider instance with a default HanLP segmenter, created via HanLP.newSegment().
    • HanLPProvider

      public HanLPProvider(com.hankcs.hanlp.seg.Segment seg)
      Constructs a new HanLPProvider instance with a custom HanLP Segment implementation.
      Parameters:
      seg - The custom Segment object to use for word segmentation.
  • Method Details

    • parse

      public NLPResult parse(CharSequence text)
      Performs word segmentation on the given text using the configured HanLP Segment instance. The result is wrapped in a HanLPResult to conform to the NLPResult interface.
      Specified by:
      parse in interface NLPProvider
      Parameters:
      text - The input text CharSequence to be segmented.
      Returns:
      An NLPResult object containing the segmented words from HanLP.