/** * * APDPlat - Application Product Development Platform Copyright (c) 2013, 杨尚川, * yang-shangchuan@qq.com * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation, either version 3 of the License, or (at your option) any later * version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program. If not, see <http://www.gnu.org/licenses/>. * */ package org.apdplat.superword.rule; import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.HashMap; import java.util.Map; /** * 词性 * @author 杨尚川 */ public class PartOfSpeech { private PartOfSpeech(){} private static final Logger LOGGER = LoggerFactory.getLogger(PartOfSpeech.class); private static final Map<String, String> pos = new HashMap<>(); static { try(BufferedReader reader = new BufferedReader( new InputStreamReader( PartOfSpeech.class.getResourceAsStream( "/part_of_speech_des.txt")))){ String line = null; while((line=reader.readLine()) != null) { LOGGER.info("解析:{}",line); line = line.trim(); if(StringUtils.isNotBlank(line) && !line.startsWith("#")){ String[] attrs = line.split("="); if(attrs!=null && attrs.length==2){ pos.put(attrs[0], attrs[1]); LOGGER.info("{}={}",attrs[0],attrs[1]); } } } }catch (Exception e){ LOGGER.error("初始化词性失败", e); } LOGGER.info("初始化词性完毕,词性数:{}",pos.size()); } public static String getMeaning(String partOfSpeech){ return pos.get(partOfSpeech); } public static void main(String[] args) { System.out.println(PartOfSpeech.getMeaning("V")); } }