示例#1
0
        public static async void MakeFrequencyDictionary(CommonData commonData)
        {
            List <string> data = await FbReaderCover.ReadDataFromFile(@"C:\temp\1.fb2");

            Double fCount = 0;

            commonData.wordItemsHandler = new WordItemsHandler();
            foreach (string line in data)
            {
                fCount++;
                commonData.wordItemsHandler.AddWordFromBookString(line);

                if (fCount < 20 || fCount % 200 == 0)
                {
                    commonData.wordItemsHandler.UpdateStat();
                }

                if (fCount < 20 || fCount % 20 == 0)
                {
                    Console.Clear();
                    //Console.WriteLine("lines: " + fCount);//4150
                    Console.WriteLine(Math.Round((fCount / 4150) * 100, 2) + "%");//4150
                    commonData.wordItemsHandler.PrintStat();
                }
            }

            string rnd = Guid.NewGuid().ToString().Split('-')[0];

            File.WriteAllLines(@"C:\temp\1outMM" + rnd + ".csv", commonData.wordItemsHandler.GetCsvData().ToArray());
            Console.WriteLine(">>>>>>>>>>>>>>>>>>>>>>>>>");
        }
示例#2
0
        internal static async void UpdateContext(CommonData commonData)
        {
            var mostPopular = commonData.wordItemsHandler.GetFirst(700);
            Dictionary <int, string> data = FbReaderCover.ReadDataFromFile(@"C:\temp\1.fb2").Result.Select((element, index) => new { element, index }).ToDictionary(ele => ele.index, ele => ele.element);


            foreach (var item in mostPopular)
            {
                item.contexts = GetContext(data, item.value).Select((element, index) => new { element, index }).ToDictionary(ele => ele.index, ele => new Word(ele.element));
            }



            string output = JsonConvert.SerializeObject(new { data = mostPopular });

            File.WriteAllText(@"C:\temp\withContext.json", output);
        }