HanLP 是一个高效、易用的自然语言处理工具包,它提供了丰富的NLP功能,包括分词、词性标注、命名实体识别、依存句法分析等。

快速入门

  1. 安装 HanLP
    你可以通过 Maven 或 Gradle 来添加 HanLP 的依赖:

    <dependency>
        <groupId>com.hankcs</groupId>
        <artifactId>hanlp</artifactId>
        <version>2.1.8</version>
    </dependency>
    
  2. 使用 HanLP 进行分词

    import com.hankcs.hanlp.HanLP;
    import com.hankcs.hanlp.seg.common.Term;
    
    public class Main {
        public static void main(String[] args) {
            String text = "HanLP 是一个自然语言处理工具包。";
            List<Term> terms = HanLP.segment(text);
            for (Term term : terms) {
                System.out.println(term.word);
            }
        }
    }
    

高级功能

  • 词性标注
    HanLP 提供了多种词性标注工具,例如:

    import com.hankcs.hanlp.seg.common.Term;
    
     public class Main {
         public static void main(String[] args) {
             String text = "今天天气真好。";
             List<Term> terms = HanLP.segment(text);
             for (Term term : terms) {
                 System.out.println(term.word + "/" + term.nature);
             }
         }
     }
    
  • 命名实体识别
    HanLP 支持多种命名实体识别任务,例如:

    import com.hankcs.hanlp.seg.common.Term;
    
     public class Main {
         public static void main(String[] args) {
             String text = "我昨天去了北京的天安门广场。";
             List<Term> terms = HanLP.segment(text);
             for (Term term : terms) {
                 System.out.println(term.word + "/" + term.nature);
             }
         }
     }
    

更多信息

HanLP Logo