Module bus.extra

Class Pinyin4JProvider

java.lang.Object
org.miaixz.bus.extra.pinyin.provider.pinyin4j.Pinyin4JProvider
All Implemented Interfaces:
Serializable, org.miaixz.bus.core.Provider, PinyinProvider

public class Pinyin4JProvider extends Object implements PinyinProvider
Encapsulates the Pinyin4j engine.

Pinyin4j (http://sourceforge.net/projects/pinyin4j) encapsulation.

To introduce (dependency):

 <dependency>
     <groupId>com.belerweb</groupId>
     <artifactId>pinyin4j</artifactId>
     <version>2.5.1</version>
 </dependency>
 
Since:
Java 17+
Author:
Kimi Liu
See Also:
  • Constructor Details

    • Pinyin4JProvider

      public Pinyin4JProvider()
      Constructs a new Pinyin4JProvider instance. Checks if the Pinyin4j library is available (via PinyinHelper class).
  • Method Details

    • getPinyin

      public String getPinyin(char c, boolean tone)
      Description copied from interface: PinyinProvider
      Converts a single character to its Pinyin, with an option to retain tone marks. If the character is a Chinese character, its Pinyin is returned; otherwise, the character itself is returned as a string.
      Specified by:
      getPinyin in interface PinyinProvider
      Parameters:
      c - The character to convert.
      tone - true to retain tone marks in the Pinyin, false otherwise.
      Returns:
      The Pinyin of the Chinese character, or the character itself if not Chinese.
    • getPinyin

      public String getPinyin(String str, String separator, boolean tone)
      Description copied from interface: PinyinProvider
      Retrieves the complete Pinyin for a given string, with an option to retain tone marks. Non-Chinese characters remain as is.
      Specified by:
      getPinyin in interface PinyinProvider
      Parameters:
      str - The input string.
      separator - The separator to use between each Pinyin character.
      tone - true to retain tone marks in the Pinyin, false otherwise.
      Returns:
      The Pinyin representation of the string.