<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問答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
        主站蜘蛛池模板: 大妹子影视剧在线观看全集免费| 国产亚洲精品第一综合| 日本免费一区二区久久人人澡| 亚洲av再在线观看| 国产亚洲精品成人久久网站| 四虎成人精品在永久免费| 日韩在线视精品在亚洲| 国产一级理论免费版| 免费一级做a爰片久久毛片潮| 亚洲国产精品线在线观看| 精品久久久久久国产免费了| 中文字幕精品亚洲无线码一区应用| 99精品全国免费观看视频..| 国产亚洲福利精品一区| 免费无码成人AV在线播放不卡| 亚洲视频在线不卡| 在线观看免费高清视频| 国产亚洲视频在线| 亚洲中文字幕不卡无码| 一区二区三区福利视频免费观看| 7777久久亚洲中文字幕蜜桃 | 亚洲综合区小说区激情区| 久青草视频97国内免费影视| 久久精品国产亚洲AV网站| 亚洲av无码专区在线电影| 男人的天堂亚洲一区二区三区| 亚洲国产成人精品无码区花野真一| 在线a免费观看最新网站| 日本亚洲免费无线码| 亚洲人成影院在线观看| 在线毛片片免费观看| 亚洲伊人久久大香线蕉影院| 国产一区视频在线免费观看| 久久久久久久99精品免费观看| 亚洲AV无码国产精品色| 亚洲午夜AV无码专区在线播放| 国产精品99精品久久免费| 亚洲第一成年网站视频| 亚洲AV综合色区无码一区爱AV| 四虎www免费人成| 免费在线黄色电影|