private float addCount(HashMap<String, Voca> map, String key) { float value = 1.0f; if (map.containsKey(key)) { Voca voca = map.get(key); value = voca.getCount() + 0.8f; } return value; }
public void wordExtract(HashMap<String, Voca> map, Sentence st) { System.out.println("# [wordExtract()] 어절의 개수 : " + st.size()); try { for (int i = 0; i < st.size() - 2; i++) { Voca voca = new Voca(); String tag = st.get(i).getFirstMorp().getTag(); String fullName = st.get(i).getExp(); String vocaName = st.get(i).getFirstMorp().getString(); String specialTag = st.get(i).get(st.get(i).size() - 1).getTag(); // 체언인지 용언인지 구분 if (isWord(tag)) { if (fullName.length() < 2) { continue; } if (isSpecial(specialTag)) { fullName = fullName.substring(0, fullName.length() - 1); } voca.setFullName(fullName); voca.setVocaName(vocaName); // 다음 단어가 부사와 같은 단어를 걸러내야됨 Eojeol nextEojeol = null; StringBuffer temp = new StringBuffer(); for (int j = i + 1; j < st.size() - 1; j++) { nextEojeol = st.get(j); String nextTag = nextEojeol.getFirstMorp().getTag(); String nextFullName = nextEojeol.getExp(); if (isWord(nextTag)) { if (nextFullName.length() < 2) { temp.append(nextFullName + " "); continue; } break; } } String next = ""; if (isSpecial(nextEojeol.get(nextEojeol.size() - 1).getTag())) { next = nextEojeol.getExp().substring(0, nextEojeol.getExp().length() - 1); temp.append(next); voca.setRelatedName(temp.toString()); } else { temp.append(nextEojeol.getExp()); voca.setRelatedName(temp.toString()); } String key = fullName + temp.toString(); temp = null; voca.setCount(addCount(map, key)); map.put(key, voca); } } } catch (Exception e) { e.printStackTrace(); } System.out.println("단어 개수 : " + map.size()); }