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

首頁(yè) > 編程 > Python > 正文

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

2020-01-04 13:44:53
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

這些對(duì)文本的操作經(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("//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)計(jì)的實(shí)例就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持VEVB武林網(wǎng)。


注:相關(guān)教程知識(shí)閱讀請(qǐng)移步到python教程頻道。
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 清河县| 临西县| 大姚县| 临澧县| 珲春市| 宣威市| 方山县| 太仆寺旗| 辽宁省| 开鲁县| 南昌县| 永宁县| 治县。| 鄯善县| 常宁市| 临潭县| 同德县| 柏乡县| 五台县| 桂阳县| 浦北县| 佛山市| 乐清市| 怀远县| 沙河市| 慈利县| 峨山| 修水县| 岗巴县| 巩义市| 高台县| 灵璧县| 樟树市| 长垣县| 罗源县| 凉城县| 阳西县| 晋城| 井研县| 集贤县| 清涧县|