예제 #1
0
        private static void RetriveWordMode(string startTimestamp)
        {
            Console.WriteLine("Here be dragonz");
            string apikey;

            try
            {
                apikey = System.IO.File.ReadAllText(Helpers.GetExecutingDirectoryPath() + @"\babel.apikey");
            }
            catch (Exception)
            {
                throw;
            }

            LocalWordDB  database = new LocalWordDB();
            BabelAPICore babelAPI = new BabelAPICore(apikey, database);

            Console.WriteLine("{0} remaining request for today : {1} ", database.GetTodayBabelRequestsCount(), DateTime.Today.ToString());

            int amount = 100;

            Console.WriteLine("try to retrieve {0} senses", amount);
            Console.WriteLine("Asking babel...");
            var wordsenses = babelAPI.RetrieveWordSenses(amount);

            //convert words from Sense to DbWord list and log : SOLID VIOLATION !
            HashSet <DbWord> dbwordToUpdate = babelAPI.ParseBabelSenseToDbWord(wordsenses);

            Console.WriteLine("Recieved {0} words to update or insert in the database", dbwordToUpdate.Count);

            //insert retrieved synset into database
            var results = database.UpdateOrAddWordsWithSynset(dbwordToUpdate);

            Console.WriteLine("{0} words inserted, {1} words updated", results.Item1, results.Item2);
            int    totalWordCount    = database.GetWordCount();
            int    wordWithoutSynset = database.GetWordWithoutSynsetCount();
            int    wordsDone         = totalWordCount - wordWithoutSynset;
            double stat             = Math.Round((1 - ((double)wordWithoutSynset / (double)totalWordCount)) * 100.0, 2);
            int    goalNotCompleted = database.GetWordsNotCompletedCount(Goal);
            double goalRatio        = Math.Round((1 - ((double)goalNotCompleted / (double)Goal)) * 100.0, 2);

            Console.WriteLine($"Words with synset in database : {wordsDone}/{totalWordCount} ({stat}% completed), {wordWithoutSynset} left. \nGoal: {Goal - goalNotCompleted}/{Goal} ({goalRatio}%)");
        }