当前位置:网站首页>结巴分词器_分词器原理
结巴分词器_分词器原理
2022-06-28 09:22:00 【Java架构师必看】
大家好,我是架构君,一个会写代码吟诗的架构师。今天说一说结巴分词器_分词器原理,希望能够帮助大家进步!!!
安装jieba库:pip3 install jieba
#结巴分词
# -*- coding:utf-8 -*-
import sys
import os
import jiebasent = '天善智能是一个专注于商业智能BI、数据分析、数据挖掘和大数据技术领域的技术社区 www.hellobi.com 。内容从最初的商业智能 BI 领域也扩充到了数据分析、数据挖掘和大数据相关 的技术领域,包括 R、Python、SPSS、Hadoop、Spark、Hive、Kylin等,成为一个专注于数据领域的垂直社区。天善智能致力于构建一个基于数据领域的生态圈,通过社区链接一切 与数据相关的资源:例如数据本身、人、数据方案供应商和企业,与大家一起共同努力推动大数据、商业智能BI在国内的普及和发展。'
print (sent)结巴分词模块有三种分词模式:
1. 全模式 :把句子中所有可以成词的词语都扫描出来,速度非常快,但是不能解决歧义。这种全模式,会根据字典,将所有出现的字词全部匹配划分,所以会出现重复,显然,这不是我们需要的。
2.精确模式 :试图将句子最精确地切开,适合文本分析(类似LTP分词方式),而这种精确模式就比较接近我们想要的了。
3.搜索引擎模式:在精确模式的基础上对长词再次切分,提高召回率,适合用于搜索引擎分词。这种搜索引擎模式也不错呢,更加细化了。
#全模式
wordlist = jieba.cut(sent,cut_all = True)
print('|'.join(wordlist))#精确切分
wordlist = jieba.cut(sent)
print('|'.join(wordlist)) #搜索引擎模式
wordlist = jieba.cut_for_search(sent)
print('|'.join(wordlist))发现新问题--增加用户自定义词典:回看精确模式的结果,发现有些新词汇或者专业词汇,例如:天善智能、大数据,这些不应该再被切分,所以在默认词典的基础上,我们可以加载自定义的词典。进入我的jieba模块目录->看到有个dict的词典,打开->发现有 1.词 2.数字(代表词频,越高越容易匹配到) 3.词性。为了方便,我们自己定义添加一个词典命名为userdict.txt
#增加用户自定义字典
#使用用户字典
jieba.load_userdict('D:\\Anaconda3\\Lib\\site-packages\\jieba\\userdict.txt')
wordlist = jieba.cut(sent)
print('|'.join(wordlist)) 参考资料:
https://zhuanlan.zhihu.com/p/29747350?utm_source=qq&utm_medium=social&utm_oi=780081763178258432
今天文章到此就结束了,感谢您的阅读,Java架构师必看祝您升职加薪,年年好运。
边栏推荐
- PMP考试重点总结四——规划过程组(2)
- A classic JVM class loaded interview question class singleton{static singleton instance = new singleton(); private singleton() {}
- Is it safe for CICC fortune to open an account? How much do you charge?
- Summary of PMP learning experience
- 手机买同业存单基金开户选哪家证券公司比较好,比较安全呢
- 虚拟机14安装win7(图教程)
- Two interview demo
- JDBC connection database (MySQL) steps
- Find the total number of 1 appearing in the integer 1-N and the number of 1 in the binary of the integer
- SQL injection file read / write
猜你喜欢

Decision table method for basic content learning of software testing (2)

APICloud携手三六零天御,助力企业守好App安全“第一关”

Dbeaver连接人大金仓KingbaseES V8(超详细图文教程)

PMP考试重点总结六——图表整理

new URL(“www.jjj.com“)

JMeter -- interface test 2

Use of Jasper soft studio report tool and solution of thorny problems

This article explains in detail the difficult problems and solutions faced by 3D cameras

redis5.0的槽点迁移,随意玩(单机迁移集群)

PMP考试重点总结五——执行过程组
随机推荐
线程的生命周期
数字人行业爆发在即,市场格局几何?
P2394 yyy loves Chemistry I
手机炒股开户安不安全?
The concept of "tree structure" perfectly interprets the primary and secondary of things
Screen settings in the source code of OBS Live Room
When the interviewer asks you to write binarysort in two ways
SQL 优化经历:从 30248秒到 0.001秒的经历
Divide and rule classic Hanoi
Calcul des frais d'achat et de vente d'actions
PMP考试重点总结五——执行过程组
构造方法绝不是在new()之后就立马执行!!!!!
Full link service tracking implementation scheme
线程和进程
静态代码块永远先执行? 格局小了!!!
我想网上注册股票开户,如何操作?在线开户安全么?
Two interview demo
为什么SELECT * 会导致查询效率低?
Valentine's Day - VBS learning (sentences, love words)
Understanding the IO model