當前位置: 首頁>>代碼示例>>Java>>正文


Java HanyuPinyinOutputFormat.setVCharType方法代碼示例

本文整理匯總了Java中net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat.setVCharType方法的典型用法代碼示例。如果您正苦於以下問題:Java HanyuPinyinOutputFormat.setVCharType方法的具體用法?Java HanyuPinyinOutputFormat.setVCharType怎麽用?Java HanyuPinyinOutputFormat.setVCharType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat的用法示例。


在下文中一共展示了HanyuPinyinOutputFormat.setVCharType方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getPinYin

import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat; //導入方法依賴的package包/類
/**
 * 將漢字轉換為全拚
 *
 * @param src 源漢字
 * @return String pin yin
 */
public static String getPinYin(String src) {
    char[] t1 = src.toCharArray();
    String[] t2;
    // 設置漢字拚音輸出的格式
    HanyuPinyinOutputFormat t3 = new HanyuPinyinOutputFormat();
    t3.setCaseType(HanyuPinyinCaseType.LOWERCASE);
    t3.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
    t3.setVCharType(HanyuPinyinVCharType.WITH_V);
    StringBuilder t4 = new StringBuilder();
    try {
        for (char aT1 : t1) {
            // 判斷是否為漢字字符
            if (Character.toString(aT1).matches("[\\u4E00-\\u9FA5]+")) {
                t2 = PinyinHelper.toHanyuPinyinStringArray(aT1, t3);// 將漢字的幾種全拚都存到t2數組中
                t4.append(t2[0]);// 取出該漢字全拚的第一種讀音並連接到字符串t4後
            } else {
                // 如果不是漢字字符,直接取出字符並連接到字符串t4後
                t4.append(Character.toString(aT1));
            }
        }
    } catch (BadHanyuPinyinOutputFormatCombination e) {
        LOGGER.error("", e);
    }
    return t4.toString();
}
 
開發者ID:ruyangit,項目名稱:angit,代碼行數:32,代碼來源:PinyinUtil.java

示例2: getPinYin

import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat; //導入方法依賴的package包/類
/**
 * 將字符串中的中文轉化為拚音,其他字符不變
 *
 * @param inputString
 *
 * @return
 */
public static String getPinYin(String inputString) {
    HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
    format.setCaseType(HanyuPinyinCaseType.LOWERCASE);
    format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
    format.setVCharType(HanyuPinyinVCharType.WITH_V);

    char[] input = inputString.trim().toCharArray();
    String output = "";

    try {
        for (int i = 0; i < input.length; i++) {
            if (java.lang.Character.toString(input[i]).matches("[\\u4E00-\\u9FA5]+")) {
                String[] temp = PinyinHelper.toHanyuPinyinStringArray(input[i], format);
                output += temp[0];
            } else
                output += java.lang.Character.toString(input[i]);
        }
    } catch (BadHanyuPinyinOutputFormatCombination e) {
        e.printStackTrace();
    }
    return output;
}
 
開發者ID:roselism,項目名稱:CallPP,代碼行數:30,代碼來源:ChineseComparator.java

示例3: getPingYin

import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat; //導入方法依賴的package包/類
public static String getPingYin(String src) {
    char[] t1 = null;
    t1 = src.toCharArray();
    String[] t2 = new String[t1.length];
    HanyuPinyinOutputFormat t3 = new HanyuPinyinOutputFormat();
    t3.setCaseType(HanyuPinyinCaseType.LOWERCASE);
    t3.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
    t3.setVCharType(HanyuPinyinVCharType.WITH_V);
    String t4 = "";
    int t0 = t1.length;
    try {
        for (int i = 0; i < t0; i++) {
            // 判斷是否為漢字字符
            if (java.lang.Character.toString(t1[i]).matches("[\\u4E00-\\u9FA5]+")) {
                t2 = PinyinHelper.toHanyuPinyinStringArray(t1[i], t3);
                t4 += t2[0];
            } else {
                t4 += java.lang.Character.toString(t1[i]);
            }
        }
        return t4;
    } catch (BadHanyuPinyinOutputFormatCombination e1) {
        e1.printStackTrace();
    }
    return t4;
}
 
