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

首頁 > 編程 > Python > 正文

python 文本單詞提取和詞頻統(tǒng)計的實(shí)例

2020-02-16 00:15:17
字體:
供稿:網(wǎng)友

這些對文本的操作經(jīng)常用到, 那我就總結(jié)一下。 陸續(xù)補(bǔ)充。。。

操作:

strip_html(cls, text) 去除html標(biāo)簽

separate_words(cls, text, min_lenth=3) 文本提取

get_words_frequency(cls, words_list) 獲取詞頻

源碼:

class DocProcess(object): @classmethod def strip_html(cls, text):  """   Delete html tags in text.   text is String  """  new_text = " "  is_html = False  for character in text:   if character == "<":    is_html = True   elif character == ">":    is_html = False    new_text += " "   elif is_html is False:    new_text += character  return new_text @classmethod def separate_words(cls, text, min_lenth=3):  """   Separate text into words in list.  """  splitter = re.compile("http://W+")  return [s.lower() for s in splitter.split(text) if len(s) > min_lenth] @classmethod def get_words_frequency(cls, words_list):  """   Get frequency of words in words_list.   return a dict.  """  num_words = {}  for word in words_list:   num_words[word] = num_words.get(word, 0) + 1  return num_words

以上這篇python 文本單詞提取和詞頻統(tǒng)計的實(shí)例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持武林站長站。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 石嘴山市| 阳江市| 杭州市| 凤山市| 新田县| 乌恰县| 绵阳市| 开阳县| 大方县| 西宁市| 溧阳市| 郓城县| 南陵县| 舒兰市| 霍邱县| 河西区| 青海省| 乌审旗| 安吉县| 张北县| 永修县| 东辽县| 邹城市| 泰顺县| 乳山市| 得荣县| 宁强县| 横山县| 万州区| 南召县| 渑池县| 新巴尔虎左旗| 水富县| 海阳市| 大化| 德格县| 剑河县| 行唐县| 阿拉善右旗| 双柏县| 龙州县|