java匹配多音字


import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.concurrent.ExecutionException;

import org.apache.commons.lang.exception.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.support.PropertiesLoaderUtils;

import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;

/**
 * 多音字配置文件读取工具类(duoyizi.properties)
 * 
 * @author ZhuLei
 * @date 2016年11月14日
 */
public final class DuoYinZiUtil {

	private static Logger logger = LoggerFactory.getLogger(DuoYinZiUtil.class);

	private DuoYinZiUtil() {
	}

	private static Properties props = null;
	private static LoadingCache<String, String> cahceBuilder = null;
	private static Map<String, String> map = new HashMap<String, String>();
	static {
		try {

			props = PropertiesLoaderUtils
					.loadAllProperties("duoyizi.properties");
			cahceBuilder = CacheBuilder.newBuilder().maximumSize(100)
					.build(new CacheLoader<String, String>() {
						@Override
						public String load(String key) throws Exception {

							return getValueByKey(key);
						}
					});
			Iterator<Entry<Object, Object>> it = props.entrySet().iterator();
			while (it.hasNext()) {
				@SuppressWarnings({ "rawtypes" })
				Map.Entry entry = (Map.Entry) it.next();
				String key = (String) entry.getKey();
				String value = (String) entry.getValue();
				map.put(key, value);
			}
		} catch (Exception e) {
			logger.error(ExceptionUtils.getFullStackTrace(e));
			System.exit(1);
		}
	}

	private static String getValueByKey(String key) {
		return props.getProperty(key);
	}

	public static String get(String key) {
		try {
			return cahceBuilder.get(key);
		} catch (ExecutionException e) {
			logger.error(ExceptionUtils.getFullStackTrace(e));
		}
		return null;
	}

	public static String get(char key) {
		try {
			return map.get(String.valueOf(key));
		} catch (Exception e) {
			// 不处理,返回空字符串
		}
		return "";
	}

	@SuppressWarnings("unused")
	private static String get(String key, String defaultValue) {
		return props.getProperty(key, defaultValue);
	}

}
这是匹配多音字工具类代码。
下面是配置文件代码
\u67CF=bai
\u8D32=ben
\u8584=bo
\u90FD=du
\u9889=jie
\u89E3=xie
\u79D8=bi
\u957F=chang
\u957F\u5B59=zhangsun
\u725F=mou
\u8398=shen
\u6BB7=yin
\u96BD=juan
\u5C09=wei
\u5C09\u8FDF=yu
\u5947=ji
\u5B93=mi
\u76D6=ge
\u8983=qin
\u5355=shan
\u5355\u4E8E=chan
\u8C0C=shen
\u7FDF=zhai
\u4E50=yue
\u53EC=shao
\u9697=kui
\u79CD=chong
\u6734=piao
\u4EC7=qiu
\u533A=ou
\u6298=she
\u9ED1=hei
\u7E41=po
\u7EAA=ji
\u67E5=cha
\u90C7=huan
\u5F17=fu
\u891A=chu
\u9002=shi
\u53E5=ju
\u961A=kan
\u4E5C=niè
\u772D=sui
\u6D17=xian
\u5458=yun
\u796D=zhai
\u5BBF=su
\u7F2A=miao
\u4E58=cheng
\u8F9F=bi
\u8F66=che
\u4F1A=kuai
\u94C5=qian
\u8304=qie
\u4E07=wan
\u4E07\u4FDF=moqi
\u543E=wu



相关推荐
©️2020 CSDN 皮肤主题: 技术黑板 设计师:CSDN官方博客 返回首页