Skip to content

Commit

Permalink
解析字符串
Browse files Browse the repository at this point in the history
  • Loading branch information
ysc committed Apr 12, 2015
1 parent 18c547c commit 7bb9946
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/main/java/org/apdplat/word/segmentation/PartOfSpeech.java
Expand Up @@ -41,20 +41,27 @@ public PartOfSpeech(String pos, String des){
this.des = des;
}
private static class PartOfSpeechMap{
private static final Map<String, String> BUILDIN_POS = getBuildInPos();
private static Map<String, String> getBuildInPos(){
Map<String, String> bip = new HashMap<>();
private static final Map<String, PartOfSpeech> BUILDIN_POS = getBuildInPos();
private static Map<String, PartOfSpeech> getBuildInPos(){
Map<String, PartOfSpeech> bip = new HashMap<>();
try {
for (Field field : PartOfSpeech.class.getFields()) {
PartOfSpeech partOfSpeech = (PartOfSpeech)field.get(PartOfSpeech.class);
bip.put(partOfSpeech.getPos(), partOfSpeech.getDes());
bip.put(partOfSpeech.getPos(), partOfSpeech);
}
}catch (Exception e){
LOGGER.error("词性初始化失败", e);
}
return bip;
}
}
public static PartOfSpeech valueOf(String pos){
PartOfSpeech partOfSpeech = PartOfSpeechMap.BUILDIN_POS.get(pos.toLowerCase());
if(partOfSpeech==null){
partOfSpeech = UNKNOWN;
}
return partOfSpeech;
}
public static boolean isBuildIn(String pos){
return PartOfSpeechMap.BUILDIN_POS.get(pos.toLowerCase()) != null;
}
Expand Down

0 comments on commit 7bb9946

Please sign in to comment.