fxsjy / jieba

结巴中文分词
MIT License
33.41k stars 6.73k forks source link

请问是否可以把一个句子分成多个有用词? #944

Open 1057437122 opened 3 years ago

1057437122 commented 3 years ago

比如说用户的输入是:'苹果手机壳',是否可以拆分为['苹果', '苹果手机', '手机','手机壳','苹果手机壳']这样的列表?

maotingyang commented 3 years ago

這不就是全模式嗎,cut_all=True

1057437122 commented 2 years ago

這不就是全模式嗎,cut_all=True

不是哦,这是我的测试:

>>> import jieba
>>> str='苹果手机壳'
>>> a=jieba.cut(str,cut_all=True)
>>> a
<generator object Tokenizer.cut at 0x7fc25cf82ba0>
>>> ','.join(a)
Building prefix dict from the default dictionary ...
Dumping model to file cache /var/folders/qh/r_mkjfkd3lx8w5p47qjh7wtw0000gn/T/jieba.cache
Loading model cost 0.562 seconds.
Prefix dict has been built successfully.
'苹果,手机,机壳'