用nltk colocation功能抽取中文短语和专业词汇增加分词准确性
来源:互联网 发布:想做淘宝客服怎么申请 编辑:程序博客网 时间:2024/04/29 07:06
#用nltk+jieba发现连词和三连词。
import jieba
import nltk
from nltk.collocations import *
train_corpus = "测试数据库,用户支付表,支付金额,支付用户,测试数据库,用户支付表,支付金额,支付用户"
bigram_measures = nltk.collocations.BigramAssocMeasures()
trigram_measures = nltk.collocations.TrigramAssocMeasures()
finder = BigramCollocationFinder.from_words(jieba.cut(train_corpus))
finder.apply_word_filter(lambda w: w.lower() in [',', '.', ',', '。'])
finder.nbest(bigram_measures.pmi, 10)
finder = TrigramCollocationFinder.from_words(jieba.cut(train_corpus))
finder.apply_word_filter(lambda w: w.lower() in [',', '.', ',', '。'])
finder.nbest(trigram_measures.pmi, 10)
#用gensim+jieba发现连词
import jieba
import gensim
mddesc = ['测试数据库','用户支付表','支付金额','支付用户']
train_corpus = []
for desc in mddesc:
train_corpus.append("/".join(jieba.cut(desc)).split("/"))
train_corpus.append("/".join(jieba.cut(desc)).split("/"))
#set the params(min_count, threshold) carefully when you use small corpus.
phrases = gensim.models.phrases.Phrases(train_corpus, min_count = 1, threshold=0.1)
bigram = gensim.models.phrases.Phraser(phrases)
input = "从用户支付表中选择支付金额大于5的用户。"
inputarr = "/".join(jieba.cut(input)).split("/")
repl = [s.replace("_","") for s in bigram[inputarr]]
print(repl)
参考:
https://radimrehurek.com/gensim/models/phrases.html
http://www.nltk.org/howto/collocations.html
http://blog.sina.com.cn/s/blog_630c58cb0100vkix.html
http://nullege.com/codes/search/nltk.metrics.TrigramAssocMeasures
结论:用nltk可方便地发现连词和三连词,用于发现常见搭配、专用词和新词。gensim有此功能,但有点麻烦,不是gensim的强项。
import jieba
import nltk
from nltk.collocations import *
train_corpus = "测试数据库,用户支付表,支付金额,支付用户,测试数据库,用户支付表,支付金额,支付用户"
bigram_measures = nltk.collocations.BigramAssocMeasures()
trigram_measures = nltk.collocations.TrigramAssocMeasures()
finder = BigramCollocationFinder.from_words(jieba.cut(train_corpus))
finder.apply_word_filter(lambda w: w.lower() in [',', '.', ',', '。'])
finder.nbest(bigram_measures.pmi, 10)
finder = TrigramCollocationFinder.from_words(jieba.cut(train_corpus))
finder.apply_word_filter(lambda w: w.lower() in [',', '.', ',', '。'])
finder.nbest(trigram_measures.pmi, 10)
#用gensim+jieba发现连词
import jieba
import gensim
mddesc = ['测试数据库','用户支付表','支付金额','支付用户']
train_corpus = []
for desc in mddesc:
train_corpus.append("/".join(jieba.cut(desc)).split("/"))
train_corpus.append("/".join(jieba.cut(desc)).split("/"))
#set the params(min_count, threshold) carefully when you use small corpus.
phrases = gensim.models.phrases.Phrases(train_corpus, min_count = 1, threshold=0.1)
bigram = gensim.models.phrases.Phraser(phrases)
input = "从用户支付表中选择支付金额大于5的用户。"
inputarr = "/".join(jieba.cut(input)).split("/")
repl = [s.replace("_","") for s in bigram[inputarr]]
print(repl)
参考:
https://radimrehurek.com/gensim/models/phrases.html
http://www.nltk.org/howto/collocations.html
http://blog.sina.com.cn/s/blog_630c58cb0100vkix.html
http://nullege.com/codes/search/nltk.metrics.TrigramAssocMeasures
结论:用nltk可方便地发现连词和三连词,用于发现常见搭配、专用词和新词。gensim有此功能,但有点麻烦,不是gensim的强项。
0 0
- 用nltk colocation功能抽取中文短语和专业词汇增加分词准确性
- Lucene中文分析器的中文分词准确性和性能比较
- Lucene中文分析器的中文分词准确性和性能比较
- Lucene中文分析器的中文分词准确性和性能比较
- python NLTK、中文分词
- 斯坦福和NLTK英语短语词组抽取工具原理及源码理解
- 计算机词汇和短语整理
- 5.NLTK之分类和标注词汇
- nltk.获得文本语料和词汇资源
- 安装和使用NLTK分词和去停词
- 安装和使用NLTK分词和去停词
- NLTK进行英文分句和分词
- Coreseek+Mmseg 中文分词词汇长度修改
- coreseek增加自定义中文分词
- 增加面试机会的关键词和短语
- NLTK 2 获得文本语料和词汇资源
- NLTK学习笔记(五):分类和标注词汇
- NLTK学习笔记(五):分类和标注词汇
- spring schedule的简单实现
- Mac 运行windows软件
- ECLIPSE java.lang.OutOfMemoryError: PermGen space 错误
- 使用 FCM 关于推送无法接收的问题(Firebase 推送)
- e-Bar隐私政策
- 用nltk colocation功能抽取中文短语和专业词汇增加分词准确性
- B1065. 单身狗(25)
- 使用sqlserver数据库java.util.Date类型异常
- 重读《软件测试的艺术》
- 残酷职场的生存法则的是什么?
- oc 中的拷贝
- Tomcat:IOException while loading persisted sessions: java.io.EOFException解决手记
- 分析动态代理Java JDK 动态代理(AOP)使用及实现原理分析
- 关于Tomcat调用Weblogic容器Ejb T3协议