zoukankan      html  css  js  c++  java
  • 智联招聘的python岗位数据结巴分词(二)

    上次获取第一次分词之后的内容了

    但是数据数据量太大了 ,这时候有个模块就派上用场了collections模块的Counter类

    Counter类:为hashable对象计数,是字典的子类。

    然后使用most_common方法返回一个TopN列表。如果n没有被指定,则返回所有元素。当多个元素计数值相同时,排列是无确定顺序的。

    def get_top_words(topn):
    
        # 从out.txt中读取带词性的分词结果列表
        words_with_attr = read_result()
    
        # 要过滤掉的词性列表
        stop_attr = ['a', 'ad', 'b', 'c', 'd', 'f', 'df', 'm', 'mq', 'p', 'r', 'rr', 's', 't', 'u', 'v', 'z']
    
        # 过滤掉不需要的词性的词
        words = [x[0] for x in words_with_attr if x[1] not in stop_attr]
    
        # 获取topn的词并存入文件topn_words.txt,top_words_with_freq为一个字典,在生成词云的时候会用到,格式为:
        # {'aa':1,'bb':2,'cc':3}
        top_words_with_freq = get_topn_words(words=words, topn=topn)
    
        return top_words_with_freq
    def get_topn_words(words, topn):
        c = Counter(words).most_common(topn) #获取topn列表
        top_words_with_freq = {}
        with open('top{0}_words.txt'.format(topn), 'w+') as f:
            for x in c:
                f.write('{0},{1}
    '.format(x[0], x[1]))
                top_words_with_freq.setdefault(x[0],x[1])
        return top_words_with_freq
    

      

    接下来就是把这个topn的列表进行分词了

  • 相关阅读:
    基于对象颜色的对象检测(翻译)
    根据颜色和大小来检测和跟踪实时网络摄像机中的对象(翻译)
    C# 笔记 基础(2)
    C#学习笔记 基础 (1)
    深入学习RBAC系列模型——RBAC0模型的开发与学习心得
    RBAC权限管理
    SSL协议的工作流程
    页面的加载
    java实例化对象的方式
    cron表达式详解 原创
  • 原文地址:https://www.cnblogs.com/c-x-a/p/8511971.html
Copyright © 2011-2022 走看看