当前位置:网站首页>结巴分词器_分词器原理
结巴分词器_分词器原理
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架构师必看祝您升职加薪,年年好运。
边栏推荐
- 玩玩sftp上传文件
- new URL(“www.jjj.com“)
- 01-分布式系统概述
- Screen settings in the source code of OBS Live Room
- Understanding the IO model
- Static page of pinyougou mall
- Illustration of MySQL binlog, redo log and undo log
- Fastjason filter field
- Data modeling based on wide table
- 1180: fractional line delimitation /p1068 [noip2009 popularization group] fractional line delimitation
猜你喜欢

Installation of containerd1.5.5

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

1182:合影效果

虚拟机14安装win7(图教程)

File operations in QT

104. maximum depth of binary tree

Stock suspension

Valentine's Day - VBS learning (sentences, love words)

STL -- binder

为什么SELECT * 会导致查询效率低?
随机推荐
Fastjason filter field
The private attribute of this class can be used directly? New() in use!!!
Postman interface test
STL - inverter
1182: effets de la photo de groupe
Calcul des frais d'achat et de vente d'actions
A classic JVM class loaded interview question class singleton{static singleton instance = new singleton(); private singleton() {}
什么是在线开户?现在网上开户安全么?
分而治之之经典Hanoi
为什么SELECT * 会导致查询效率低?
Do static code blocks always execute first? The pattern is smaller!!!
手机买同业存单基金开户选哪家证券公司比较好,比较安全呢
PMP考试重点总结七——监控过程组(1)
Understanding the IO model
RMAN backup message ora-19809 ora-19804
How to implement two factor authentication MFA based on RADIUS protocol?
Is it safe to open an account for online stock speculation?
P2394 yyy loves Chemistry I
01 distributed system overview
SQL 优化经历:从 30248秒到 0.001秒的经历