protected int sum(String word) { TagCount count = dict.get(word); if (count != null) { return count.sum(); } return 0; }
private void readTags(DataInputStream rf) throws IOException { // Object[] arr=dict.keySet().toArray(); int maxNumTags = 0; int len = rf.readInt(); if (VERBOSE) { System.err.println("Reading Dictionary of " + len + " words."); } for (int i = 0; i < len; i++) { String word = rf.readUTF(); TagCount count = TagCount.readTagCount(rf); int numTags = count.numTags(); if (numTags > maxNumTags) { maxNumTags = numTags; } this.dict.put(word, count); if (VERBOSE) { System.err.println(" " + word + " [idx=" + i + "]: " + count); } } if (VERBOSE) { System.err.println( "Read dictionary of " + len + " words; max tags for word was " + maxNumTags + '.'); } }
String getFirstTag(String word) { TagCount count = dict.get(word); if (count != null) { return count.getFirstTag(); } return null; }
protected String[] getTags(String word) { TagCount count = get(word); if (count == null) { return null; } return count.getTags(); }
/** * This makes ambiguity classes from all words in the dictionary and remembers their classes in * the TagCounts */ protected void setAmbClasses(AmbiguityClasses ambClasses, int veryCommonWordThresh, TTags ttags) { for (Map.Entry<String, TagCount> entry : dict.entrySet()) { String w = entry.getKey(); TagCount count = entry.getValue(); int ambClassId = ambClasses.getClass(w, this, veryCommonWordThresh, ttags); count.setAmbClassId(ambClassId); } }
protected int getCount(String word, String tag) { TagCount count = dict.get(word); if (count == null) { return 0; } else { return count.get(tag); } }
void save(DataOutputStream file) { String[] arr = dict.keySet().toArray(new String[dict.keySet().size()]); try { file.writeInt(arr.length); System.err.println("Saving dictionary of " + arr.length + " words ..."); for (String word : arr) { TagCount count = get(word); file.writeUTF(word); count.save(file); } Integer[] arrverbs = this.partTakingVerbs.keySet().toArray(new Integer[partTakingVerbs.keySet().size()]); file.writeInt(arrverbs.length); for (Integer iO : arrverbs) { CountWrapper tC = this.partTakingVerbs.get(iO); file.writeInt(iO.intValue()); tC.save(file); } } catch (Exception e) { e.printStackTrace(); } }
private static void assertTagCount(String tag, int n, TagCount tagCount) { assertThat(tagCount.getTag(), is(tag)); assertThat(tagCount.getN(), is(n)); }