Exemplo n.º 1
0
        }         // ///////////////  ////////////////////////////////////////////////////////////////

        public void Push(string key, bool know, bool unknow)
        {
            if (db == null)
            {
                db = new Dictionary <string, int>();
            }
            int val = KnownUnknown.GetN(know, unknow);

            if (db.ContainsKey(key))
            {
                db[key] = val;
            }
            else
            {
                db.Add(key, val);
            }
        }         // //////////////////////////////////////////////////////////////////////////////
Exemplo n.º 2
0
        public void Load(string fname = "")
        {
            if (fname == null)
            {
                fname = defFName;
            }
            if (fname.Length == 0)
            {
                fname = defFName;
            }

            string dbfname = fname;

            if (!File.Exists(dbfname))
            {
                dbfname = @"..\" + dbfname;
                if (!File.Exists(dbfname))
                {
                    dbfname = @"..\" + dbfname;
                    if (!File.Exists(dbfname))
                    {
                        dbfname = @"..\" + dbfname;
                        if (!File.Exists(dbfname))
                        {
                            Console.WriteLine("No DB file '" + fname + "' !");
                            return;
                        }
                    }
                }
            }
            db = new Dictionary <string, int>();
            using (StreamReader sr = new StreamReader(dbfname, Encoding.Default)) {
                string line;
                while ((line = sr.ReadLine()) != null)
                {
                    string sval = line.Substring(0, 1);
                    string skey = line.Substring(1, line.Length - 1);
                    try {
                        db.Add(skey, KnownUnknown.GetN(sval));
                    } catch (ArgumentException) {
                        Console.WriteLine("An element with Key = " + skey + " already exists.");
                    }
                }
            }
        }         // ///////////////////////////////////////////////////////////////////////////////
Exemplo n.º 3
0
        }         // /////////////// 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 = "") ////////////////////