예제 #1
0
        public void TestSelectManyManyMoreWords(int argsize)
        {
            //arrange
            LocalWordDB sut = new LocalWordDB();

            sut.CreateDatabase();

            List <DbWord> wordlist = new List <DbWord>();

            for (int i = 0; i < argsize; i++)
            {
                wordlist.Add(new DbWord {
                    Word = Guid.NewGuid().ToString(), SynsetId = Guid.NewGuid().ToString(), CreationDate = DateTime.Today
                });
            }
            wordlist.Add(defaultDbWord);
            wordlist.Add(defaultDbWord2);

            sut.TryAddWord(defaultDbWord.Word, defaultDbWord.SynsetId).Should().BeTrue();
            sut.TryAddWord(defaultDbWord2.Word, defaultDbWord2.SynsetId).Should().BeTrue();


            //act
            sut.TryGetWords(wordlist, out IEnumerable <DbWord> data2).Should().BeTrue();
            //assert
            var wordOut = data2.ToHashSet();

            wordOut.Contains(defaultDbWord).Should().BeTrue();
            wordOut.Contains(defaultDbWord2).Should().BeTrue();
            //restore
            sut.DeleteDatabase();
        }
예제 #2
0
        public void TestSelectWordsWithoutSynset()
        {
            //arrange
            LocalWordDB sut = new LocalWordDB();

            sut.CreateDatabase();

            List <DbWord> wordlist = new List <DbWord>
            {
                defaultDbWord,
                defaultDbWord2,
                new DbWord {
                    Word = "test3", SynsetId = null, CreationDate = DateTime.Today
                }
            };

            foreach (DbWord word in wordlist)
            {
                sut.TryAddWord(word.Word, word.SynsetId).Should().BeTrue();
            }
            //act-assert


            sut.TryGetWordsWithoutSynset(1000, out IEnumerable <DbWord> outdbWords).Should().Be(1);

            outdbWords.First().Should().Be(wordlist.Last());

            //restore
            sut.DeleteDatabase();
        }
예제 #3
0
        public void TestSelectManyWords()
        {
            //arrange
            LocalWordDB sut = new LocalWordDB();

            sut.CreateDatabase();

            List <DbWord> wordlist = new List <DbWord>
            {
                defaultDbWord,
                defaultDbWord2
            };

            sut.TryAddWord(defaultDbWord.Word, defaultDbWord.SynsetId).Should().BeTrue();
            sut.TryAddWord(defaultDbWord2.Word, defaultDbWord2.SynsetId).Should().BeTrue();
            //act-assert


            sut.TryGetWords(wordlist, out IEnumerable <DbWord> data2);

            DbWord[] wordSelected = data2.ToArray();

            for (int i = 0; i < wordlist.Count; i++)
            {
                wordSelected[i].Should().Be(wordlist[i]);
            }

            //restore
            sut.DeleteDatabase();
        }
예제 #4
0
        public void TestWordCount(int count)
        {
            //arrange
            LocalWordDB sut = new LocalWordDB();

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

            for (int i = 0; i < count; i++)
            {
                wordlist.Add(new DbWord
                {
                    Word         = Guid.NewGuid().ToString(),
                    SynsetId     = Guid.NewGuid().ToString(),
                    CreationDate = DateTime.Today
                });
            }
            //act-assert
            sut.TryAddWords(wordlist).Should().Be(count);

            sut.GetWordCount().Should().Be(wordlist.Count);

            //restore
            sut.DeleteDatabase();
        }
예제 #5
0
        public void TestUpdateWordsRelationStatus()
        {
            //arrange
            LocalWordDB sut = new LocalWordDB();

            sut.CreateDatabase();

            List <DbWord> wordlist = new List <DbWord>
            {
                new DbWord {
                    Word = "test", SynsetId = "b:fzf4687", CreationDate = DateTime.Today, WordId = 1
                },
                new DbWord {
                    Word = "test2", SynsetId = "b:vdqvqdv45", CreationDate = DateTime.Today, WordId = 2
                }
            };

            sut.TryAddWord(defaultDbWord.Word, defaultDbWord.SynsetId).Should().BeTrue();
            sut.TryAddWord(defaultDbWord2.Word, defaultDbWord2.SynsetId).Should().BeTrue();

            //act
            sut.UpdateWordRelationStatus(wordlist, true).Should().Be(2);

            //assert

            sut.TryGetWords(wordlist, out IEnumerable <DbWord> outDbWords).Should().BeTrue();

            outDbWords.Count().Should().Be(wordlist.Count);

            outDbWords.Any(x => x.RelationsRequested == true).Should().BeTrue();


            //restore
            sut.DeleteDatabase();
        }
