赞
踩
- #!usr/bin/env python
- #-*- coding:utf-8-*-
- import jieba
- import jieba.analyse
- import codecs
- file_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=0
- for 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+=1
- for keyword in keywords:
- (word,flag)=keyword[0]
- weight=keyword[1]
- f_result.write('\"word\&
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。