Convert Figma logo to code with AI

belerweb logopinyin4j

A copy of http://sourceforge.net/projects/pinyin4j, then deploy it to maven central repository.

1,231
305
1,231
39

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

  1. Basic Pinyin conversion:
PinyinHelper.toHanyuPinyinStringArray('中');
// Output: ["zhong1"]
  1. 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è"
  1. Getting multiple Pinyin representations:
String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray('重');
// Output: ["zhong4", "chong2"]

Getting Started

  1. 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'
    
  2. 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 Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

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)