예제 #6
0
        private static void RetriveRelationsMode(string startTimestamp)
        {
            Console.WriteLine("Here be dragonz again");
            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} ", 1000 - database.GetTodayBabelRequestsCount(), DateTime.Today.ToString());

            int amount = 100;

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

            Console.WriteLine($"{relations.Count()} responses");

            //convert words from BabelRelation to DbRelation list and log : SOLID VIOLATION !
            HashSet <DbRelation> dbRelationToUpdate = babelAPI.ParseBabelRelationsToDbRelation(relations);

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


            //TODO : insert retrieved relations into database and update the word to said they have relations now
            var results = database.TryAddRelations(dbRelationToUpdate);

            Console.WriteLine("{0} relations inserted", results);


            int wordsWithRelationUpdated = database.UpdateWordRelationStatus(relations.Select(x => x.Item2), true);

            int    totalWordCount = database.GetWordCount();
            double stat           = Math.Round((1 - ((double)wordsWithRelationUpdated / (double)totalWordCount)) * 100.0, 2);

            int    goalNotCompleted = database.GetWordWithoutRelationCount(Goal);
            double goalRatio        = Math.Round((1 - ((double)goalNotCompleted / (double)Goal)) * 100.0, 2);

            Console.WriteLine($"Words with relations : {wordsWithRelationUpdated}/{totalWordCount} ({stat}% completed). \n" +
                              $"Goal: {Goal - goalNotCompleted}/{Goal} ({goalRatio}%)");


            /*
             * int wordWithoutSynset = database.GetWordWithoutSynsetCount();
             * int wordsDone = totalWordCount - wordWithoutSynset;
             * double stat = Math.Round((1 - ((double)wordWithoutSynset / (double)totalWordCount)) * 100.0, 2);
             * int goal = 3924;
             * int goalNotCompleted = database.GetWordsNotCompletedCount(goal);
             * Console.WriteLine($"Words with synset in database : {wordsDone}/{totalWordCount} ({stat}% completed), {wordWithoutSynset} left. Goal: {goal - goalNotCompleted}/{goal} ({goalRatio}%)");
             */
        }
예제 #7
0
        public void TestMultipleWordInsertion(int count)
        {
            //arrange
            LocalWordDB sut = new LocalWordDB();

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

            for (int i = 0; i < count; i++)
            {
                wordlist.Add(new DbWord {
                    Word         = Guid.NewGuid().ToString(),
                    SynsetId     = Guid.NewGuid().ToString(),
                    CreationDate = DateTime.Today
                });
            }

            //act-assert
            sut.TryAddWords(wordlist).Should().Be(count);

            int countCheck = 0;

            foreach (DbWord word in wordlist)
            {
                sut.TryGetWord(word.Word, out DbWord wordOut).Should().BeTrue();
                countCheck++;
            }

            countCheck.Should().Be(wordlist.Count);

            //restore
            sut.DeleteDatabase();
        }
예제 #8
0
        public void TestAddWordFromWord()
        {
            //arrange
            LocalWordDB sut = new LocalWordDB();

            sut.CreateDatabase();
            //act-assert
            sut.TryAddWord(defaultDbWord.Word, defaultDbWord.SynsetId).Should().BeTrue();
            //restore
            sut.DeleteDatabase();
        }
예제 #9
0
        public void TestAddLog()
        {
            //arrange
            LocalWordDB sut = new LocalWordDB();

            sut.CreateDatabase();

            sut.TryAddLog("b:576847", "{'hdjkh':'result'}").Should().BeTrue();
            //act-assert
            //restore
            sut.DeleteDatabase();
        }
예제 #10
0
        public void TestDatabaseCreation()
        {
            //arrange
            LocalWordDB sut = new LocalWordDB();

            //act
            sut.CreateDatabase();
            //assert
            File.Exists(LocalWordDB.DbFile).Should().BeTrue();
            //restore
            sut.DeleteDatabase();
            File.Exists(LocalWordDB.DbFile).Should().BeFalse();
        }
예제 #11
0
        public void TestAddRelationFromWordInfo()
        {
            //arrange
            LocalWordDB sut = new LocalWordDB();

            sut.CreateDatabase();

            sut.TryAddWord(defaultDbWord.Word, defaultDbWord.SynsetId).Should().BeTrue();
            sut.TryAddWord(defaultDbWord2.Word, defaultDbWord2.SynsetId).Should().BeTrue();
            //act-assert
            sut.TryAddRelation(defaultDbWord2.Word, defaultDbWord2.SynsetId, "Hyperonym").Should().BeTrue();
            //restore
            sut.DeleteDatabase();
        }
예제 #12
0
        public void TestNotTodayCountLog(int year, int month, int day)
        {
            //arrange
            var         date = new DateTime(year, month, day);
            LocalWordDB sut  = new LocalWordDB();

            sut.CreateDatabase();

            sut.TryAddLog("b:576847", "{'hdjkh':'result'}").Should().BeTrue();
            //act-assert
            sut.GetBabelRequestsCount(date).Should().Be(0);
            //restore
            sut.DeleteDatabase();
        }
