Beispiel #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}%)");
        }
Beispiel #2
0
        public void TestWordCompletedCount(int count)
        {
            //arrange
            LocalWordDB sut = new LocalWordDB();

            sut.CreateDatabase();
            List <DbWord> wordlist = new List <DbWord>();

            int    nullSynsetCount = 0;
            string synset          = null;

            for (int i = 0; i < count; i++)
            {
                if (i % 2 == 0)//only even
                {
                    synset = Guid.NewGuid().ToString();
                    nullSynsetCount++;
                }

                wordlist.Add(new DbWord
                {
                    Word         = Guid.NewGuid().ToString(),
                    SynsetId     = synset,
                    CreationDate = DateTime.Today
                });

                synset = null;
            }

            sut.TryAddWords(wordlist, true).Should().Be(count);

            //act-assert
            sut.GetWordsNotCompletedCount(count).Should().Be(nullSynsetCount);

            //restore
            sut.DeleteDatabase();
        }