io.xuxiaowei:pinyin4j

说明

  • com.belerweb:pinyin4j 在处理单字拼音时,无法得到预期结果,如:

    1. 像将 有限公司 期望转为拼音 you$xian$gong$si,但是只能得到 you$xian$gongsi
      package net.sourceforge.pinyin4j.test;
      
      import junit.framework.TestCase;
      import net.sourceforge.pinyin4j.PinyinHelper;
      import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
      import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
      import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
      import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
      
      /**
       * @author xuxiaowei
       */
      public class StandaloneWordTests extends TestCase {
      
          public void testWord_1() throws BadHanyuPinyinOutputFormatCombination {
              HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
              format.setCaseType(HanyuPinyinCaseType.LOWERCASE);
              format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
              String string = PinyinHelper.toHanYuPinyinString("有限公司", format, "$", false);
              assertEquals("you$xian$gongsi", string);
          }
      
      }
      
  • io.xuxiaowei:pinyin4j,能够满足上述要求,并且保留原有功能

    package net.sourceforge.pinyin4j.test;
    
    import junit.framework.TestCase;
    import net.sourceforge.pinyin4j.PinyinHelper;
    import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
    import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
    import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
    import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
    
    /**
     * @author xuxiaowei
     */
    public class StandaloneWordTests extends TestCase {
    
        public void testWord_1() throws BadHanyuPinyinOutputFormatCombination {
            HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
            format.setCaseType(HanyuPinyinCaseType.LOWERCASE);
            format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
            String string = PinyinHelper.toHanYuPinyinString("有限公司", format, "$", false);
            assertEquals("you$xian$gongsi", string);
        }
    
        public void testWord_2() throws BadHanyuPinyinOutputFormatCombination {
            HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
            format.setCaseType(HanyuPinyinCaseType.LOWERCASE);
            format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
            String string = PinyinHelper.toHanYuPinyinString("有限公司", format, "$", false, false);
            assertEquals("you$xian$gongsi", string);
        }
    
        public void testWord_3() throws BadHanyuPinyinOutputFormatCombination {
            HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
            format.setCaseType(HanyuPinyinCaseType.LOWERCASE);
            format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
            String string = PinyinHelper.toHanYuPinyinString("有限公司", format, "$", false, true);
            assertEquals("you$xian$gong$si$", string);
        }
    
    }
    

io.xuxiaowei:pinyin4j 发布版本

发布版本 发布时间
2.5.1 2025-07-12 17:43
2.5.2 2025-09-02 12:03

com.belerweb:pinyin4j 发布版本

发布版本 发布时间
2.5.0 2013-04-22 09:08
2.5.1 2016-03-15 06:54