文章提取关键词_jieba(IF-IDF/TextRank)
来源:互联网 发布:笨方法学python ex26 编辑:程序博客网 时间:2024/05/24 05:06
1、基于TextRank的提取文章关键词:extract_keyword_textrank.py:
2.基于IF-IDF的提取文章关键词extract_keywod_ifidf.py:
#!usr/bin/env python#-*- coding:utf-8-*-import jiebaimport jieba.analyseimport codecsfile_path='./data/000000_0'result_file_path="./data/000000_0_result_textrank"f=open(file_path,'r')f_result=codecs.open(result_file_path,'w+','utf-8')f_result.write('[\n')texts=f.readlines()num_text=0for text in texts:text_id=texts.split('\t')[0]text_content=texts.split('\t')[3]f_result.write('{\"text_id\": %s\n'% text_id)keywords=jieba.analyse.textrank(text_content,topK=20,withWeight=True,allowPOS=('ns', 'n', 'vn', 'v'),withFlag=True)f_result.write('\"keyword\":{')num_text+=1for keyword in keywords:(word,flag)=keyword[0]weight=keyword[1]f_result.write('\"word\":%s,\"weight\":%s,\"nature\": %s\n'% (word,weight,flag))f_result.write('}\n')if num_text%100=0:print "已经处理%s篇文章" % num_textf_result.write(']\n')print "总共处理%s篇文章" num_textf_result.close()f.close()
2.基于IF-IDF的提取文章关键词extract_keywod_ifidf.py:
#!usr/bin/env python#-*- coding:utf-8-*-import jiebaimport jieba.analyseimport codecsfile_path='./data/000000_0'result_file_path="./data/000000_0_result_ifidf"f=open(file_path,'r')f_result=codecs.open(result_file_path,'w+','utf-8')f_result.write('[')texts=f.readlines()num_text=0for text in texts:text_id=texts.split('\t')[0]text_content=texts.split('\t')[3]f_result.write('{\"text_id\": %s\n'% text_id)keywords=jieba.analyse.extract_tags(text_content,topK=20,withWeight=True,allowPOS=('ns', 'n', 'vn', 'v'),withFlag=True)f_result.write('\"keyword\":{')num_text+=1for keyword in keywords:(word,flag)=keyword[0]weight=keyword[1]f_result.write('\"word\":%s,\"weight\":%s,\"nature\": %s\n'% (word,weight,flag))f_result.write('}')if num_text%100=0:print "已经处理%s篇文章" % num_textf_result.write(']')print "总共处理%s篇文章" %num_textf_result.close()f.close()
0 0
- 文章提取关键词_jieba(IF-IDF/TextRank)
- textrank关键词提取
- textrank提取文档关键词
- 关键词提取算法-TextRank
- 利用TF-IDF 提取文章关键词
- TF-IDF提取文章关键词算法
- 关键词提取之TextRank算法
- 笔记-TextRank与关键词提取
- textrank 关键词提取-python实现
- tf-idf使用-提取文章关键词-搜索文章
- TF-IDF提取关键词
- TF-IDF提取关键词
- TextRank算法提取关键词的Java实现
- 基于TextRank的关键词、短语、摘要提取
- TextRank算法提取关键词的Java实现
- TextRank 算法提取关键词的 Java 实现
- 基于TextRank的关键词提取算法
- [NLP技术]关键词提取算法-TextRank
- ToggleButton 自定义控件的哪些坑
- apache ftp相关问题整理
- 百度指数词简单描述
- 一只小蜜蜂 hd 2044
- IIC总线时序详解
- 文章提取关键词_jieba(IF-IDF/TextRank)
- LintCode-两个链表的和sum
- 在VS中添加lib库的三种方法
- 【链接】Xcode升级之后安装插件管理工具
- 整形转换成字符串
- SharePoint
- 杭电1062(Text Reverse)字符串翻转问题
- ASP.NET中如何获取上传图片的宽和高
- TCP客户/服务器程序实例