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的列表进行分词了

  • 相关阅读:
    linux下svn命令大全
    php常用函数
    在centos上设置计划任务
    sphinx使用心得
    sphinx2.8.8的配置文件
    Mac使用
    sftp
    uwp应用在debug模式下运行正常,编译为release版本的时候抛出异常
    win10 uwp 读取resw资源文件
    dll被设置为用记事本打开的解决方法
  • 原文地址:https://www.cnblogs.com/c-x-a/p/8511971.html
Copyright © 2011-2022 走看看