public int CompareTo(Object obj) { if (obj.GetType().Equals(this.GetType())) { TrigramTrinaryNode other = (TrigramTrinaryNode)obj; if (this.frequency < other.frequency) { return(-1); } else if (this.frequency == other.frequency) { return(0); } else { return(1); } } else { return(1); } }
private void loadTrigram() { Trigram = new Trigram(); using (System.IO.StreamReader sr = System.IO.File.OpenText("News.vfreq")) { string s = ""; while ((s = sr.ReadLine()) != null) { s = s.ToLowerInvariant(); string[] split = s.Split(' '); if (split.Length == 2) { TrigramMainNode t = new TrigramMainNode(split[0], long.Parse(split[1])); Trigram.MainNodes.Add(t); } } } using (System.IO.StreamReader sr = System.IO.File.OpenText("News.id3gram")) { string s = ""; while ((s = sr.ReadLine()) != null) { s = s.ToLowerInvariant(); string[] split = s.Split(' '); int[] parse = new int[split.Length]; bool fit = true; for (int i = 0; i < split.Length; i++) { parse[i] = int.Parse(split[i]); if (parse[i] > Trigram.MainNodes.Count) fit = false; } if (split.Length == 4 && fit) { TrigramMainNode tmn = Trigram.MainNodes[parse[0]]; TrigramMainNode secondary = Trigram.MainNodes[parse[1]]; TrigramMainNode trinary = Trigram.MainNodes[parse[2]]; TrigramSecondaryNode tsn = null; if (tmn.SecondaryNodeChildren.Count > 0 && tmn.SecondaryNodeChildren[tmn.SecondaryNodeChildren.Count - 1].index == parse[1]) { tsn = tmn.SecondaryNodeChildren[tmn.SecondaryNodeChildren.Count - 1]; } if (tsn == null) { tsn = new TrigramSecondaryNode(parse[1]); tmn.SecondaryNodeChildren.Add(tsn); } TrigramTrinaryNode ttn = new TrigramTrinaryNode(parse[2], (long)(parse[3])); tsn.TrinaryNodeChildren.Add(ttn); } } } }