python 文本单词提取和词频统计的实例
2019-01-15 00:03
1306 查看
这些对文本的操作经常用到, 那我就总结一下。 陆续补充。。。
操作:
strip_html(cls, text) 去除html标签
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 文本单词提取和词频统计的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。
您可能感兴趣的文章:
相关文章推荐
- python 文本单词提取和词频统计
- 【实例】python中文词频排序 + html提取文本工具下载链接
- 【python】统计文本中出现最多次的单词
- [置顶] Python生成词云图,TIIDF方法文本挖掘: 词频统计,词云图
- 使用Python+NLTK实现英文单词词频统计
- 统计一个英文文本的单词词频
- scala--三种文本特征提取(TF-IDF/Word2Vec/CountVectorizer)及Spark MLlib调用实例(Scala/Java/python)
- python---在文本/文章中统计字符串中出现单词次数
- python读取文件里的单词,统计词频,输出到文件
- Python 练习册 6-统计文本文件中的出现最多的单词
- 第0004道练习题_Python统计文本里单词出现次数
- PYTHON3.6对中文文本分词、去停用词以及词频统计
- python 统计文本单词数-字典排序
- Python 对文本先按词频统计,若相同按字典排序,后取TopN
- python统计文本字符串里单词出现频率的方法
- Python实现统计文本当中单词的数量,
- 用python统计文本里的单词出现次数最多的10个
- python结巴分词以及词频统计实例
- 编程统计一个英文文本文件中单词词频
- 【实例】词频统计及其可视化python+jieba+wordcloud