pyhanlp 自定义词典操作

Posted on 2020-12-30 19:20:00

pyhanlp 自定义词典操作

在代码中编辑自定义词典

CustomDictionary = JClass("com.hankcs.hanlp.dictionary.CustomDictionary")
CustomDictionary.add("代行", "nnt 1999")
CustomDictionary.add("李紫文", "nr 1")
CustomDictionary.add("胡浩洋", "nr 1")

强制 优先自定义词典

HanLP.newSegment()\
     .enableNameRecognize(True) \
     .enableCustomDictionaryForcing(True)
     .seg(sentence)