開發者ID:chengxp3,項目名稱:galaxy,代碼行數:27,代碼來源:StockChineseToPinyin.java

示例4: getPinYin

import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat; //導入方法依賴的package包/類
public static String getPinYin(String strs) {

        HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
        format.setCaseType(HanyuPinyinCaseType.LOWERCASE);
        format.setToneType(HanyuPinyinToneType.WITHOUT_TONE); // WITH_TONE_NUMBER/WITHOUT_TONE/WITH_TONE_MARK
        format.setVCharType(HanyuPinyinVCharType.WITH_U_UNICODE);
        char[] ch = strs.trim().toCharArray();
        StringBuffer buffer = new StringBuffer("");

        try {
            for (int i = 0; i < ch.length; i++) {
                // unicode,bytes應該也可以.
                if (Character.toString(ch[i]).matches("[\u4e00-\u9fa5]+")) {
                    String[] temp = PinyinHelper.toHanyuPinyinStringArray(ch[i], format);
                    buffer.append(temp[0]);
                    //buffer.append(" ");
                } else {
                    buffer.append(Character.toString(ch[i]));
                }
            }
        } catch (BadHanyuPinyinOutputFormatCombination e) {
            e.printStackTrace();
        }
        return buffer.toString();
    }
 
開發者ID:xuxueli,項目名稱:xxl-incubator,代碼行數:26,代碼來源:PinyinUtil.java

示例5: getPinyin

import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat; //導入方法依賴的package包/類
@Override
public String[] getPinyin(char ch) throws IllegalPinyinException {
	try{
		HanyuPinyinOutputFormat outputFormat = new HanyuPinyinOutputFormat();
		outputFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
		outputFormat.setCaseType(HanyuPinyinCaseType.LOWERCASE);
		outputFormat.setVCharType(HanyuPinyinVCharType.WITH_V);

		if(ch>=32 && ch<=125){	//ASCII >=33 ASCII<=125的直接返回 ,ASCII碼表:http://www.asciitable.com/
			return new String[]{String.valueOf(ch)};
		}
		return ArrayUtils.distinct(PinyinHelper.toHanyuPinyinStringArray(ch, outputFormat));
	} catch (BadHanyuPinyinOutputFormatCombination e) {
		throw new IllegalPinyinException(e);
	}

}
 
開發者ID:TFdream,項目名稱:py4j,代碼行數:18,代碼來源:PinyinConverter.java

示例6: testToPinyin

import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat; //導入方法依賴的package包/類
private void testToPinyin() throws IOException {
        initNames();
        HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
        format.setVCharType(HanyuPinyinVCharType.WITH_V);
        names.forEach(name -> {
            String py = null;
            try {
                py = PinyinHelper.toHanYuPinyinString(name, format, "", true);
                String hanPy = Han2Pinyin(name);
                String hanPy2 = HanLP.convertToPinyinString(name, "", false);
                if (!py.equals(hanPy)) {
                    System.out.println(String.format("%s: %s - %s - %s", name, py, hanPy, hanPy2));
                }

//                if (!py.equals(py.replaceAll("[\\u3400-\\u9FFF]", ""))) {
//                    System.out.println(py);
//                }
            } catch (BadHanyuPinyinOutputFormatCombination badHanyuPinyinOutputFormatCombination) {
                badHanyuPinyinOutputFormatCombination.printStackTrace();
            }
        });
    }
 
開發者ID:ltf,項目名稱:lab,代碼行數:23,代碼來源:PinyinTest.java

示例7: testIsChinese

import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat; //導入方法依賴的package包/類
@Test
public void testIsChinese() throws BadHanyuPinyinOutputFormatCombination {
    char[] allChars = allChars();
    final int allCharsLength = allChars.length;
    HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
    format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
    format.setCaseType(HanyuPinyinCaseType.UPPERCASE);
    format.setVCharType(HanyuPinyinVCharType.WITH_V);

    for (int i = 0; i < allCharsLength; i++) {
        char targetChar = allChars[i];
        String[] pinyins = PinyinHelper.toHanyuPinyinStringArray(targetChar, format);
        if (pinyins != null && pinyins.length > 0) {
            // is chinese
            assertThat(Pinyin.isChinese(targetChar), is(true));
        } else {
            // not chinese
            assertThat(Pinyin.isChinese(targetChar), is(false));
        }
    }
}
 
