pinyin4j
A copy of http://sourceforge.net/projects/pinyin4j, then deploy it to maven central repository.
Top Related Projects
汉字转拼音(pypinyin)
Quick Overview
Pinyin4j is a Java library that converts Chinese characters to their corresponding Pinyin (phonetic) representation. It supports multiple Pinyin systems and provides various output formats, making it a versatile tool for Chinese language processing in Java applications.
Pros
- Supports multiple Pinyin systems (Hanyu Pinyin, Tongyong Pinyin, Wade-Giles, etc.)
- Offers various output formats (with or without tone marks, with tone numbers, etc.)
- Handles both Simplified and Traditional Chinese characters
- Lightweight and easy to integrate into Java projects
Cons
- Limited to Java applications, not available for other programming languages
- May not handle some rare or complex Chinese characters accurately
- Lacks built-in support for sentence-level tone sandhi rules
- Documentation could be more comprehensive and up-to-date
Code Examples
- Basic Pinyin conversion:
PinyinHelper.toHanyuPinyinStringArray('中');
// Output: ["zhong1"]
- Converting a string to Pinyin with tone marks:
HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
format.setToneType(HanyuPinyinToneType.WITH_TONE_MARK);
format.setVCharType(HanyuPinyinVCharType.WITH_V);
String pinyin = PinyinHelper.toHanyuPinyinString("你好世界", format, " ");
// Output: "nǐ hǎo shì jiè"
- Getting multiple Pinyin representations:
String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray('重');
// Output: ["zhong4", "chong2"]
Getting Started
-
Add the Pinyin4j dependency to your project:
For Maven:
<dependency> <groupId>com.belerweb</groupId> <artifactId>pinyin4j</artifactId> <version>2.5.1</version> </dependency>
For Gradle:
implementation 'com.belerweb:pinyin4j:2.5.1'
-
Use the library in your Java code:
import net.sourceforge.pinyin4j.PinyinHelper; import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat; import net.sourceforge.pinyin4j.format.HanyuPinyinToneType; public class PinyinExample { public static void main(String[] args) { String chinese = "你好"; HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat(); format.setToneType(HanyuPinyinToneType.WITH_TONE_NUMBER); String pinyin = PinyinHelper.toHanyuPinyinString(chinese, format, " "); System.out.println(pinyin); // Output: ni3 hao3 } }
Competitor Comparisons
汉字转拼音(pypinyin)
Pros of python-pinyin
- Written in Python, making it more accessible for Python developers
- Supports multiple output formats (e.g., numerical tone marks, diacritical marks)
- Actively maintained with regular updates and improvements
Cons of python-pinyin
- Limited to Python environments, unlike pinyin4j which is Java-based
- May have slower performance compared to pinyin4j's compiled Java code
- Lacks some advanced features present in pinyin4j, such as custom dictionaries
Code Comparison
python-pinyin:
from pypinyin import pinyin, Style
print(pinyin('中心', style=Style.TONE))
# Output: [['zhōng'], ['xīn']]
pinyin4j:
import net.sourceforge.pinyin4j.PinyinHelper;
String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray('中');
System.out.println(pinyinArray[0]); // Output: zhong1
Both libraries provide similar functionality for converting Chinese characters to pinyin, but with different syntax and output formats. python-pinyin offers more flexibility in output styles, while pinyin4j provides a more straightforward API for Java developers.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
pinyin4j
A copy of http://sourceforge.net/projects/pinyin4j, then deploy it to maven central repository.
Download
Download the jar via maven:
<dependency>
<groupId>com.belerweb</groupId>
<artifactId>pinyin4j</artifactId>
<version>2.5.0</version>
</dependency>
QQ Group
QQ群ï¼479540440
å¤é³åè¯å«
å¨pinyin4jçåºç¡ä¸æ·»å äºå¤é³åè¯å«ï¼å¸¦è¿ä¸ä¸ä¸ªå¤é³è¯ï¼ä½æ¯è¿è¿è¿ä¸å¤ï¼æ以ç¨æ·å¯è®¾ç½®å¤æè¯åº
å¤æå¤é³è¯åº
ç¨æ·é ç½®çå¤æè¯åºä¼è¦çç³»ç»ä¸ç¸åè¯ç读é³,å¯ç¨äºçº é
é ç½®æ¹å¼å¾ç®å,åªéè¦é 置路å¾å³å¯
MultiPinyinConfig.multiPinyinPath="/Users/yiboliu/my_multi_pinyin.txt"
æ ¼å¼åç³»ç»çå¤é³è¯åº,å¦:
å¸è¡é¬¼æ¥è®° (xi1,xue4,gui3,ri4,ji4)
Top Related Projects
汉字转拼音(pypinyin)
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot