public void optimizeWords() { String correctedWord; java.util.List<String> v = new ArrayList<String>(words.keySet()); MsgTextPane.write("Applying stem correction to Dictionary..."); matchInfo = false; Collections.sort(v); int success = 0; int failed = 0; for (String str : v) { // str is lowercase and deturkified because it is in keySet correctedWord = correctWordByRules(str); if (!correctedWord.equals(words.get(str))) { failed++; } else { if (success < 100) { dictFrame.writeDictArea("Redundant word removed : " + correctedWord + "\n", false); } else if (success == 100) { dictFrame.writeDictArea("...", false); } words.remove(str); success++; } } MsgTextPane.write("Purge on dictionary : " + success + " words removed\n"); matchInfo = true; }
private void printEntryList(HashSet set, HashMap map) { Iterator iter = set.iterator(); while (iter.hasNext()) { String key = (String) iter.next(); String entry = (String) map.get(key); if (entry != null) { dictFrame.writeDictArea(key + " >> " + entry + "\n", false); } else { dictFrame.writeDictArea(key + "\n", false); } } }
public void removeStem(String word) { String key = language.removeDiacritics(word); stems.remove(key); addedstems.remove(key); removedstems.add(key); dictFrame.writeDictArea("Stem removed: ", false); dictFrame.writeSelectDictArea(word); dictFrame.writeDictArea("\n", false); dictFrame.scrollEnd(); dictFrame.isModified(true); }
public void removeWord(String word) { String key = language.removeDiacritics(word); words.remove(key); addedwords.remove(key); removedwords.add(key); dictFrame.writeDictArea("Word removed: ", false); dictFrame.writeDictArea(word, false); dictFrame.writeDictArea("\n", false); dictFrame.scrollEnd(); dictFrame.isModified(true); }
public String correctWordByDictionary(String word) { if (words.containsKey(word)) { String correctedWord = words.get(word); if (matchInfo) { dictFrame.writeDictArea(word + " >> ", false); dictFrame.writeSelectDictArea(correctedWord); dictFrame.writeDictArea("\n", false); dictFrame.scrollEnd(); } return correctedWord; } else { return word; } }
public void addStem(String word) { String key = language.removeDiacritics(word); if (validCharacters(key)) { stems.put(key, word); removedstems.remove(key); addedstems.add(key); dictFrame.writeDictArea("Stem added: ", false); dictFrame.writeSelectDictArea(word); dictFrame.writeDictArea("\n", false); dictFrame.scrollEnd(); dictFrame.isModified(true); } }
public void optimizeStems() { WordTree w = new WordTree(language); for (String key : words.keySet()) { String word = words.get(key); w.addWord(word, 1); } stems.clear(); ArrayList<String> stemList; stemList = w.scanStems(); for (String stem : stemList) { stems.put(language.removeDiacritics(stem), stem); } MsgTextPane.write(stemList.size() + " stems extracted"); if (true) { String correctedWord; String correctStem; java.util.List<String> v = new ArrayList<String>(stems.keySet()); // MsgTextPane.write("Applying stem reduction to Dictionary..."); matchInfo = false; Collections.sort(v); int success = 0; int failed = 0; for (String str : v) { correctStem = stems.get(str); stems.remove(str); correctedWord = correctWordByRules(str); // no dictionary lookup because otherwise if stem happens to be in words it is removed if (correctedWord.equals(correctStem)) { if (success < 100) { dictFrame.writeDictArea("Redundant stem removed : " + correctedWord + "\n", false); } else if (success == 100) { dictFrame.writeDictArea("...", false); } success++; } else { // put it back stems.put(str, correctStem); failed++; } } MsgTextPane.write(success + " redundant stems removed\n"); matchInfo = true; } }
public boolean saveDictionary(String fileName) { boolean confirm; ConfirmDialog cd = new ConfirmDialog(); cd.popUp( null, words.size() + "/" + stems.size() + " entries will be written to " + fileName, "Continue", "Cancel"); confirm = cd.confirm; if (confirm) { try { File initialFile = new File(fileName); OutputStream is = new FileOutputStream(initialFile); OutputStreamWriter isr = new OutputStreamWriter(is, "UTF-8"); MsgTextPane.write("write encoding = " + isr.getEncoding()); BufferedWriter outputStream = new BufferedWriter(isr); java.util.List<String> v; v = new ArrayList<String>(words.keySet()); for (String str : v) { outputStream.write((String) words.get(str)); outputStream.newLine(); } v = new ArrayList<String>(stems.keySet()); for (String str : v) { outputStream.write("[" + (String) stems.get(str) + "]"); outputStream.newLine(); } outputStream.close(); addedwords.clear(); addedstems.clear(); removedwords.clear(); removedstems.clear(); dictFrame.isModified(false); return true; } catch (IOException io) { MsgTextPane.write(" io exception during save dictionary"); return false; } } else { return false; } }
public void printModifications() { dictFrame.writeDictArea("\nDICTIONARY MODIFICATIONS\n", false); if (!addedwords.isEmpty()) { dictFrame.writeDictArea("WORDS ADDED\n", false); printEntryList(addedwords, words); } if (!removedwords.isEmpty()) { dictFrame.writeDictArea("WORDS REMOVED\n", false); printEntryList(removedwords, words); } if (!addedstems.isEmpty()) { dictFrame.writeDictArea("STEMS ADDED\n", false); printEntryList(addedstems, stems); } if (!removedstems.isEmpty()) { dictFrame.writeDictArea("STEMS REMOVED\n", false); printEntryList(removedstems, stems); } dictFrame.scrollEnd(); }
public void printAll(String dictionaryPattern) { Pattern pattern; Matcher matcher; java.util.List<String> v; int count; if (dictionaryPattern.equals("")) { dictionaryPattern = "^.*$"; } pattern = Pattern.compile(dictionaryPattern); v = new ArrayList<>(words.keySet()); Collections.sort(v); dictFrame.writeDictArea("Searching Dictionary..." + "\n", true); count = 1; for (String str : v) { matcher = pattern.matcher((String) str); // search the keys Boolean found = false; if (matcher.find()) { dictFrame.writeDictArea(count + " " + (String) words.get(str) + "\n", false); count++; } } dictFrame.writeDictArea(count - 1 + " entries in dictionary" + "\n", true); v = new ArrayList<>(stems.keySet()); Collections.sort(v); dictFrame.writeDictArea("Searching stems..." + "\n", true); count = 1; for (String str : v) { matcher = pattern.matcher((String) str); // search the keys Boolean found = false; if (matcher.find()) { dictFrame.writeDictArea(count + " " + str + " " + (String) stems.get(str) + "\n", false); count++; } } dictFrame.writeDictArea(count - 1 + " stems" + "\n", true); }
public void dictionaryWindowVisible(boolean b) { dictFrame.setVisible(b); }
public GenericDictionary(Language l) { language = l; dictFrame = new DictionaryFrame(language); dictFrame.setVisible(false); }