開發者ID:promeG,項目名稱:TinyPinyin,代碼行數:22,代碼來源:PinyinTest.java

示例8: getPingYin

import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat; //導入方法依賴的package包/類
/**
 * ���ַ����е�����ת��Ϊƴ��,�����ַ�����
 * @param inputString
 * @return
 */
public static String getPingYin(String inputString) {
	HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
	format.setCaseType(HanyuPinyinCaseType.LOWERCASE);
	format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
	format.setVCharType(HanyuPinyinVCharType.WITH_V);

	char[] input = inputString.trim().toCharArray();
	String output = "";

	try {
		for (char curchar : input) {
			if (java.lang.Character.toString(curchar).matches(
					"[\\u4E00-\\u9FA5]+")) {
				String[] temp = PinyinHelper.toHanyuPinyinStringArray(
						curchar, format);
				output += temp[0];
			} else
				output += java.lang.Character.toString(curchar);
		}
	} catch (BadHanyuPinyinOutputFormatCombination e) {
		e.printStackTrace();
	}
	return output;
}
 
開發者ID:nighthary,項目名稱:phoneContact,代碼行數:30,代碼來源:PinyinUtils.java

示例9: getPingYin

import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat; //導入方法依賴的package包/類
/**
 * 將字符串中的中文轉化為拚音,其他字符不變
 * 
 * @param inputString
 * @return
 */
public static String getPingYin(String inputString) {
	HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
	format.setCaseType(HanyuPinyinCaseType.LOWERCASE);
	format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
	format.setVCharType(HanyuPinyinVCharType.WITH_V);

	char[] input = inputString.trim().toCharArray();
	String output = "";

	try {
		for (int i = 0; i < input.length; i++) {
			if (java.lang.Character.toString(input[i]).matches("[\\u4E00-\\u9FA5]+")) {
				String[] temp = PinyinHelper.toHanyuPinyinStringArray(input[i], format);
				output += temp[0];
			} else
				output += java.lang.Character.toString(input[i]);
		}
	} catch (BadHanyuPinyinOutputFormatCombination e) {
		e.printStackTrace();
	}
	return output;
}
 
開發者ID:ImKarl,項目名稱:ccshop,代碼行數:29,代碼來源:PinYinUtil.java

示例10: initHanyuPinyin

import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat; //導入方法依賴的package包/類
public static void initHanyuPinyin() {
	format = new HanyuPinyinOutputFormat();

	// UPPERCASE:大寫 (ZHONG)
	// LOWERCASE:小寫 (zhong)
	format.setCaseType(HanyuPinyinCaseType.LOWERCASE);

	// WITHOUT_TONE:無音標 (zhong)
	// WITH_TONE_NUMBER:1-4數字表示英標 (zhong4)
	// WITH_TONE_MARK:直接用音標符(必須WITH_U_UNICODE否則異常) (zhòng)
	format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);

	// WITH_V:用v表示ü (nv)
	// WITH_U_AND_COLON:用"u:"表示ü (nu:)
	// WITH_U_UNICODE:直接用ü (nü)
	format.setVCharType(HanyuPinyinVCharType.WITH_V);

}
 
開發者ID:justingboy,項目名稱:CouldBooks,代碼行數:19,代碼來源:BookSortUtil.java

示例11: getPingYin

import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat; //導入方法依賴的package包/類
/**
 * 將字符串中的中文轉化為拚音,其他字符不變
 *
 * @param inputString
 * @return
 */
public static String getPingYin(String inputString) {
    HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
    format.setCaseType(HanyuPinyinCaseType.LOWERCASE);
    format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
    format.setVCharType(HanyuPinyinVCharType.WITH_V);

    char[] input = inputString.trim().toCharArray();
    String output = "";

    try {
        for (int i = 0; i < input.length; i++) {
            if (java.lang.Character.toString(input[i]).matches("[\\u4E00-\\u9FA5]+")) {
                String[] temp = PinyinHelper.toHanyuPinyinStringArray(input[i], format);
                output += temp[0];
            } else
                output += java.lang.Character.toString(input[i]);
        }
    } catch (BadHanyuPinyinOutputFormatCombination e) {
        e.printStackTrace();
    }
    return output;
}
 
