前端技术
HTML
CSS
Javascript
前端框架和UI库
VUE
ReactJS
AngularJS
JQuery
NodeJS
JSON
Element-UI
Bootstrap
Material UI
服务端和客户端
Java
Python
PHP
Golang
Scala
Kotlin
Groovy
Ruby
Lua
.net
c#
c++
后端WEB和工程框架
SpringBoot
SpringCloud
Struts2
MyBatis
Hibernate
Tornado
Beego
Go-Spring
Go Gin
Go Iris
Dubbo
HessianRPC
Maven
Gradle
数据库
MySQL
Oracle
Mongo
中间件与web容器
Redis
MemCache
Etcd
Cassandra
Kafka
RabbitMQ
RocketMQ
ActiveMQ
Nacos
Consul
Tomcat
Nginx
Netty
大数据技术
Hive
Impala
ClickHouse
DorisDB
Greenplum
PostgreSQL
HBase
Kylin
Hadoop
Apache Pig
ZooKeeper
SeaTunnel
Sqoop
Datax
Flink
Spark
Mahout
数据搜索与日志
ElasticSearch
Apache Lucene
Apache Solr
Kibana
Logstash
数据可视化与OLAP
Apache Atlas
Superset
Saiku
Tesseract
系统与容器
Linux
Shell
Docker
Kubernetes
[词典]的搜索结果
这里是文章列表。热门标签的颜色随机变换,标签颜色没有特殊含义。
点击某个标签可搜索标签相关的文章。
点击某个标签可搜索标签相关的文章。
Java
...算机领域的分词器词汇词典:点这里传送过去 但这里面只有计算机领域的术语,对于常用中文,比如“吃饭”、“逛街”...等词汇是不包括的。 所以,如果大家需要对日常中文文章或语料做分词,需要用这里的词典。两个词典可以并存,配置到分词器的配置文件中。 2. 下载地址 点我免费下载 词库txt文件一览(49万多个词汇): 建议:如果你的程序对分词比较敏感,请务必先小范围用少量样本测试试用,看看分词效果是否符合预期,没有问题再放入正式环境。 3. 分词器使用 关于分词器的使用,见本文第一小节的链接,那个链接里面有介绍。 如果你是用的是IKAnalyzer,可以把新的词典加入到配置文件中:IKAnalyzer.cfg.xml 4. 补充说明 尽管该文章以IKAnalyzer为例,但是这个词典是通用的,它的格式是“词汇1\n词汇2\n词汇3\n”,即用回车符分隔的一个个词汇。很多分词器都是通用的。 分词器有很多,大家根据实际需求选择使用。比如: IK Analyzer:一款基于Java开发的开源中文分词工具,广泛应用于Elasticsearch和Solr中。 Ansj:一个高效的Java分词框架,支持多种分词模式如最大匹配、最小切分等。 Stanford Segmenter:斯坦福大学提供的分词器,基于统计模型和规则,具有较高的准确性。 FudanNLP分词器:复旦大学自然语言处理小组研发的分词系统。 jieba分词:Python社区中流行的开源中文分词库,支持精确模式、全模式、搜索引擎模式等多种分词模式。 LTP(哈工大 Language Technology Platform)分词器:哈尔滨工业大学开发的一套全面的自然语言处理工具包,其中包含高质量的分词模块。 THULAC:由清华大学自然语言处理与社会人文计算实验室推出的分词和词性标注工具。 HanLP:由李航团队开发的自然语言处理库,包含高效准确的分词组件。
2024-01-27 19:37:56
371
admin-tim
Java
...文的分词,就需要维护词典。 现在已经有很多非常好用的中文分词器,大家都是基于词典进行分词。但是词典一般是常用词的词典,如果你的文章领域是计算机领域,可能就需要自己扩充词典。 比如“合并排序树”,在计算机领域可以作为一个单独的词,但使用未加载计算机词典的分词器可能就会分词为——二叉、排序、树。但有的时候我们也想让它作为一个独立的词出现,这样可能会在搜索逻辑中会获得更高的匹配得分,或有其它的更多用途。 2. 下载地址 点我免费下载 改词典是站长用ai训练并整理的,这一版本包含6万多个计算机领域的词汇,能为你的工作带来一些帮助,非常高兴! 但可能也有些不属于计算机领域的词汇被误整理了进去,但对分词逻辑应该是无害的。 词库txt文件一览(60721个词汇): 建议:如果你的程序对分词比较敏感,请务必先小范围用少量样本测试试用,看看分词效果是否符合预期,没有问题再放入正式环境。 3. java示例 这里用IKAnalyzer举例,IKAnalyzer的示例网上有很多,这里简要描述。 3.1 依赖下载 这里提供一个阿里云的仓库,你可以搜索并下载得到对应dependency的坐标并引入到你的pom.xml里面: 阿里云仓库:https://developer.aliyun.com/mvn/search <dependency> <groupId>com.janeluo</groupId> <artifactId>ikanalyzer</artifactId> <version>2012_u6</version> </dependency> 初次以外,你还要引入一个lucene的依赖: <dependency> <groupId>org.apache.lucene</groupId> <artifactId>lucene-core</artifactId> <version>3.6.0</version> </dependency> 3.2 java代码 public static void cut(String text) throws IOException { List terms = new ArrayList(); try (StringReader sr = new StringReader(text)) { IKSegmenter ik = new IKSegmenter(sr, false); Lexeme lex = null; while ((lex = ik.next()) != null) { terms.add(lex.getLexemeText()); } } System.out.println(JSON.toJSONString(terms)); } 用main函数或你代码中的上游逻辑调用上述cut代码,即可输出分词结果。 3.3 加入新的词典 你需要在classpath下面引入IKAnalyzer的配置文件:IKAnalyzer.cfg.xml 并把上边下载好的词典引入进去,如下图: 3.4 切换分词模式 熟悉IKAnalyzer的朋友都知道它有两个分词模式:ik_max_word和ik_smart 在3.2的代码中可以用“new IKSegmenter(sr, false)”的第二个参数做切换,为true则是ik_smart,为false则是ik_max_word。 4. 效果对比测试 这里对下面两个字符串做分词效果测试: String text1 = "阿姆斯里克数据处理查询解析引擎"; String text2 = "基于java语言开发的轻量级的中文分词工具包"; 4.1 未引入新词典的分词效果 4.2 引入新词典的分词效果 上图可以看到,比如“查询解析引擎”、“中文分词工具包”这类的词已经被分词器切割出来了,这在没有新词典的情况下是无法完成的。 5. 补充说明 尽管该文章以IKAnalyzer为例,但是这个词典是通用的,它的格式是“词汇1\n词汇2\n词汇3\n”,即用回车符分隔的一个个词汇。很多分词器都是通用的。 文章是原创的,词典是站长整理的,如有转载,请注明出处,表示感谢!
2024-01-26 17:33:58
408
admin-tim
转载文章
...架中查阅图灵计算机大词典: thumbnail adj. 极小的, 极短的; n. 大拇指的指甲, 极小之物; n. 拇指甲(草图);adj.简略的,缩略的(拇指甲大小的,小型的); n. 极小的图片, 小的代表大的更多细节的图片 (计算机用语); thumbnail 在Bootstrap框架中真实含义: n.【计】缩略图。 thumbnail在美工用来具体表现布局方式表达: 大致相当亦为效果图及缩略图,很小(大约为3×4英寸),缩略了细节比较粗糙,是最基本的东西。 直线或水波纹表示正文的位置,方框表示图形的位置。然后,中选的小样再进一步发展。 以下举个案例: a元素超链接thumbnail呈缩略图构成 <div class="col-xs-6 col-md-3"> </div>: <div class="container"> <div class="row"> <div class="col-xs-6 col-md-3"> <a href="" class="thumbnail"> <img src="../image/HAIAN.jpg" alt="180x100%" style="height: 180px;width: 100%;display: block;"> </a> </div> <div class="col-xs-6 col-md-3"> <a href="" class="thumbnail"> <img src="../image/HAIAN.jpg" alt="180x100%" style="height: 180px;width: 100%;display: block;"> </a> </div> <div class="col-xs-6 col-md-3"> <a href="" class="thumbnail"> <img src="../image/HAIAN.jpg" alt="180x100%" style="height: 180px;width: 100%;display: block;"> </a> </div> <div class="col-xs-6 col-md-3"> <a href="" class="thumbnail"> <img src="../image/HAIAN.jpg" alt="180x100%" style="height: 180px;width: 100%;display: block;"> </a> </div> </div> </div> 本篇文章为转载内容。原文链接:https://blog.csdn.net/sinat_34719507/article/details/53576257。 该文由互联网用户投稿提供,文中观点代表作者本人意见,并不代表本站的立场。 作为信息平台,本站仅提供文章转载服务,并不拥有其所有权,也不对文章内容的真实性、准确性和合法性承担责任。 如发现本文存在侵权、违法、违规或事实不符的情况,请及时联系我们,我们将第一时间进行核实并删除相应内容。
2023-06-08 11:31:22
299
转载
Apache Solr
...词,我们可以通过增加词典或者训练新的模型来进行处理。 六、总结 Apache Lucene和Solr为我们提供了一种方便的方式来实现中文分词和处理。然而,由于中文的复杂性,我们在实际应用中还需要不断地探索和优化,以提高分词的准确性和效率。 七、结语 随着人工智能的发展,自然语言处理将会变得越来越重要。希望通过这篇文章,大家能了解到如何使用Apache Lucene和Solr实现中文分词和处理,并能够从中受益。同时,我们也期待在未来能够看到更多更好的中文处理工具和技术。
2024-01-28 10:36:33
391
彩虹之上-t
Apache Lucene
...玩转起来,比如自定义词典、同义词扩展这些小玩意儿,都得弄得明明白白。 思考过程:在实践中,不断优化分析器配置,甚至开发定制化分析组件,都是为了提高搜索结果的相关性和准确性。例如,针对特定领域或行业术语,可能需要加载额外的词典以改善召回率。 结论: Apache Lucene提供了一个强大而灵活的基础框架,使得开发者能够轻松应对多语言搜索场景。虽然每种语言都有它独一无二的语法和表达小癖好,但有了Lucene这个精心打磨的分析器大家族,我们就能轻轻松松地搭建并管理一个兼容各种语言的搜索引擎,效率杠杠滴!甭管是全球各地的产品文档你要检索定位,还是在那些跨国大项目里头挖寻核心信息,Lucene都妥妥地成了应对这类技术难题的一把好手。在不断摸索和改进的过程中,我们不仅能亲自体验到Lucene那股实实在在的威力,而且每当搜索任务顺利完成时,就像打开一个惊喜盲盒,总能收获满满的成就感和喜悦感,这感觉真是太棒了!
2023-06-25 08:13:22
531
彩虹之上
Apache Lucene
...登录词是指在分词器的词典中没有出现过的词。比如新出现的产品名称、人名等。这些词如果处理不当,会影响搜索结果的准确性。 解决方案:可以使用一些启发式的方法,如基于规则的匹配或者使用机器学习模型来识别这些未登录词,并赋予它们合适的标签。 代码示例: java // 示例:如果发现未登录词,可以将其标记为"未登录词" public void handleOutofVocabWord(String word) { System.out.println("发现未登录词:" + word); } 3.3 词干提取问题 问题描述:词干提取是将词变为其基本形式的过程,比如将“跳跃”变为“跳”。然而,错误的词干提取会导致词义的丢失。比如说,把“跳跃”错提取成“跳”,看着是简单了,但可能会漏掉一些重要的意思。 解决方案:选择合适的词干提取算法很重要。Lucene 提供了多种词干提取器,可以根据不同的语言和需求进行选择。 代码示例: java // 使用Snowball词干提取器 Analyzer analyzer = new StandardAnalyzer(); TokenStream tokenStream = analyzer.tokenStream("content", "跳跃"); tokenStream.reset(); while (tokenStream.incrementToken()) { System.out.println(tokenStream.getAttribute(CharTermAttribute.class).toString()); } 3.4 词性标注问题 问题描述:词性标注是指为每个词分配一个词性标签,如名词、动词等。弄错了词语的类型可会影响接下来的各种操作,比如说会让分析句子结构的结果变得不那么准确。 解决方案:可以使用外部工具,如Stanford CoreNLP或NLTK来进行词性标注,然后再结合到Lucene的分词流程中。 代码示例: java // 示例:使用Stanford CoreNLP进行词性标注 Properties props = new Properties(); props.setProperty("annotators", "tokenize, ssplit, pos"); StanfordCoreNLP pipeline = new StanfordCoreNLP(props); String text = "跳跃是一种有趣的活动"; Annotation document = new Annotation(text); pipeline.annotate(document); List sentences = document.get(CoreAnnotations.SentencesAnnotation.class); for (CoreMap sentence : sentences) { for (CoreLabel token : sentence.get(CoreAnnotations.TokensAnnotation.class)) { String word = token.get(CoreAnnotations.TextAnnotation.class); String pos = token.get(CoreAnnotations.PartOfSpeechAnnotation.class); System.out.println(word + "/" + pos); } } 4. 总结 通过上面的讨论,我们可以看到,分词虽然是全文检索中的基础步骤,但其实充满了挑战。每种语言都有自己的特点和难点,我们需要根据实际情况灵活应对。希望今天的分享对你有所帮助! 好了,今天的分享就到这里啦!如果你有任何疑问或想法,欢迎留言交流。咱们下次再见!
2025-01-09 15:36:22
87
星河万里
PostgreSQL
...一本按字母顺序排列的词典中查找词汇时,索引就如同那目录页,让你迅速找到目标单词所在的页面。在PostgreSQL中,最常见的索引类型是B树索引,它能高效地支持范围查询和等值查询。 sql -- 创建一个简单的B树索引示例 CREATE INDEX idx_employee_name ON employees (first_name, last_name); 上述代码会在employees表的first_name和last_name列上创建一个多字段B树索引,这样当我们查找特定员工姓名时,数据库能够快速定位到相关记录。 2. 索引的可视化与验证 虽然索引自身并不直接显示数据,但我们可以通过查询系统表来查看索引信息,间接了解其内容和作用效果。例如: sql -- 查看已创建的索引详情 SELECT FROM pg_indexes WHERE tablename = 'employees'; -- 或者查看索引大小和统计信息 ANALYZE idx_employee_name; 这些操作有助于我们评估索引的有效性和利用率,而不是直接看到索引存储的具体值。 3. 表达式索引的妙用 有时,我们可能需要基于某个计算表达式的值来建立索引,这就是所谓的“表达式索引”。这就像是你整理音乐播放列表,把歌曲按照时长从小到大或者从大到小排个队。虽然实际上你的手机或电脑里存的是每首歌的名字和文件地址,但为了让它们按照时长排列整齐,系统其实是在根据每首歌的时长给它们编了个索引号。 sql -- 创建一个基于年龄(假设从出生日期计算)的表达式索引 CREATE INDEX idx_employee_age ON employees ((EXTRACT(YEAR FROM age(birth_date)))); 此索引将根据员工的出生日期计算出他们的年龄并据此排序,对于按年龄筛选查询特别有用。 4. 并发创建索引与生产环境考量 在大型应用或繁忙的生产环境中,创建索引可能会对业务造成影响。幸运的是,PostgreSQL允许并发创建索引,以尽量减少对读写操作的影响: sql -- 使用CONCURRENTLY关键字创建索引,降低阻塞 CREATE INDEX CONCURRENTLY idx_employee_salary ON employees (salary); 这段代码会创建一个与现有业务并发运行的索引构建任务,使得其他查询可以继续执行,而不必等待索引完成。 结语 虽然我们无法直接通过索引来“显示”数据,但通过合理创建和利用索引,我们可以显著提升数据库系统的响应速度,从而为用户提供更好的体验。在PostgreSQL的世界里,捣鼓索引的学问,就像是在破解一个数据库优化的神秘谜团。每一个我们用心打造的索引,都像是朝着高性能数据库架构迈进的一块积木,虽然小,但却至关重要,步步为赢。每一次实践,都伴随着我们的思考与理解,让我们愈发深刻体会到数据库底层逻辑的魅力所在。下次当你面对庞大的数据集时,别忘了这个无声无息却无比强大的工具——索引,它正静候你的指令,随时准备为你提供闪电般的查询速度。
2023-06-04 17:45:07
409
桃李春风一杯酒_
转载文章
...繁体分词 支持自定义词典 MIT 授权协议 安装说明 代码对 Python 2/3 均兼容 全自动安装:easy_install jieba 或者 pip install jieba / pip3 install jieba 半自动安装:先下载 http://pypi.python.org/pypi/jieba/ ,解压后运行 python setup.py install 手动安装:将 jieba 目录放置于当前目录或者 site-packages 目录 通过 import jieba 来引用 如果需要使用paddle模式下的分词和词性标注功能,请先安装paddlepaddle-tiny,pip install paddlepaddle-tiny==1.6.1。 算法 基于前缀词典实现高效的词图扫描,生成句子中汉字所有可能成词情况所构成的有向无环图 (DAG) 采用了动态规划查找最大概率路径, 找出基于词频的最大切分组合 对于未登录词,采用了基于汉字成词能力的 HMM 模型,使用了 Viterbi 算法 主要功能 分词 jieba.cut 方法接受四个输入参数: 需要分词的字符串;cut_all 参数用来控制是否采用全模式;HMM 参数用来控制是否使用 HMM 模型;use_paddle 参数用来控制是否使用paddle模式下的分词模式,paddle模式采用延迟加载方式,通过enable_paddle接口安装paddlepaddle-tiny,并且import相关代码; jieba.cut_for_search 方法接受两个参数:需要分词的字符串;是否使用 HMM 模型。该方法适合用于搜索引擎构建倒排索引的分词,粒度比较细 待分词的字符串可以是 unicode 或 UTF-8 字符串、GBK 字符串。注意:不建议直接输入 GBK 字符串,可能无法预料地错误解码成 UTF-8 jieba.cut 以及 jieba.cut_for_search 返回的结构都是一个可迭代的 generator,可以使用 for 循环来获得分词后得到的每一个词语(unicode),或者用 jieba.lcut 以及 jieba.lcut_for_search 直接返回 list jieba.Tokenizer(dictionary=DEFAULT_DICT) 新建自定义分词器,可用于同时使用不同词典。jieba.dt 为默认分词器,所有全局分词相关函数都是该分词器的映射。 代码示例 encoding=utf-8import jiebajieba.enable_paddle() 启动paddle模式。 0.40版之后开始支持,早期版本不支持strs=["我来到北京清华大学","乒乓球拍卖完了","中国科学技术大学"]for str in strs:seg_list = jieba.cut(str,use_paddle=True) 使用paddle模式print("Paddle Mode: " + '/'.join(list(seg_list)))seg_list = jieba.cut("我来到北京清华大学", cut_all=True)print("Full Mode: " + "/ ".join(seg_list)) 全模式seg_list = jieba.cut("我来到北京清华大学", cut_all=False)print("Default Mode: " + "/ ".join(seg_list)) 精确模式seg_list = jieba.cut("他来到了网易杭研大厦") 默认是精确模式print(", ".join(seg_list))seg_list = jieba.cut_for_search("小明硕士毕业于中国科学院计算所,后在日本京都大学深造") 搜索引擎模式print(", ".join(seg_list)) 输出: 【全模式】: 我/ 来到/ 北京/ 清华/ 清华大学/ 华大/ 大学【精确模式】: 我/ 来到/ 北京/ 清华大学【新词识别】:他, 来到, 了, 网易, 杭研, 大厦 (此处,“杭研”并没有在词典中,但是也被Viterbi算法识别出来了)【搜索引擎模式】: 小明, 硕士, 毕业, 于, 中国, 科学, 学院, 科学院, 中国科学院, 计算, 计算所, 后, 在, 日本, 京都, 大学, 日本京都大学, 深造 添加自定义词典 载入词典 开发者可以指定自己自定义的词典,以便包含 jieba 词库里没有的词。虽然 jieba 有新词识别能力,但是自行添加新词可以保证更高的正确率 用法: jieba.load_userdict(file_name) file_name 为文件类对象或自定义词典的路径 词典格式和 dict.txt 一样,一个词占一行;每一行分三部分:词语、词频(可省略)、词性(可省略),用空格隔开,顺序不可颠倒。file_name 若为路径或二进制方式打开的文件,则文件必须为 UTF-8 编码。 词频省略时使用自动计算的能保证分出该词的词频。 例如: 创新办 3 i云计算 5凱特琳 nz台中 更改分词器(默认为 jieba.dt)的 tmp_dir 和 cache_file 属性,可分别指定缓存文件所在的文件夹及其文件名,用于受限的文件系统。 范例: 自定义词典:https://github.com/fxsjy/jieba/blob/master/test/userdict.txt 用法示例:https://github.com/fxsjy/jieba/blob/master/test/test_userdict.py 之前: 李小福 / 是 / 创新 / 办 / 主任 / 也 / 是 / 云 / 计算 / 方面 / 的 / 专家 / 加载自定义词库后: 李小福 / 是 / 创新办 / 主任 / 也 / 是 / 云计算 / 方面 / 的 / 专家 / 调整词典 使用 add_word(word, freq=None, tag=None) 和 del_word(word) 可在程序中动态修改词典。 使用 suggest_freq(segment, tune=True) 可调节单个词语的词频,使其能(或不能)被分出来。 注意:自动计算的词频在使用 HMM 新词发现功能时可能无效。 代码示例: >>> print('/'.join(jieba.cut('如果放到post中将出错。', HMM=False)))如果/放到/post/中将/出错/。>>> jieba.suggest_freq(('中', '将'), True)494>>> print('/'.join(jieba.cut('如果放到post中将出错。', HMM=False)))如果/放到/post/中/将/出错/。>>> print('/'.join(jieba.cut('「台中」正确应该不会被切开', HMM=False)))「/台/中/」/正确/应该/不会/被/切开>>> jieba.suggest_freq('台中', True)69>>> print('/'.join(jieba.cut('「台中」正确应该不会被切开', HMM=False)))「/台中/」/正确/应该/不会/被/切开 “通过用户自定义词典来增强歧义纠错能力” — https://github.com/fxsjy/jieba/issues/14 关键词提取 基于 TF-IDF 算法的关键词抽取 import jieba.analyse jieba.analyse.extract_tags(sentence, topK=20, withWeight=False, allowPOS=()) sentence 为待提取的文本 topK 为返回几个 TF/IDF 权重最大的关键词,默认值为 20 withWeight 为是否一并返回关键词权重值,默认值为 False allowPOS 仅包括指定词性的词,默认值为空,即不筛选 jieba.analyse.TFIDF(idf_path=None) 新建 TFIDF 实例,idf_path 为 IDF 频率文件 代码示例 (关键词提取) https://github.com/fxsjy/jieba/blob/master/test/extract_tags.py 关键词提取所使用逆向文件频率(IDF)文本语料库可以切换成自定义语料库的路径 用法: jieba.analyse.set_idf_path(file_name) file_name为自定义语料库的路径 自定义语料库示例:https://github.com/fxsjy/jieba/blob/master/extra_dict/idf.txt.big 用法示例:https://github.com/fxsjy/jieba/blob/master/test/extract_tags_idfpath.py 关键词提取所使用停止词(Stop Words)文本语料库可以切换成自定义语料库的路径 用法: jieba.analyse.set_stop_words(file_name) file_name为自定义语料库的路径 自定义语料库示例:https://github.com/fxsjy/jieba/blob/master/extra_dict/stop_words.txt 用法示例:https://github.com/fxsjy/jieba/blob/master/test/extract_tags_stop_words.py 关键词一并返回关键词权重值示例 用法示例:https://github.com/fxsjy/jieba/blob/master/test/extract_tags_with_weight.py 基于 TextRank 算法的关键词抽取 jieba.analyse.textrank(sentence, topK=20, withWeight=False, allowPOS=(‘ns’, ‘n’, ‘vn’, ‘v’)) 直接使用,接口相同,注意默认过滤词性。 jieba.analyse.TextRank() 新建自定义 TextRank 实例 算法论文: TextRank: Bringing Order into Texts 基本思想: 将待抽取关键词的文本进行分词 以固定窗口大小(默认为5,通过span属性调整),词之间的共现关系,构建图 计算图中节点的PageRank,注意是无向带权图 使用示例: 见 test/demo.py 词性标注 jieba.posseg.POSTokenizer(tokenizer=None) 新建自定义分词器,tokenizer 参数可指定内部使用的 jieba.Tokenizer 分词器。jieba.posseg.dt 为默认词性标注分词器。 标注句子分词后每个词的词性,采用和 ictclas 兼容的标记法。 除了jieba默认分词模式,提供paddle模式下的词性标注功能。paddle模式采用延迟加载方式,通过enable_paddle()安装paddlepaddle-tiny,并且import相关代码; 用法示例 >>> import jieba>>> import jieba.posseg as pseg>>> words = pseg.cut("我爱北京天安门") jieba默认模式>>> jieba.enable_paddle() 启动paddle模式。 0.40版之后开始支持,早期版本不支持>>> words = pseg.cut("我爱北京天安门",use_paddle=True) paddle模式>>> for word, flag in words:... print('%s %s' % (word, flag))...我 r爱 v北京 ns天安门 ns paddle模式词性标注对应表如下: paddle模式词性和专名类别标签集合如下表,其中词性标签 24 个(小写字母),专名类别标签 4 个(大写字母)。 标签 含义 标签 含义 标签 含义 标签 含义 n 普通名词 f 方位名词 s 处所名词 t 时间 nr 人名 ns 地名 nt 机构名 nw 作品名 nz 其他专名 v 普通动词 vd 动副词 vn 名动词 a 形容词 ad 副形词 an 名形词 d 副词 m 数量词 q 量词 r 代词 p 介词 c 连词 u 助词 xc 其他虚词 w 标点符号 PER 人名 LOC 地名 ORG 机构名 TIME 时间 并行分词 原理:将目标文本按行分隔后,把各行文本分配到多个 Python 进程并行分词,然后归并结果,从而获得分词速度的可观提升 基于 python 自带的 multiprocessing 模块,目前暂不支持 Windows 用法: jieba.enable_parallel(4) 开启并行分词模式,参数为并行进程数 jieba.disable_parallel() 关闭并行分词模式 例子:https://github.com/fxsjy/jieba/blob/master/test/parallel/test_file.py 实验结果:在 4 核 3.4GHz Linux 机器上,对金庸全集进行精确分词,获得了 1MB/s 的速度,是单进程版的 3.3 倍。 注意:并行分词仅支持默认分词器 jieba.dt 和 jieba.posseg.dt。 Tokenize:返回词语在原文的起止位置 注意,输入参数只接受 unicode 默认模式 result = jieba.tokenize(u'永和服装饰品有限公司')for tk in result:print("word %s\t\t start: %d \t\t end:%d" % (tk[0],tk[1],tk[2])) word 永和 start: 0 end:2word 服装 start: 2 end:4word 饰品 start: 4 end:6word 有限公司 start: 6 end:10 搜索模式 result = jieba.tokenize(u'永和服装饰品有限公司', mode='search')for tk in result:print("word %s\t\t start: %d \t\t end:%d" % (tk[0],tk[1],tk[2])) word 永和 start: 0 end:2word 服装 start: 2 end:4word 饰品 start: 4 end:6word 有限 start: 6 end:8word 公司 start: 8 end:10word 有限公司 start: 6 end:10 ChineseAnalyzer for Whoosh 搜索引擎 引用: from jieba.analyse import ChineseAnalyzer 用法示例:https://github.com/fxsjy/jieba/blob/master/test/test_whoosh.py 命令行分词 使用示例:python -m jieba news.txt > cut_result.txt 命令行选项(翻译): 使用: python -m jieba [options] filename结巴命令行界面。固定参数:filename 输入文件可选参数:-h, --help 显示此帮助信息并退出-d [DELIM], --delimiter [DELIM]使用 DELIM 分隔词语,而不是用默认的' / '。若不指定 DELIM,则使用一个空格分隔。-p [DELIM], --pos [DELIM]启用词性标注;如果指定 DELIM,词语和词性之间用它分隔,否则用 _ 分隔-D DICT, --dict DICT 使用 DICT 代替默认词典-u USER_DICT, --user-dict USER_DICT使用 USER_DICT 作为附加词典,与默认词典或自定义词典配合使用-a, --cut-all 全模式分词(不支持词性标注)-n, --no-hmm 不使用隐含马尔可夫模型-q, --quiet 不输出载入信息到 STDERR-V, --version 显示版本信息并退出如果没有指定文件名,则使用标准输入。 --help 选项输出: $> python -m jieba --helpJieba command line interface.positional arguments:filename input fileoptional arguments:-h, --help show this help message and exit-d [DELIM], --delimiter [DELIM]use DELIM instead of ' / ' for word delimiter; or aspace if it is used without DELIM-p [DELIM], --pos [DELIM]enable POS tagging; if DELIM is specified, use DELIMinstead of '_' for POS delimiter-D DICT, --dict DICT use DICT as dictionary-u USER_DICT, --user-dict USER_DICTuse USER_DICT together with the default dictionary orDICT (if specified)-a, --cut-all full pattern cutting (ignored with POS tagging)-n, --no-hmm don't use the Hidden Markov Model-q, --quiet don't print loading messages to stderr-V, --version show program's version number and exitIf no filename specified, use STDIN instead. 延迟加载机制 jieba 采用延迟加载,import jieba 和 jieba.Tokenizer() 不会立即触发词典的加载,一旦有必要才开始加载词典构建前缀字典。如果你想手工初始 jieba,也可以手动初始化。 import jiebajieba.initialize() 手动初始化(可选) 在 0.28 之前的版本是不能指定主词典的路径的,有了延迟加载机制后,你可以改变主词典的路径: jieba.set_dictionary('data/dict.txt.big') 例子: https://github.com/fxsjy/jieba/blob/master/test/test_change_dictpath.py 其他词典 占用内存较小的词典文件 https://github.com/fxsjy/jieba/raw/master/extra_dict/dict.txt.small 支持繁体分词更好的词典文件 https://github.com/fxsjy/jieba/raw/master/extra_dict/dict.txt.big 下载你所需要的词典,然后覆盖 jieba/dict.txt 即可;或者用 jieba.set_dictionary('data/dict.txt.big') 其他语言实现 结巴分词 Java 版本 作者:piaolingxue 地址:https://github.com/huaban/jieba-analysis 结巴分词 C++ 版本 作者:yanyiwu 地址:https://github.com/yanyiwu/cppjieba 结巴分词 Rust 版本 作者:messense, MnO2 地址:https://github.com/messense/jieba-rs 结巴分词 Node.js 版本 作者:yanyiwu 地址:https://github.com/yanyiwu/nodejieba 结巴分词 Erlang 版本 作者:falood 地址:https://github.com/falood/exjieba 结巴分词 R 版本 作者:qinwf 地址:https://github.com/qinwf/jiebaR 结巴分词 iOS 版本 作者:yanyiwu 地址:https://github.com/yanyiwu/iosjieba 结巴分词 PHP 版本 作者:fukuball 地址:https://github.com/fukuball/jieba-php 结巴分词 .NET(C) 版本 作者:anderscui 地址:https://github.com/anderscui/jieba.NET/ 结巴分词 Go 版本 作者: wangbin 地址: https://github.com/wangbin/jiebago 作者: yanyiwu 地址: https://github.com/yanyiwu/gojieba 结巴分词Android版本 作者 Dongliang.W 地址:https://github.com/452896915/jieba-android 友情链接 https://github.com/baidu/lac 百度中文词法分析(分词+词性+专名)系统 https://github.com/baidu/AnyQ 百度FAQ自动问答系统 https://github.com/baidu/Senta 百度情感识别系统 系统集成 Solr: https://github.com/sing1ee/jieba-solr 分词速度 1.5 MB / Second in Full Mode 400 KB / Second in Default Mode 测试环境: Intel® Core™ i7-2600 CPU @ 3.4GHz;《围城》.txt 常见问题 1. 模型的数据是如何生成的? 详见: https://github.com/fxsjy/jieba/issues/7 2. “台中”总是被切成“台 中”?(以及类似情况) P(台中) < P(台)×P(中),“台中”词频不够导致其成词概率较低 解决方法:强制调高词频 jieba.add_word('台中') 或者 jieba.suggest_freq('台中', True) 3. “今天天气 不错”应该被切成“今天 天气 不错”?(以及类似情况) 解决方法:强制调低词频 jieba.suggest_freq(('今天', '天气'), True) 或者直接删除该词 jieba.del_word('今天天气') 4. 切出了词典中没有的词语,效果不理想? 解决方法:关闭新词发现 jieba.cut('丰田太省了', HMM=False) jieba.cut('我们中出了一个叛徒', HMM=False) 更多问题请点击:https://github.com/fxsjy/jieba/issues?sort=updated&state=closed 修订历史 https://github.com/fxsjy/jieba/blob/master/Changelog jieba “Jieba” (Chinese for “to stutter”) Chinese text segmentation: built to be the best Python Chinese word segmentation module. Features Support three types of segmentation mode: Accurate Mode attempts to cut the sentence into the most accurate segmentations, which is suitable for text analysis. Full Mode gets all the possible words from the sentence. Fast but not accurate. Search Engine Mode, based on the Accurate Mode, attempts to cut long words into several short words, which can raise the recall rate. Suitable for search engines. Supports Traditional Chinese Supports customized dictionaries MIT License Online demo http://jiebademo.ap01.aws.af.cm/ (Powered by Appfog) Usage Fully automatic installation: easy_install jieba or pip install jieba Semi-automatic installation: Download http://pypi.python.org/pypi/jieba/ , run python setup.py install after extracting. Manual installation: place the jieba directory in the current directory or python site-packages directory. import jieba. Algorithm Based on a prefix dictionary structure to achieve efficient word graph scanning. Build a directed acyclic graph (DAG) for all possible word combinations. Use dynamic programming to find the most probable combination based on the word frequency. For unknown words, a HMM-based model is used with the Viterbi algorithm. Main Functions Cut The jieba.cut function accepts three input parameters: the first parameter is the string to be cut; the second parameter is cut_all, controlling the cut mode; the third parameter is to control whether to use the Hidden Markov Model. jieba.cut_for_search accepts two parameter: the string to be cut; whether to use the Hidden Markov Model. This will cut the sentence into short words suitable for search engines. The input string can be an unicode/str object, or a str/bytes object which is encoded in UTF-8 or GBK. Note that using GBK encoding is not recommended because it may be unexpectly decoded as UTF-8. jieba.cut and jieba.cut_for_search returns an generator, from which you can use a for loop to get the segmentation result (in unicode). jieba.lcut and jieba.lcut_for_search returns a list. jieba.Tokenizer(dictionary=DEFAULT_DICT) creates a new customized Tokenizer, which enables you to use different dictionaries at the same time. jieba.dt is the default Tokenizer, to which almost all global functions are mapped. Code example: segmentation encoding=utf-8import jiebaseg_list = jieba.cut("我来到北京清华大学", cut_all=True)print("Full Mode: " + "/ ".join(seg_list)) 全模式seg_list = jieba.cut("我来到北京清华大学", cut_all=False)print("Default Mode: " + "/ ".join(seg_list)) 默认模式seg_list = jieba.cut("他来到了网易杭研大厦")print(", ".join(seg_list))seg_list = jieba.cut_for_search("小明硕士毕业于中国科学院计算所,后在日本京都大学深造") 搜索引擎模式print(", ".join(seg_list)) Output: [Full Mode]: 我/ 来到/ 北京/ 清华/ 清华大学/ 华大/ 大学[Accurate Mode]: 我/ 来到/ 北京/ 清华大学[Unknown Words Recognize] 他, 来到, 了, 网易, 杭研, 大厦 (In this case, "杭研" is not in the dictionary, but is identified by the Viterbi algorithm)[Search Engine Mode]: 小明, 硕士, 毕业, 于, 中国, 科学, 学院, 科学院, 中国科学院, 计算, 计算所, 后, 在, 日本, 京都, 大学, 日本京都大学, 深造 Add a custom dictionary Load dictionary Developers can specify their own custom dictionary to be included in the jieba default dictionary. Jieba is able to identify new words, but you can add your own new words can ensure a higher accuracy. Usage: jieba.load_userdict(file_name) file_name is a file-like object or the path of the custom dictionary The dictionary format is the same as that of dict.txt: one word per line; each line is divided into three parts separated by a space: word, word frequency, POS tag. If file_name is a path or a file opened in binary mode, the dictionary must be UTF-8 encoded. The word frequency and POS tag can be omitted respectively. The word frequency will be filled with a suitable value if omitted. For example: 创新办 3 i云计算 5凱特琳 nz台中 Change a Tokenizer’s tmp_dir and cache_file to specify the path of the cache file, for using on a restricted file system. Example: 云计算 5李小福 2创新办 3[Before]: 李小福 / 是 / 创新 / 办 / 主任 / 也 / 是 / 云 / 计算 / 方面 / 的 / 专家 /[After]: 李小福 / 是 / 创新办 / 主任 / 也 / 是 / 云计算 / 方面 / 的 / 专家 / Modify dictionary Use add_word(word, freq=None, tag=None) and del_word(word) to modify the dictionary dynamically in programs. Use suggest_freq(segment, tune=True) to adjust the frequency of a single word so that it can (or cannot) be segmented. Note that HMM may affect the final result. Example: >>> print('/'.join(jieba.cut('如果放到post中将出错。', HMM=False)))如果/放到/post/中将/出错/。>>> jieba.suggest_freq(('中', '将'), True)494>>> print('/'.join(jieba.cut('如果放到post中将出错。', HMM=False)))如果/放到/post/中/将/出错/。>>> print('/'.join(jieba.cut('「台中」正确应该不会被切开', HMM=False)))「/台/中/」/正确/应该/不会/被/切开>>> jieba.suggest_freq('台中', True)69>>> print('/'.join(jieba.cut('「台中」正确应该不会被切开', HMM=False)))「/台中/」/正确/应该/不会/被/切开 Keyword Extraction import jieba.analyse jieba.analyse.extract_tags(sentence, topK=20, withWeight=False, allowPOS=()) sentence: the text to be extracted topK: return how many keywords with the highest TF/IDF weights. The default value is 20 withWeight: whether return TF/IDF weights with the keywords. The default value is False allowPOS: filter words with which POSs are included. Empty for no filtering. jieba.analyse.TFIDF(idf_path=None) creates a new TFIDF instance, idf_path specifies IDF file path. Example (keyword extraction) https://github.com/fxsjy/jieba/blob/master/test/extract_tags.py Developers can specify their own custom IDF corpus in jieba keyword extraction Usage: jieba.analyse.set_idf_path(file_name) file_name is the path for the custom corpus Custom Corpus Sample:https://github.com/fxsjy/jieba/blob/master/extra_dict/idf.txt.big Sample Code:https://github.com/fxsjy/jieba/blob/master/test/extract_tags_idfpath.py Developers can specify their own custom stop words corpus in jieba keyword extraction Usage: jieba.analyse.set_stop_words(file_name) file_name is the path for the custom corpus Custom Corpus Sample:https://github.com/fxsjy/jieba/blob/master/extra_dict/stop_words.txt Sample Code:https://github.com/fxsjy/jieba/blob/master/test/extract_tags_stop_words.py There’s also a TextRank implementation available. Use: jieba.analyse.textrank(sentence, topK=20, withWeight=False, allowPOS=('ns', 'n', 'vn', 'v')) Note that it filters POS by default. jieba.analyse.TextRank() creates a new TextRank instance. Part of Speech Tagging jieba.posseg.POSTokenizer(tokenizer=None) creates a new customized Tokenizer. tokenizer specifies the jieba.Tokenizer to internally use. jieba.posseg.dt is the default POSTokenizer. Tags the POS of each word after segmentation, using labels compatible with ictclas. Example: >>> import jieba.posseg as pseg>>> words = pseg.cut("我爱北京天安门")>>> for w in words:... print('%s %s' % (w.word, w.flag))...我 r爱 v北京 ns天安门 ns Parallel Processing Principle: Split target text by line, assign the lines into multiple Python processes, and then merge the results, which is considerably faster. Based on the multiprocessing module of Python. Usage: jieba.enable_parallel(4) Enable parallel processing. The parameter is the number of processes. jieba.disable_parallel() Disable parallel processing. Example: https://github.com/fxsjy/jieba/blob/master/test/parallel/test_file.py Result: On a four-core 3.4GHz Linux machine, do accurate word segmentation on Complete Works of Jin Yong, and the speed reaches 1MB/s, which is 3.3 times faster than the single-process version. Note that parallel processing supports only default tokenizers, jieba.dt and jieba.posseg.dt. Tokenize: return words with position The input must be unicode Default mode result = jieba.tokenize(u'永和服装饰品有限公司')for tk in result:print("word %s\t\t start: %d \t\t end:%d" % (tk[0],tk[1],tk[2])) word 永和 start: 0 end:2word 服装 start: 2 end:4word 饰品 start: 4 end:6word 有限公司 start: 6 end:10 Search mode result = jieba.tokenize(u'永和服装饰品有限公司',mode='search')for tk in result:print("word %s\t\t start: %d \t\t end:%d" % (tk[0],tk[1],tk[2])) word 永和 start: 0 end:2word 服装 start: 2 end:4word 饰品 start: 4 end:6word 有限 start: 6 end:8word 公司 start: 8 end:10word 有限公司 start: 6 end:10 ChineseAnalyzer for Whoosh from jieba.analyse import ChineseAnalyzer Example: https://github.com/fxsjy/jieba/blob/master/test/test_whoosh.py Command Line Interface $> python -m jieba --helpJieba command line interface.positional arguments:filename input fileoptional arguments:-h, --help show this help message and exit-d [DELIM], --delimiter [DELIM]use DELIM instead of ' / ' for word delimiter; or aspace if it is used without DELIM-p [DELIM], --pos [DELIM]enable POS tagging; if DELIM is specified, use DELIMinstead of '_' for POS delimiter-D DICT, --dict DICT use DICT as dictionary-u USER_DICT, --user-dict USER_DICTuse USER_DICT together with the default dictionary orDICT (if specified)-a, --cut-all full pattern cutting (ignored with POS tagging)-n, --no-hmm don't use the Hidden Markov Model-q, --quiet don't print loading messages to stderr-V, --version show program's version number and exitIf no filename specified, use STDIN instead. Initialization By default, Jieba don’t build the prefix dictionary unless it’s necessary. This takes 1-3 seconds, after which it is not initialized again. If you want to initialize Jieba manually, you can call: import jiebajieba.initialize() (optional) You can also specify the dictionary (not supported before version 0.28) : jieba.set_dictionary('data/dict.txt.big') Using Other Dictionaries It is possible to use your own dictionary with Jieba, and there are also two dictionaries ready for download: A smaller dictionary for a smaller memory footprint: https://github.com/fxsjy/jieba/raw/master/extra_dict/dict.txt.small There is also a bigger dictionary that has better support for traditional Chinese (繁體): https://github.com/fxsjy/jieba/raw/master/extra_dict/dict.txt.big By default, an in-between dictionary is used, called dict.txt and included in the distribution. In either case, download the file you want, and then call jieba.set_dictionary('data/dict.txt.big') or just replace the existing dict.txt. Segmentation speed 1.5 MB / Second in Full Mode 400 KB / Second in Default Mode Test Env: Intel® Core™ i7-2600 CPU @ 3.4GHz;《围城》.txt 本篇文章为转载内容。原文链接:https://blog.csdn.net/yegeli/article/details/107246661。 该文由互联网用户投稿提供,文中观点代表作者本人意见,并不代表本站的立场。 作为信息平台,本站仅提供文章转载服务,并不拥有其所有权,也不对文章内容的真实性、准确性和合法性承担责任。 如发现本文存在侵权、违法、违规或事实不符的情况,请及时联系我们,我们将第一时间进行核实并删除相应内容。
2023-12-02 10:38:37
500
转载
站内搜索
用于搜索本网站内部文章,支持栏目切换。
知识学习
实践的时候请根据实际情况谨慎操作。
随机学习一条linux命令:
traceroute host
- 显示数据包到目标主机经过的路由路径。
推荐内容
推荐本栏目内的其它文章,看看还有哪些文章让你感兴趣。
2023-04-28
2023-08-09
2023-06-18
2023-04-14
2023-02-18
2023-04-17
2024-01-11
2023-10-03
2023-09-09
2023-06-13
2023-08-07
2023-03-11
历史内容
快速导航到对应月份的历史文章列表。
随便看看
拉到页底了吧,随便看看还有哪些文章你可能感兴趣。
时光飞逝
"流光容易把人抛,红了樱桃,绿了芭蕉。"