python 搜索引擎Whoosh中文文档和代码 以及jieba的使用
生活随笔
收集整理的這篇文章主要介紹了
python 搜索引擎Whoosh中文文档和代码 以及jieba的使用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
注意, 數據庫的表最好別有下劃線
?
?
中文文檔鏈接:
https://mr-zhao.gitbooks.io/whoosh/content/%E5%A6%82%E4%BD%95%E7%B4%A2%E5%BC%95%E6%96%87%E6%A1%A3.html https://mr-zhao.gitbooks.io/whoosh/content/如何索引文檔.html?q=?
代碼:
https://github.com/renfanzi/myWhoosh?
?
jieba的使用案例 =====》版本3.5
from jieba.analyse import ChineseAnalyzer import jiebaanalyzer = ChineseAnalyzer() a = analyzer("我的好朋友是李明;我愛北京天安門;IBM和Microsoft; I have a dream. this is intetesting and interested me a lot") # 這樣的是只過濾詞,更加簡潔,更方便 print([i.text for i in a])seg_list = jieba.cut("我的好朋友是李明;我愛北京天安門;IBM和Microsoft; I have a dream. this is intetesting and interested me a lot",cut_all=False) # cut_all = False 就是連標點等都不過濾,完全切割cut seg_list1 = jieba.cut("IBM和Microsoft; I have a dream. this is intetesting and interested me a lot",cut_all=True) # cut_all = False 就是過濾標點等 print([i for i in seg_list if i]) print([i for i in seg_list1 if i])# 注意,其實也可以用join來拼接
?
?
結果:
Building prefix dict from the default dictionary ... Loading model from cache /tmp/jieba.cache Loading model cost 0.865 seconds. Prefix dict has been built succesfully. ['我', '好', '朋友', '是', '李明', '我', '愛', '北京', '天安', '天安門', 'ibm', 'microsoft', 'dream', 'intetest', 'interest', 'me', 'lot'] ['我', '的', '好', '朋友', '是', '李明', ';', '我', '愛', '北京', '天安門', ';', 'IBM', '和', 'Microsoft', ';', ' ', 'I', ' ', 'have', ' ', 'a', ' ', 'dream', '.', ' ', 'this', ' ', 'is', ' ', 'intetesting', ' ', 'and', ' ', 'interested', ' ', 'me', ' ', 'a', ' ', 'lot'] ['IBM', '和', 'Microsoft', 'I', 'have', 'a', 'dream', 'this', 'is', 'intetesting', 'and', 'interested', 'me', 'a', 'lot']?
轉載于:https://www.cnblogs.com/renfanzi/p/7195970.html
總結
以上是生活随笔為你收集整理的python 搜索引擎Whoosh中文文档和代码 以及jieba的使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: HDU 2564 饭卡
- 下一篇: Jquery获取对象的几种方式介绍