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:\Users\kk\Desktop\hello-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+'\r\n') 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:\Users\kk\Desktop\q.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"?> <project version="4"> <component name="Encoding"> <file url="PROJECT" charset="UTF-8" /> </component> </project>
misc.xml
<?xml version="1.0" encoding="UTF-8"?> <project version="4"> <component name="ProjectLevelVcsManager" settingsEditedManually="false"> <OptionsSetting value="true" id="Add" /> <OptionsSetting value="true" id="Remove" /> <OptionsSetting value="true" id="Checkout" /> <OptionsSetting value="true" id="Update" /> <OptionsSetting value="true" id="Status" /> <OptionsSetting value="true" id="Edit" /> <ConfirmationsSetting value="0" id="Add" /> <ConfirmationsSetting value="0" id="Remove" /> </component> <component name="ProjectRootManager" version="2" project-jdk-name="Python 2.7.11 (C:\Python27\python.exe)" project-jdk-type="Python SDK" /> </project>
modules.xml
<?xml version="1.0" encoding="UTF-8"?> <project version="4"> <component name="ProjectModuleManager"> <modules> <module fileurl="file://$PROJECT_DIR$/.idea/爬虫练习代码.iml" filepath="$PROJECT_DIR$/.idea/爬虫练习代码.iml" /> </modules> </component> </project>

本篇文章给大家带来了关于Python的相关知识,其中主要介绍了关于Seaborn的相关问题,包括了数据可视化处理的散点图、折线图、条形图等等内容,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于Python的相关知识,其中主要介绍了关于进程池与进程锁的相关问题,包括进程池的创建模块,进程池函数等等内容,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于Python的相关知识,其中主要介绍了关于简历筛选的相关问题,包括了定义 ReadDoc 类用以读取 word 文件以及定义 search_word 函数用以筛选的相关内容,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于Python的相关知识,其中主要介绍了关于数据类型之字符串、数字的相关问题,下面一起来看一下,希望对大家有帮助。

VS Code的确是一款非常热门、有强大用户基础的一款开发工具。本文给大家介绍一下10款高效、好用的插件,能够让原本单薄的VS Code如虎添翼,开发效率顿时提升到一个新的阶段。

本篇文章给大家带来了关于Python的相关知识,其中主要介绍了关于numpy模块的相关问题,Numpy是Numerical Python extensions的缩写,字面意思是Python数值计算扩展,下面一起来看一下,希望对大家有帮助。

pythn的中文意思是巨蟒、蟒蛇。1989年圣诞节期间,Guido van Rossum在家闲的没事干,为了跟朋友庆祝圣诞节,决定发明一种全新的脚本语言。他很喜欢一个肥皂剧叫Monty Python,所以便把这门语言叫做python。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

SublimeText3 英文版
推薦:為Win版本,支援程式碼提示!

mPDF
mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。