简繁体汉字转拼音的项目,解决多音字的问题。ElasticSearch、solr 的拼音分词工具

Overview

pinyin-plus

汉字转拼音的库,有如下特点

  • 拼音数据基于 cc-cedictkaifangcidian 开源词库
  • 基于拼音词库的数据初始化分词引擎进行分词,准确度高,解决多音字的问题
  • 支持繁体字
  • 支持自定义词库,词库格式同 cc-cedict 字典格式
  • api 简单,分为普通模式、索引模式

使用场景

汉字转拼音,常用于索引引擎场景创建拼音的索引,这个场景的问题一般由两种实现路径,一种是直接使用带拼音的的分词 插件,会自动帮你创建出拼音的索引,还有一种就是自己将汉字转换为拼音字符串,采用空格分隔分词来达到定制化索引的目的。 不论哪种实现路径,都离不开分词和拼音转换。pinyin-plus 的特点是,索引分词的词库和拼音的词库是基于同一套词库, 所以多音词的准确度特别高,而且词库的格式保留了开源词典的格式,词库可以轻松的定时更新。同时也预留了自定义词库的扩展 接口,保留定制化需求的高优先级

性能

#pinyin-plus 的压测数据,测试词语:率土之滨
kl@kldeMacBook-Pro-6 arthas % wrk -t16 -c100 -d15s --latency http://localhost:8080/%E7%8E%87%E5%9C%9F%E4%B9%8B%E6%BB%A8
Running 15s test @ http://localhost:8080/%E7%8E%87%E5%9C%9F%E4%B9%8B%E6%BB%A8
  16 threads and 100 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   733.97us  138.45us  16.40ms   96.12%
    Req/Sec     8.19k   293.50     8.90k    87.83%
  Latency Distribution
     50%  718.00us
     75%  739.00us
     90%  785.00us
     99%    1.02ms
  1970023 requests in 15.10s, 266.78MB read
Requests/sec: 130469.56
Transfer/sec:     17.67MB

添加依赖

gradle

compile "com.github.taptap:pinyin-plus:1.0"

maven

        <dependency>
            <groupId>com.github.taptapgroupId>
            <artifactId>pinyin-plusartifactId>
            <version>1.0version>
        dependency>

使用

    //普通模式示例,汉字转换拼音后,单子采用空格隔开输出
    @Test
    void testToPinYin() {
        String pinyin = PinyinPlus.to("率土之滨");
        System.err.println(pinyin);
        Assertions.assertEquals("shuai tu zhi bin", pinyin);
    }
    //索引模式示例,汉字转换拼音后,词组采用空格隔开输出
    @Test
    void testToPinYin2() {
            String pinyin = PinyinPlus.toIndex("写的射雕英雄传");
            System.err.println(pinyin);
            Assertions.assertEquals("xie de shediaoyingxiongzhuan", pinyin);
    }
    

自定义词库

在项目 resources 目录下,新增 custom_cedict_ts.u8 文本文件,输入如下格式数据,# 开头的为注释,如:

#自定义词库
血花 血花 [xue4 hua1] //

格式保留和开源词库 cc-cedict 一样的风格,遇到相同的词组,自定义的优先级最高,会覆盖系统默认的词组

鸣谢

You might also like...

mall4cloud微服务商城,基于Spring Cloud、Nacos、Seata、Mysql、Redis、RocketMQ、canal、ElasticSearch、minio的B2B2C微服务商城系统,采用主流的互联网技术架构、全新的UI设计 B2B2C微服务商城|小程序微服务商城|

mall4cloud微服务商城,基于Spring Cloud、Nacos、Seata、Mysql、Redis、RocketMQ、canal、ElasticSearch、minio的B2B2C微服务商城系统,采用主流的互联网技术架构、全新的UI设计 B2B2C微服务商城|小程序微服务商城|

README 前言 本商城是基于Spring Cloud、Nacos、Seata、Mysql、Redis、RocketMQ、canal、ElasticSearch、minio的微服务B2B2C电商商城系统,采用主流的互联网技术架构、全新的UI设计、支持集群部署、服务注册和发现以及拥有完整的订单流程等

Jan 1, 2023

An example on how to build a configurable widget to trigger external searches along with Liferay search to Elasticsearch.

An example on how to build a configurable widget to trigger external searches along with Liferay search to Elasticsearch.

Liferay External Searches An example on how to build a configurable widget to trigger external searches along with Liferay search to Elasticsearch. Ge

Oct 25, 2021

The IK Analysis plugin integrates Lucene IK analyzer into elasticsearch, support customized dictionary.

