} // /////////////////////////////////////////////////////////////////////// public WordCnt At(int pos) { CWordCount wc = lstord[pos]; return(new WordCnt { word = wc.word, cnt = wc.cnt }); } // /////////////////////////////////////////////////////////////////////
} // ////////////////////////////////////////////////////////////////////// public void Sorting() { lstord.Clear(); foreach (KeyValuePair <string, ItemDists> item in lst) { CWordCount wc = new CWordCount { cnt = item.Value.Positions.Count, dists = item.Value.SumDists, word = item.Key }; lstord.Add(wc); } if (lstord.Count > 0) { lstord.Sort(); double mindist = lstord[lstord.Count - 1].dists; double maxdist = lstord[0].dists; foreach (CWordCount item in lstord) { item.dists = (mindist == maxdist) ? 0 : 99 * (item.dists - mindist) / (maxdist - mindist); } } } // ///////////////////////////////////////////////////////////////////////
} // /////////////// public void DelUn() ///////////////////////////// public void Report(Dictionary <string, int> dict_db, bool?know, bool?unknow, int min_cnt, string path = "") { Sorting(); grdata = new ObservableCollection <OutGridData>(); int n = 0; double sum = 0, min = 0, max = 0; //for (int i = 0; i < lstord.Count; i++) { foreach (CWordCount wc in lstord) { //CWordCount wc = lstord[i]; sum += wc.cnt; //int val = dict_db[wc.word]; bool bknow = false, bunknow = false, needAdd = true; if (dict_db != null) { n++; if (dict_db.ContainsKey(wc.word)) { KnownUnknown.Pop(dict_db, wc.word, out bknow, out bunknow); if (know == null && unknow == null) { //needAdd = true; } else if (know != null && unknow != null) { needAdd = ((bunknow == unknow) && (bknow == know)); } else if (unknow != null && know == null) { needAdd = (bunknow == unknow); } else if (know != null && unknow == null) { needAdd = (bknow == know); } } } if (needAdd) { if (wc.dists < min) { min = wc.dists; } if (wc.dists > max) { max = wc.dists; } // Не загружать, если количество менее if (wc.cnt >= min_cnt) { grdata.Add(new OutGridData(n, wc.cnt, wc.dists, wc.word, bknow, bunknow)); } } } foreach (OutGridData grd in grdata) { grd.Percent = (min == max) ? 0 : (double)(0.1 * (int)(1000 * (grd.Percent - min) / (max - min))); } if (path.Length == 0) { for (int i = 0; i < lstord.Count; i++) { CWordCount wc = lstord[i]; Console.WriteLine("{0} Cnt = {1}, Word = {2}, Dists = {3}", i, wc.cnt, wc.word, wc.dists); } } else { try { if (File.Exists(path)) { File.Delete(path); } using (StreamWriter sw = File.CreateText(path)) { sw.WriteLine("N;Count;Word"); int sumf = 0; for (int i = 0; i < lstord.Count; i++) { CWordCount wc = lstord[i]; sumf += wc.cnt; if (allWord > 0) { sw.WriteLine("{0};{1};{2};{3};{4}", i, (int)(100 * sum / allWord), wc.cnt, wc.word, wc.dists); //Console.WriteLine("{0} {1} {2} {3} {4}", i, (int)(100 * sum / allWord), wc.cnt, wc.word, wc.dists); } } } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } } // ///////////////// public void report(string path = "") ////////////////////