python調用hanlp分詞包手記java
Hanlp做爲一款重要的分詞工具,本月初的時候看到大快搜索發佈了hanlp的1.7版本,新增了文本聚類、流水線分詞等功能。關於hanlp1.7版本的新功能,後面有使用的到時候在給你們分享。本篇分享一個在python裏調用hanlp分詞包的過程文章,供須要的朋友參考學習交流!如下爲文章內容:python
1.在python下安裝pyhanlp函數
sudo pip install pyhanlp工具
(詳見pyhanlp官方文檔)學習
2.pyhanlp的一些使用方法spa
(1)Hanlp.segment的使用3d
from pyhanlp import *blog
print HanLP.segment("今天開心了嗎?")token
#輸出:[今天/t, 開心/a, 了/ule, 嗎/y, ?/w]ip
(pyhanlp裏已經含有如下這些功能了,能夠直接調用)
1 - # API列表
2CustomDictionary= LazyLoadingJClass('com.hankcs.hanlp.dictionary.CustomDictionary')
3 HanLP = SafeJClass('com.hankcs.hanlp.HanLP')
4 HanLP.Config = JClass('com.hankcs.hanlp.HanLP$Config')
5PerceptronLexicalAnalyzer= SafeJClass('com.hankcs.hanlp.model.perceptron.PerceptronLexicalAnalyzer')
6 DoubleArrayTrieSegment = SafeJClass('com.hankcs.hanlp.seg.Other.DoubleArrayTrieSegment')
7AhoCorasickDoubleArrayTrie = SafeJClass('com.hankcs.hanlp.collection.AhoCorasick.AhoCorasickDoubleArrayTrie')
8IOUtil = SafeJClass('com.hankcs.hanlp.corpus.io.IOUtil')
9TraditionalChineseTokenizer=SafeJClass('com.hankcs.hanlp.tokenizer.TraditionalChineseTokenizer')
調用方法
analyzer=PerceptronLexicalAnalyzer()
a =analyzer.analyze("今天開心了嗎?")
print a
3.其它更多的功能的實現。
---------------------
做者:小傻子kkk