一.jieba库用于分词,https://github.com/fxsjy/jieba

 

二.分词:分词精细:全局(文本分析)<精确(快速成词)<搜素(搜素引擎分词)

 1 #分词
 2 str=r'今天我们中出了一个叛徒,不想领导领导的领导不是好领导'
 3 a=jieba.cut(str,cut_all=True,HMM=False)
 4 #分词(字符串,是否采用全局模式(默认False精确模式),是否使用HMM模式(默认True))
 5 print(a)#返回可迭代的生成器
 6 print(','.join(a))
 7 
 8 b=jieba.lcut(str)#lcut_for_search直接返回列表
 9 print(b)
10 
11 print(jieba.lcut_for_search(str, HMM=True))#搜索模式
12 ---------------------------------------------------------
13 Building prefix dict from the default dictionary ...
14 <generator object Tokenizer.cut at 0x0368E8A0>
15 Loading model from cache C:\Users\11373\AppData\Local\Temp\jieba.cache
16 今天,我们,中出,了,一个,叛徒,,,不想,领导,领导,的,领导,不是,好,领导
17 Loading model cost 0.784 seconds.
18 ['今天', '我们', '中出', '', '一个', '叛徒', '', '不想', '领导', '领导', '', '领导', '不是', '', '领导']
19 Prefix dict has been built succesfully.
20 ['今天', '我们', '中出', '', '一个', '叛徒', '', '不想', '领导', '领导', '', '领导', '不是', '', '领导']
分词

相关文章:

  • 2021-06-23
  • 2022-02-14
  • 2022-12-23
  • 2022-12-23
  • 2021-05-22
  • 2022-12-23
猜你喜欢
  • 2022-02-28
  • 2022-12-23
  • 2022-12-23
  • 2021-07-21
相关资源
相似解决方案