zoukankan      html  css  js  c++  java
  • jieba

    (1)、jieba分词的三种模式

         精确模式、全模式、搜索引擎模式
    
         - 精确模式:把文本精确的切分开,不存在冗余单词
         - 全模式:把文本中所有可能的词语都扫描出来,有冗余
    
         - 搜索引擎模式:在精确模式基础上,对长词再次切分
    

    (2)、jieba库常用函数

    (3)、实例

    import  jieba
    
    txt = open("D:\三国演义.txt", "r", encoding='utf-8').read()
    words = jieba.lcut(txt)     # 使用精确模式对文本进行分词
    counts = {}     # 通过键值对的形式存储词语及其出现的次数
    
    for word in words:
        if  len(word) == 1:    # 单个词语不计算在内
            continue
        else:
            counts[word] = counts.get(word, 0) + 1    # 遍历所有词语,每出现一次其对应的值加 1
            
    items = list(counts.items())#将键值对转换成列表
    items.sort(key=lambda x: x[1], reverse=True)    # 根据词语出现的次数进行从大到小排序
    
    for i in range(15):
        word, count = items[i]
        print("{0:<5}{1:>5}".format(word, count))
    
  • 相关阅读:
    webpack 知识点
    freemarker知识点
    js知识点
    oracle 安装介绍
    CentOS 7.4x64 系统安装完成后配置
    centos 7 互信【ssh】
    spark与mapreduce的最大区别和spark原理
    最简单的搭建SpringBoot框架步骤
    simplify(s)
    ezplot函数
  • 原文地址:https://www.cnblogs.com/whnbky/p/14252155.html
Copyright © 2011-2022 走看看