zoukankan      html  css  js  c++  java
  • Python——jieba库初使用

    今日一言:“从来不是让你把一次考试当成人生成败的赌注,
         只是想让你在足够年轻的时候体会一次全力以赴。”
                      ——《请回答1988》

    Python——jieba库初使用

    jieba库是一款优秀的 Python 第三方中文分词库,jieba 支持三种分词模式:精确模式、全模式和搜索引擎模式,下面是三种模式的特点。


    安装

    C:Users20152>pip install -i https://pypi.tuna.tsinghua.edu.cn/simple jieba
    Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
    Collecting jieba
      Downloading https://pypi.tuna.tsinghua.edu.cn/packages/c6/cb/18eeb235f833b726522d7ebed54f2278ce28ba9438e3135ab0278d979
    2a2/jieba-0.42.1.tar.gz (19.2 MB)
         |████████████████████████████████| 19.2 MB 373 kB/s
    Installing collected packages: jieba
        Running setup.py install for jieba ... done
    Successfully installed jieba-0.42.1

    初使用

    程序:

    import jieba

    var_str = "小鱼爱吃鱼,非偏振光有完全偏振光和部分偏振光"

    print(jieba.lcut(var_str))

    print(jieba.lcut(var_str, cut_all=True))

    print(jieba.lcut_for_search(var_str))

    运行结果:

    C:Users20152AppDataLocalProgramsPythonPython36python.exe C:/Users/20152/PycharmProjects/cvTest/venv/temp.py
    Building prefix dict from the default dictionary ...
    Loading model from cache C:Users20152AppDataLocalTempjieba.cache
    Loading model cost 0.656 seconds.
    Prefix dict has been built successfully.
    ['小鱼''爱吃鱼'',''非''偏振光''有''完全''偏振光''和''部分''偏振光']
    ['小鱼''爱吃鱼'',''非''偏振''偏振光''有''完全''偏振''偏振光''和''部分''偏振''偏振光']
    ['小鱼''爱吃鱼'',''非''偏振''偏振光''有''完全''偏振''偏振光''和''部分''偏振''偏振光']

    Process finished with exit code 0

  • 相关阅读:
    react typescript 子组件调用父组件
    Mongodb query查询
    CentOS虚拟机不能联网状况下yum方式从本地安装软件包(转载的)
    CentOS6.5 mini开启网络
    MySQL的InnoDB表如何设计主键索引-转自淘宝MySQL经典案例
    linux下安装mysql-community后起不来
    Eclipse 快捷键
    maven下载jta失败,自己本地安装jta库
    spring配置文件中id与name
    @autowired和@resource的区别
  • 原文地址:https://www.cnblogs.com/rcklos/p/12858414.html
Copyright © 2011-2022 走看看