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

  • 相关阅读:
    第十九章:UTC time和local time的互换
    第二十章:安全性
    第十三章:基于socket.io实现即时通信
    第三章:ionic环境搭建之windows篇
    第十八章:自定义splash screen、app icon和tab icon
    第十七章:使用media插件来播放声音
    第一章:hybrid app开发之技术选型
    第十六章:自定义push notification sound
    第十五章:集成JPUSH
    ionic resources
  • 原文地址:https://www.cnblogs.com/rcklos/p/12858414.html
Copyright © 2011-2022 走看看