/* * public void save(String filename) { * try { * DataOutputStream rf = IOUtils.getDataOutputStream(filename); * save(rf); * rf.close(); * } catch (Exception e) { * e.printStackTrace(); * } * } */ internal virtual void Save(DataOutputStream file) { string[] arr = Sharpen.Collections.ToArray(dict.Keys, new string[dict.Keys.Count]); try { file.WriteInt(arr.Length); log.Info("Saving dictionary of " + arr.Length + " words ..."); foreach (string word in arr) { TagCount count = Get(word); file.WriteUTF(word); count.Save(file); } int[] arrverbs = Sharpen.Collections.ToArray(this.partTakingVerbs.Keys, new int[partTakingVerbs.Keys.Count]); file.WriteInt(arrverbs.Length); foreach (int iO in arrverbs) { CountWrapper tC = this.partTakingVerbs[iO]; file.WriteInt(iO); tC.Save(file); } } catch (Exception e) { Sharpen.Runtime.PrintStackTrace(e); } }
internal virtual void FillWordTagCounts(IDictionary <string, IntCounter <string> > wordTagCounts) { foreach (string word in wordTagCounts.Keys) { TagCount count = new TagCount(wordTagCounts[word]); dict[word] = count; } }
/* * public void printAmbiguous() { * String[] arr = dict.keySet().toArray(new String[dict.keySet().size()]); * try { * int countAmbiguous = 0; * int countUnAmbiguous = 0; * int countAmbDisamb = 0; * for (String word : arr) { * if (word.indexOf('|') == -1) { * continue; * } * TagCount count = get(word); * if (count.numTags() > 1) { * System.out.print(word); * countAmbiguous++; * tC.print(); * System.out.println(); * } else { * String wordA = word.substring(0, word.indexOf('|')); * if (get(wordA).numTags() > 1) { * System.out.print(word); * countAmbDisamb++; * countUnAmbiguous++; * tC.print(); * System.out.println(); * } else { * countUnAmbiguous++; * } * }// else * } * System.out.println(" ambg " + countAmbiguous + " unambg " + countUnAmbiguous + " disamb " + countAmbDisamb); * } catch (Exception e) { * e.printStackTrace(); * } * } */ /// <summary> /// This makes ambiguity classes from all words in the dictionary and remembers /// their classes in the TagCounts /// </summary> protected internal virtual void SetAmbClasses(AmbiguityClasses ambClasses, int veryCommonWordThresh, TTags ttags) { foreach (KeyValuePair <string, TagCount> entry in dict) { string w = entry.Key; TagCount count = entry.Value; int ambClassId = ambClasses.GetClass(w, this, veryCommonWordThresh, ttags); count.SetAmbClassId(ambClassId); } }
protected internal virtual int Sum(string word) { TagCount count = dict[word]; if (count != null) { return(count.Sum()); } return(0); }
internal virtual string GetFirstTag(string word) { TagCount count = dict[word]; if (count != null) { return(count.GetFirstTag()); } return(null); }
protected internal virtual string[] GetTags(string word) { TagCount count = Get(word); if (count == null) { return(null); } return(count.GetTags()); }
protected internal virtual int GetCount(string word, string tag) { TagCount count = dict[word]; if (count == null) { return(0); } else { return(count.Get(tag)); } }
/// <exception cref="System.IO.IOException"/> private void ReadTags(DataInputStream rf) { // Object[] arr=dict.keySet().toArray(); int maxNumTags = 0; int len = rf.ReadInt(); 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[word] = count; } }