做爰高潮a片〈毛片〉,尤物av天堂一区二区在线观看,一本久久A久久精品VR综合,添女人荫蒂全部过程av

最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
當前位置: 首頁 - 科技 - 知識百科 - 正文

Python使用gensim計算文檔相似性

來源:懂視網 責編:小采 時間:2020-11-27 14:35:43
文檔

Python使用gensim計算文檔相似性

Python使用gensim計算文檔相似性:pre_file.py #-*-coding:utf-8-*- import MySQLdb import MySQLdb as mdb import os,sys,string import jieba import codecs reload(sys) sys.setdefaultencoding('utf-8') #連接數據庫 try: conn=mdb.connect(host='127.0.0.1',user='root',passwd='kongjunli',
推薦度:
導讀Python使用gensim計算文檔相似性:pre_file.py #-*-coding:utf-8-*- import MySQLdb import MySQLdb as mdb import os,sys,string import jieba import codecs reload(sys) sys.setdefaultencoding('utf-8') #連接數據庫 try: conn=mdb.connect(host='127.0.0.1',user='root',passwd='kongjunli',

pre_file.py

#-*-coding:utf-8-*-
import MySQLdb
import MySQLdb as mdb
import os,sys,string
import jieba
import codecs
reload(sys)
sys.setdefaultencoding('utf-8')
#連接數據庫
try:
 conn=mdb.connect(host='127.0.0.1',user='root',passwd='kongjunli',db='test1',charset='utf8')
except Exception,e:
 print e
 sys.exit()
#獲取cursor對象操作數據庫
cursor=conn.cursor(mdb.cursors.DictCursor) #cursor游標
#獲取內容
sql='SELECT link,content FROM test1.spider;'
cursor.execute(sql) #execute()方法,將字符串當命令執行
data=cursor.fetchall()#fetchall()接收全部返回結果行
f=codecs.open('C:UserskkDesktophello-result1.txt','w','utf-8')
 
for row in data: #row接收結果行的每行數據
 seg='/'.join(list(jieba.cut(row['content'],cut_all='False')))
 f.write(row['link']+' '+seg+'
')
f.close()
 
cursor.close()
 #提交事務,在插入數據時必須

jiansuo.py

#-*-coding:utf-8-*-
import sys
import string
import MySQLdb
import MySQLdb as mdb
import gensim
from gensim import corpora,models,similarities
from gensim.similarities import MatrixSimilarity
import logging
import codecs
reload(sys)
sys.setdefaultencoding('utf-8')
 
con=mdb.connect(host='127.0.0.1',user='root',passwd='kongjunli',db='test1',charset='utf8')
with con:
 cur=con.cursor()
 cur.execute('SELECT * FROM cutresult_copy')
 rows=cur.fetchall()
 class MyCorpus(object):
 def __iter__(self):
 for row in rows:
 yield str(row[1]).split('/')
#開啟日志
logging.basicConfig(format='%(asctime)s:%(levelname)s:%(message)s',level=logging.INFO)
Corp=MyCorpus()
#將網頁文檔轉化為tf-idf
dictionary=corpora.Dictionary(Corp)
corpus=[dictionary.doc2bow(text) for text in Corp] #將文檔轉化為詞袋模型
#print corpus
tfidf=models.TfidfModel(corpus)#使用tf-idf模型得出文檔的tf-idf模型
corpus_tfidf=tfidf[corpus]#計算得出tf-idf值
#for doc in corpus_tfidf:
 #print doc
###
'''
q_file=open('C:UserskkDesktopq.txt','r')
query=q_file.readline()
q_file.close()
vec_bow=dictionary.doc2bow(query.split(' '))#將請求轉化為詞帶模型
vec_tfidf=tfidf[vec_bow]#計算出請求的tf-idf值
#for t in vec_tfidf:
 # print t
'''
###
query=raw_input('Enter your query:')
vec_bow=dictionary.doc2bow(query.split())
vec_tfidf=tfidf[vec_bow]
index=similarities.MatrixSimilarity(corpus_tfidf)
sims=index[vec_tfidf]
similarity=list(sims)
print sorted(similarity,reverse=True)

encodings.xml

<?xml version="1.0" encoding="UTF-8"?>

 
 
 


misc.xml

<?xml version="1.0" encoding="UTF-8"?>

 
 
 
 
 
 
 
 
 
 
 


modules.xml

<?xml version="1.0" encoding="UTF-8"?>

 
 
 
 
 

聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文檔

Python使用gensim計算文檔相似性

Python使用gensim計算文檔相似性:pre_file.py #-*-coding:utf-8-*- import MySQLdb import MySQLdb as mdb import os,sys,string import jieba import codecs reload(sys) sys.setdefaultencoding('utf-8') #連接數據庫 try: conn=mdb.connect(host='127.0.0.1',user='root',passwd='kongjunli',
推薦度:
標簽: 相似度 計算 文本
  • 熱門焦點

最新推薦

猜你喜歡

熱門推薦

專題
Top
主站蜘蛛池模板: 徐汇区| 舒兰市| 奈曼旗| 馆陶县| 加查县| 名山县| 万宁市| 称多县| 防城港市| 抚顺县| 南昌市| 普洱| 哈密市| 莱芜市| 福建省| 汉川市| 溆浦县| 东乡| 富阳市| 类乌齐县| 永春县| 富蕴县| 花莲市| 革吉县| 丹阳市| 垣曲县| 温宿县| 甘洛县| 清水县| 磐安县| 玛多县| 乐至县| 清苑县| 鄄城县| 蒲城县| 扬中市| 鱼台县| 闵行区| 沈丘县| 大埔区| 灵寿县|