IK Analysis for Elasticsearch The IK Analysis plugin integrates Lucene IK analyzer (http://code.google.com/p/ik-analyzer/) into elasticsearch, support

Jan 5, 2023

This application will help you to generate Elasticsearch template based on your data

Welcome to templates generator application for Elasticsearch This application will help you to generate the template and/or test index, based on your

Jan 2, 2023

Reindex - application for visualize, optimize and automate your Elasticsearch reindex process

Welcome to reindex application for Elasticsearch This application will help you to reindex one or more existing indices, into the local or remote Elas

Jan 2, 2023
Owner
TapTap
易玩(上海)网络科技有限公司
TapTap
Apache Solr is an enterprise search platform written in Java and using Apache Lucene.

Apache Solr is an enterprise search platform written in Java and using Apache Lucene. Major features include full-text search, index replication and sharding, and result faceting and highlighting.

The Apache Software Foundation 630 Dec 28, 2022
The Chronix Server implementation that is based on Apache Solr.

Chronix Server The Chronix Server is an implementation of the Chronix API that stores time series in Apache Solr. Chronix uses several techniques to o

Chronix 262 Jul 3, 2022
Elasticsearch Java Rest Client.

JEST Jest is a Java HTTP Rest client for ElasticSearch. ElasticSearch is an Open Source (Apache 2), Distributed, RESTful, Search Engine built on top o

Searchly 2.1k Jan 1, 2023
:elephant: Elasticsearch real-time search and analytics natively integrated with Hadoop

Elasticsearch Hadoop Elasticsearch real-time search and analytics natively integrated with Hadoop. Supports Map/Reduce, Apache Hive, Apache Pig, Apach

elastic 1.9k Dec 22, 2022
mall学习教程,架构、业务、技术要点全方位解析。mall项目(40k+star)是一套电商系统,使用现阶段主流技术实现。涵盖了SpringBoot 2.3.0、MyBatis 3.4.6、Elasticsearch 7.6.2、RabbitMQ 3.7.15、Redis 5.0、MongoDB 4.2.5、Mysql5.7等技术,采用Docker容器化部署。

mall学习教程 简介 mall学习教程,架构、业务、技术要点全方位解析。mall项目(40k+star)是一套电商系统,使用现阶段主流技术实现。涵盖了SpringBoot 2.3.0、MyBatis 3.4.6、Elasticsearch 7.6.2、RabbitMQ 3.7.15、Redis 5

macro 11.7k Jan 8, 2023
mall-swarm是一套微服务商城系统,采用了 Spring Cloud Hoxton & Alibaba、Spring Boot 2.3、Oauth2、MyBatis、Docker、Elasticsearch、Kubernetes等核心技术,同时提供了基于Vue的管理后台方便快速搭建系统。mall-swarm在电商业务的基础集成了注册中心、配置中心、监控中心、网关等系统功能。文档齐全,附带全套Spring Cloud教程。

mall-swarm 友情提示 快速体验项目:在线访问地址。 全套学习教程:《mall学习教程》。 Spring Cloud全套教程:《SpringCloud学习教程》。 专属学习路线:学习不走弯路,整理了套非常不错的《mall专属学习路线》。 项目交流:想要加群交流项目的朋友,可以加入mall项目

macro 9.7k Jan 3, 2023
【咕泡学院实战项目】-基于SpringBoot+Dubbo构建的电商平台-微服务架构、商城、电商、微服务、高并发、kafka、Elasticsearch

咕泡商城- 微服务架构实战 咕泡商城是咕泡学院 Java架构课程中,帮助学员对于技术更好落地的一个实战项目,项目基于springboot2.1.6.RELEASE+Dubbo2.7.3 来构建微服务。 业务模块划分,尽量贴合互联网公司的架构体系。所以,除了业务本身的复杂度不是很高之外,整体的架构基本

Mic 4.5k Dec 26, 2022
ElasticSearch SQL查询适配器,为Elasticsearch提供SQL查询的功能。支持跨集群查询,可拓展异构数据源。将calcite基于配置文件的配置方式改为通过代码灵活控制,可动态增加数据源,并支持完整的SQL查询功能。

?? 使用指南 ElasticSearchSQL查询适配器,为Elasticsearch提供SQL查询的功能。支持完整的SQL查询和跨Elasticsearch集群查询。通过代码简单配置,使项目根据Elasticsearch的index映射为Table。 License CodeBeat Langu

弘树丶 23 Jul 18, 2022
🦄 开源社区系统:基于 SpringBoot + MyBatis + MySQL + Redis + Kafka + Elasticsearch + Spring Security + ... 并提供详细的开发文档和配套教程。包含帖子、评论、私信、系统通知、点赞、关注、搜索、用户设置、数据统计等模块。

Echo — 开源社区系统 项目上线到服务器之后可能会出现各种各样的 BUG,比如 Elasticsearch 服务启动失败导致搜索模块不可用,但是在本地运行是完全没问题的,所以各位小伙伴可以放心下载部署。 ?? 项目简介 Echo 是一套前后端不分离的开源社区系统,基于目前主流 Java Web

小牛肉 434 Jan 7, 2023
Official Elasticsearch Java Client

Elasticsearch Java Client The official Java client for Elasticsearch. Note: this project is still a work in progress. This client is meant to replace

elastic 230 Jan 8, 2023