예제 #13
0
        public void TestTodayCountLog()
        {
            //arrange
            var         date = DateTime.Now;
            LocalWordDB sut  = new LocalWordDB();

            sut.CreateDatabase();

            sut.TryAddLog("b:576847", "{'hdjkh':'result'}").Should().BeTrue();
            //act-assert
            sut.GetBabelRequestsCount(date).Should().Be(1);
            sut.GetTodayBabelRequestsCount().Should().Be(1);
            //restore
            sut.DeleteDatabase();
        }
예제 #14
0
        public void TestAddRelationToEmpty()
        {
            //arrange
            LocalWordDB sut = new LocalWordDB();

            sut.CreateDatabase();

            sut.TryAddWord(defaultDbWord.Word, defaultDbWord.SynsetId).Should().BeTrue();
            sut.TryAddWord(defaultDbWord2.Word, defaultDbWord2.SynsetId).Should().BeTrue();
            //act-assert
            sut.TryAddRelation(defaultDbWord2.Word, "b:578764644", "Hyperonym").Should().BeTrue();
            sut.SynsetIdToSearch.Count.Should().Be(1);
            //restore
            sut.DeleteDatabase();
        }
예제 #15
0
        public void TestTodayMultipleCountLog(int count)
        {
            //arrange
            LocalWordDB sut = new LocalWordDB();

            sut.CreateDatabase();
            for (int i = 0; i < count; i++)
            {
                sut.TryAddLog(Guid.NewGuid().ToString(), Guid.NewGuid().ToString()).Should().BeTrue();
            }

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

            //restore
            sut.DeleteDatabase();
        }
예제 #16
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}%)");
        }
예제 #17
0
        public void TestSelectWordFromWord()
        {
            //arrange
            LocalWordDB sut = new LocalWordDB();

            sut.CreateDatabase();
            //act-assert
            sut.TryGetWord(defaultDbWord.Word, out DbWord data).Should().BeFalse();

            sut.TryAddWord(defaultDbWord.Word, defaultDbWord.SynsetId).Should().BeTrue();

            sut.TryGetWord(defaultDbWord.Word, out DbWord data2).Should().BeTrue();

            data2.Should().Be(defaultDbWord);


            //restore
            sut.DeleteDatabase();
        }
예제 #18
0
        public void TestUpdateManyWords()
        {
            //arrange
            LocalWordDB sut = new LocalWordDB();

            sut.CreateDatabase();

            List <DbWord> wordlist = new List <DbWord>
            {
                defaultDbWord,
                defaultDbWord2
            };

            sut.TryAddWord(defaultDbWord.Word, defaultDbWord.SynsetId).Should().BeTrue();
            sut.TryAddWord(defaultDbWord2.Word, defaultDbWord2.SynsetId).Should().BeTrue();

            var updatedSynset = "b:04704254";

            List <DbWord> wordlist2 = new List <DbWord>
            {
                new DbWord {
                    Word = "test", SynsetId = updatedSynset, CreationDate = DateTime.Today
                }
            };

            //act
            sut.TryUpdateDbWords(wordlist2).Should().Be(1);

            //assert

            sut.TryGetWords(wordlist, out IEnumerable <DbWord> outDbWords).Should().BeTrue();

            outDbWords.Count().Should().Be(wordlist.Count);

            outDbWords.ToList().Where(x => x.Word == "test").First().SynsetId.Should().Be(updatedSynset);


            //restore
            sut.DeleteDatabase();
        }
예제 #19
0
        public void TestNoRelationsOfWord()
        {
            //arrange
            LocalWordDB sut = new LocalWordDB();

            sut.CreateDatabase();

            sut.TryAddWord(defaultDbWord.Word, defaultDbWord.SynsetId).Should().BeTrue();

            //act-assert
            var wordreturned = sut.TryGetRelationsSum(defaultDbWord);

            wordreturned.Word.Should().Be(defaultDbWord.Word);
            wordreturned.HyperonymCount.Should().Be(0);
            wordreturned.HyponymCount.Should().Be(0);
            wordreturned.OtherCount.Should().Be(0);

            //no hyponym !!!

            //restore
            sut.DeleteDatabase();
        }
예제 #20
0
        public void TestMultipleSimilarWordInsertion()
        {
            //arrange
            LocalWordDB sut = new LocalWordDB();

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

            wordlist.Add(defaultDbWord);
            wordlist.Add(defaultDbWord2);


            //act-assert
            sut.TryAddWords(wordlist).Should().Be(wordlist.Count);


            wordlist2.Add(defaultDbWord);
            sut.TryAddWords(wordlist2).Should().Be(0, "the wordlist 2 should'nt be inserted");

            //restore
            sut.DeleteDatabase();
        }
예제 #21
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();
        }
예제 #22
0
 public DALAPIAdapter(LocalWordDB database)
 {
     _dal = database;
 }