当前位置: 首页>>代码示例>>Java>>正文


Java HanyuPinyinVCharType类代码示例

本文整理汇总了Java中net.sourceforge.pinyin4j.format.HanyuPinyinVCharType的典型用法代码示例。如果您正苦于以下问题:Java HanyuPinyinVCharType类的具体用法?Java HanyuPinyinVCharType怎么用?Java HanyuPinyinVCharType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HanyuPinyinVCharType类属于net.sourceforge.pinyin4j.format包,在下文中一共展示了HanyuPinyinVCharType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getAllPinYin

import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType; //导入依赖的package包/类
public List<String> getAllPinYin(char c){
    HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
    format.setCaseType(HanyuPinyinCaseType.LOWERCASE);
    format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
    format.setVCharType(HanyuPinyinVCharType.WITH_U_UNICODE);
    Set<String> set = new HashSet<>();
    try {
        String[] pinYinStringArray = PinyinHelper.toHanyuPinyinStringArray(c, format);
        for(String pinYin : pinYinStringArray){
            pinYin = pinYin.toLowerCase().replace("ü", "v");
            if(StringUtils.isBlank(pinYin)){
                continue;
            }
            set.add(pinYin);
            set.add(String.valueOf(pinYin.charAt(0)));
            charPinYin.add(pinYin);
            if(pinYin.length() > charMaxPinYinLength){
                charMaxPinYinLength = pinYin.length();
            }
        }
    }catch (Exception e){
        LOGGER.error("获取拼音失败", e);
    }
    return set.stream().sorted().collect(Collectors.toList());
}
 
开发者ID:ysc,项目名称:short-text-search,代码行数:26,代码来源:ShortTextSearcher.java

示例2: toPinYin

import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType; //导入依赖的package包/类
/**
 * 返回一个字的拼音
 */
public static String toPinYin(char hanzi) {
    HanyuPinyinOutputFormat hanyuPinyin = new HanyuPinyinOutputFormat();
    hanyuPinyin.setCaseType(HanyuPinyinCaseType.LOWERCASE);
    hanyuPinyin.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
    hanyuPinyin.setVCharType(HanyuPinyinVCharType.WITH_U_UNICODE);
    String[] pinyinArray = null;
    try {
        //是否在汉字范围内
        if (hanzi >= 0x4e00 && hanzi <= 0x9fa5) {
            pinyinArray = PinyinHelper.toHanyuPinyinStringArray(hanzi, hanyuPinyin);
        }
    } catch (BadHanyuPinyinOutputFormatCombination e) {
        e.printStackTrace();
        Log.e(TAG, "toPinYin: hanzi = "+hanzi );
        Log.e(TAG, "toPinYin: pinyinArray.toString() = "+pinyinArray.toString() );
    }
    //将获取到的拼音返回
    if (pinyinArray != null && pinyinArray.length > 0) {
        return pinyinArray[0];
    } else {
        Log.e(TAG, "toPinYin: hanzi = "+hanzi );
        return "#";
    }
}
 
开发者ID:lijunyandev,项目名称:MeetMusic,代码行数:28,代码来源:ChineseToEnglish.java

示例3: getPinYin

import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType; //导入依赖的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

示例4: getSinglePinyin

import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType; //导入依赖的package包/类
/**
 * 字到拼音
 * @param zhWord
 * @return
 */
public static String getSinglePinyin(char zhWord){
    String pinyin[] = new String[0];
    if (zhWord=='\0'){  // 判定字符是否为空
        return "";
    }
    if (zhWord=='(' || zhWord==')' || zhWord=='/'){
        return "";
    }
    HanyuPinyinOutputFormat hanyuPinyinOutputFormat = new HanyuPinyinOutputFormat();
    hanyuPinyinOutputFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
    hanyuPinyinOutputFormat.setVCharType(HanyuPinyinVCharType.WITH_V);
    try {
        pinyin= PinyinHelper.toHanyuPinyinStringArray(zhWord,hanyuPinyinOutputFormat);
    } catch (BadHanyuPinyinOutputFormatCombination badHanyuPinyinOutputFormatCombination) {
        badHanyuPinyinOutputFormatCombination.printStackTrace();
    }
    return  pinyin[0];
}
 
开发者ID:wellCh4n,项目名称:Anti-Evil,代码行数:24,代码来源:PinyinQuery.java

示例5: getPinYin

import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType; //导入依赖的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

示例6: getPingYin

import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType; //导入依赖的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

示例7: getPinYin

import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType; //导入依赖的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

示例8: getPinyin

import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType; //导入依赖的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

示例9: testToPinyin

import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType; //导入依赖的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

示例10: testIsChinese

import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType; //导入依赖的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

示例11: getPingYin

import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType; //导入依赖的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

示例12: getPingYin

import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType; //导入依赖的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

示例13: initHanyuPinyin

import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType; //导入依赖的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

示例14: getPingYin

import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType; //导入依赖的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

示例15: getPingYin

import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType; //导入依赖的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


注:本文中的net.sourceforge.pinyin4j.format.HanyuPinyinVCharType类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。