国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

使用python進行文本預處理和提取特征的實例

2020-02-15 21:39:30
字體:
來源:轉載
供稿:網友

如下所示:

<strong><span style="font-size:14px;">文本過濾</span></strong> 
result = re.sub(r'[^/u4e00-/u9fa5,。?!,、;:“ ”‘ '( )《 》〈 〉]', "", content)#只保留中文和標點 
result = re.sub(r'[^/u4e00-/u9fa5]', "",content)#只保留中文 result = re.sub(r'[^/0-9/./u4e00-/u9fa5,。?!,、;:“ ”‘ '( )《 》〈 〉]', "", content)#只保留中文和標點和數字 result = re.sub(r'[^/u4e00-/u9fa5,A-Za-z0-9]', "",content)#只保留中文、英文和數字 

文本去除兩個以上空格

content=re.sub(r'/s{2,}', '', content)

bas4編碼變成中文

def bas4_decode(bas4_content):  decodestr= base64.b64decode(bas4_content)  result = re.sub(r'[^/0-9/./u4e00-/u9fa5,。?!,、;:“ ”‘ '( )《 》〈 〉]', "", decodestr.decode())#只保留中文和標點和數字  return result 

文本去停用詞

def text_to_wordlist(text):  result = re.sub(r'[^/u4e00-/u9fa5]', "",text)  f1_seg_list = jieba.cut(result)#需要添加一個詞典,來彌補結巴分詞中沒有的詞語,從而保證更高的正確率  f_stop = codecs.open("./stopword.txt","r","utf-8")  try:   f_stop_text = f_stop.read()  finally:   f_stop.close()  f_stop_seg_list = f_stop_text.split()   test_words = []   for myword in f1_seg_list:   if myword not in f_stop_seg_list:    test_words.append(myword)      return test_words 

文本特征提取

import jieba import jieba.analyse import numpy as np #import json import redef Textrank(content): result = re.sub(r'[^/u4e00-/u9fa5]', "",content) seg = jieba.cut(result)  jieba.analyse.set_stop_words('stopword.txt') keyList=jieba.analyse.textrank('|'.join(seg), topK=10, withWeight=False)  return keyListdef TF_IDF(content): result = re.sub(r'[^/u4e00-/u9fa5]', "",content) seg = jieba.cut(result)  jieba.analyse.set_stop_words('stopword.txt') keyWord = jieba.analyse.extract_tags(   '|'.join(seg), topK=10, withWeight=False, allowPOS=())#關鍵詞提取,在這里對jieba的tfidf.py進行了修改  return keyWord

以上這篇使用python進行文本預處理和提取特征的實例就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持武林站長站。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 珠海市| 阜城县| 信丰县| 青河县| 娄烦县| 集安市| 宁南县| 阿尔山市| 岑巩县| 东光县| 包头市| 鱼台县| 青河县| 盐山县| 金阳县| 渭源县| 镇巴县| 安达市| 札达县| 淄博市| 远安县| 开平市| 吉林市| 甘洛县| 宾川县| 巴中市| 永德县| 澎湖县| 读书| 剑河县| 永州市| 云安县| 雷波县| 宁城县| 巴青县| 军事| 津南区| 温州市| 江门市| 上杭县| 鄢陵县|