開發者ID:krisjin,項目名稱:bscl,代碼行數:29,代碼來源:ChineseUtil.java

示例12: getPingYin

import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat; //導入方法依賴的package包/類
/**
 * ���ַ��е�����ת��Ϊƴ��,�����ַ��
 * 
 * @param inputString
 * @return
 */
public static String getPingYin(String inputString) {
	HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
	format.setCaseType(HanyuPinyinCaseType.LOWERCASE);
	format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
	format.setVCharType(HanyuPinyinVCharType.WITH_V);

	char[] input = inputString.trim().toCharArray();
	String output = "";

	try {
		for (int i = 0; i < input.length; i++) {
			if (java.lang.Character.toString(input[i]).matches("[\\u4E00-\\u9FA5]+")) {
				String[] temp = PinyinHelper.toHanyuPinyinStringArray(input[i], format);
				output += temp[0];
			} else
				output += java.lang.Character.toString(input[i]);
		}
	} catch (BadHanyuPinyinOutputFormatCombination e) {
		e.printStackTrace();
	}
	return output;
}
 
開發者ID:BusinessWechat,項目名稱:YikuairAndroid,代碼行數:29,代碼來源:PingYinUtil.java

示例13: getPinYin

import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat; //導入方法依賴的package包/類
private static String getPinYin(String words, boolean acronym) {
    HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
    format.setCaseType(HanyuPinyinCaseType.LOWERCASE);
    format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
    format.setVCharType(HanyuPinyinVCharType.WITH_U_UNICODE);
    char[] chars = words.trim().toCharArray();
    StringBuilder result = new StringBuilder();
    try {
        for (char c : chars) {
            if (Character.toString(c).matches("[\u4e00-\u9fa5]+")) {
                String[] pinyinStringArray = PinyinHelper.toHanyuPinyinStringArray(c, format);
                if(acronym){
                    result.append(pinyinStringArray[0].charAt(0));
                }else {
                    result.append(pinyinStringArray[0]);
                }
            }else{
                return null;
            }
        }
    } catch (Exception e) {
        LOGGER.error("拚音標注失敗", e);
    }
    return result.toString();
}
 
開發者ID:ysc,項目名稱:word,代碼行數:26,代碼來源:PinyinTagging.java

示例14: toPinYinUpperCase

import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat; //導入方法依賴的package包/類
/**
 * 將漢字轉換為全大寫拚音
 * @param src
 * @return
 * @throws Exception
 */
public static String toPinYinUpperCase(String src) throws Exception {

    HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
    //全部大寫
    format.setCaseType(HanyuPinyinCaseType.UPPERCASE);
    //不攜帶音標
    format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
    format.setVCharType(HanyuPinyinVCharType.WITH_U_AND_COLON);
    try {
        String s = PinyinHelper.toHanYuPinyinString(src, format, "", true);
        return s;
    } catch (BadHanyuPinyinOutputFormatCombination badHanyuPinyinOutputFormatCombination) {
        throw new Exception("無法轉換拚音");
    }
}
 
開發者ID:pengjieran,項目名稱:OpenTools,代碼行數:22,代碼來源:PinYinUtil.java

示例15: processMessageString

import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat; //導入方法依賴的package包/類
/**
 * Sends alerts to the Pebble watch, as per the Pebble app's intents
 * @param alert Alert which to send to the watch.
 */
private static String processMessageString(String originalMessage) {
	// This is the traditional Pebble alert which does not show Unicode characters
	HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
	format.setCaseType(HanyuPinyinCaseType.LOWERCASE);
	format.setToneType(HanyuPinyinToneType.WITH_TONE_NUMBER);
	format.setVCharType(HanyuPinyinVCharType.WITH_V);
				
	try {
		// I know this is deprecated but there's no viable alternative...
		return PinyinHelper.toHanyuPinyinString(originalMessage, format , "");
	} catch (BadHanyuPinyinOutputFormatCombination e) {
		Log.e("Pinyin", "Failed to convert pinyin");
	}

	return "";
}
 
開發者ID:etiago,項目名稱:WeChatPebble,代碼行數:21,代碼來源:MessageProcessingService.java


注:本文中的net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat.setVCharType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。