Java:TinyPinyin实现汉字转拼音

news/2025/2/21 12:19:20/

TinyPinyin是一个适用于Java和Android的快速、低内存占用的汉字转拼音库。

文档

  • https://github.com/promeG/TinyPinyin
  • https://mvnrepository.com/artifact/com.github.promeg/tinypinyin

引入依赖

<!-- TinyPinyin核心包 -->
<dependency><groupId>com.github.promeg</groupId><artifactId>tinypinyin</artifactId><version>2.0.3</version>
</dependency><!-- 可选,适用于Java的中国地区词典 -->
<dependency><groupId>com.github.promeg</groupId><artifactId>tinypinyin-lexicons-java-cncity</artifactId><version>2.0.3</version>
</dependency>

方法签名

/*** 如果c为汉字,则返回大写拼音;如果c不是汉字,则返回String.valueOf(c)*/
String Pinyin.toPinyin(char c)/*** c为汉字,则返回true,否则返回false*/
boolean Pinyin.isChinese(char c)/*** 将输入字符串转为拼音,转换过程中会使用之前设置的用户词典,以字符为单位插入分隔符*/
String toPinyin(String str, String separator)

代码示例

package com.example.demo;import com.github.promeg.pinyinhelper.Pinyin;
import org.junit.Test;public class PinyinTests {@Testpublic void testPinyin(){// 返回大写拼音String pinyin = Pinyin.toPinyin("你好中国", "");System.out.println(pinyin);// NIHAOZHONGGUO}
}

http://www.ppmy.cn/news/1140729.html

相关文章

【虚拟机栈】

文章目录 1. 虚拟机栈概述2. 局部变量表(Local Variables)3. 操作数栈4. 动态链接4.1 方法的调用&#xff1a;解析与分配 5. 方法返回地址6. 栈的相关面试题 1. 虚拟机栈概述 每个线程在创建时都会创建一个虚拟机栈&#xff0c;其内部保存一个个的栈帧&#xff08;Stack Frame…

Java中几种不同的引用

文章目录 Java中几种不同的引用StrongReference(强引用)SoftReference(软引用)WeakReferenc(弱引用)虚引用PhantomReference Java中几种不同的引用 我们希望能描述这样一类对象&#xff1a;当内存空间还足够时&#xff0c;则能保留在内存中&#xff1b;如果内存空间在进行垃圾…

ValueError: high is out of bounds for int32 报错

问题描述&#xff1a; 笔者在Windows 64位平台跑一个在Ubuntu上运行正常的程序时&#xff0c;出现了以下报错&#xff1a; 具体为&#xff1a; seed np.random.randint(0, 2 ** 32) # make a seed with numpy generatorFile "mtrand.pyx", line 763, in numpy.ra…

磁通量概述

磁通量指的是设在磁感应强度为B的匀强磁场中&#xff0c;有一个面积为S且与磁场方向垂直的平面&#xff0c;磁感应强度B与面积S的乘积&#xff0c;叫做穿过这个平面的磁通量&#xff0c;简称磁通&#xff08;Magnetic Flux&#xff09;。标量&#xff0c;符号“Φ”。在一般情况…

java开源商城免费搭建 VR全景商城 saas商城 b2b2c商城 o2o商城 积分商城 秒杀商城 拼团商城 分销商城 短视频商城

1. 涉及平台 平台管理、商家端&#xff08;PC端、手机端&#xff09;、买家平台&#xff08;H5/公众号、小程序、APP端&#xff08;IOS/Android&#xff09;、微服务平台&#xff08;业务服务&#xff09; 2. 核心架构 Spring Cloud、Spring Boot、Mybatis、Redis 3. 前端框架…

linux内核分析:docker与隔离

Docker,K8s,KVM,Hypervisor和微服务有什么区别联系吗? - 知乎 docker容器 容器实现封闭的环境主要要靠两种技术,一种是看起来是隔离的技术,称为 namespace(命名空间)。在每个 namespace 中的应用看到的,都是不同的 IP 地址、用户空间、进程 ID 等。另一种是用起来是…

springboot整合pi支付开发

pi支付流程图&#xff1a; 使用Pi SDK功能发起支付由 Pi SDK 自动调用的回调函数&#xff08;让您的应用服务器知道它需要发出批准 API 请求&#xff09;从您的应用程序服务器到 Pi 服务器的 API 请求以批准付款&#xff08;让 Pi 服务器知道您知道此付款&#xff09;Pi浏览器向…

http发送和接收图片json文件

一、http数据发送 1、先将图片转换为base64格式 std::string detectNet::Mat2Base64(const cv::Mat &image, std::string imgType){std::vector<uchar> buf;cv::imencode(imgType, image, buf);//uchar *enc_msg reinterpret_cast<unsigned char*>(buf.data…