Пример #1
0
        public void CalculateCosineSimilarityGreaterThanTest()
        {
            Input1.Add("people");
            Input2.Add("people");
            var test = new CalculateCosine(Input1, Input2);

            Assert.GreaterOrEqual(test._cosValue, 0);
        }
Пример #2
0
        public void MagnitudeTest()
        {
            double vector = 16;

            var test = new CalculateCosine(Input1, Input2);

            Assert.AreEqual(test.SquareRoot(vector), 4);
        }
Пример #3
0
        static void Main(string[] args)
        {
            Stopwatch stopwatch = new Stopwatch();

            Console.WriteLine(Stopwatch.IsHighResolution);
            stopwatch.Start();

            #region LevenshteinDistance
            //Indlæser hver linje af teksten til en liste af strings
            LoadStringToList tekstA = new LoadStringToList(@"C:\Users\Patri\Dropbox\Projekt\P2\Program\Nyheder_Database\Koran_Bible_Same1.txt");
            LoadStringToList tekstB = new LoadStringToList(@"C:\Users\Patri\Dropbox\Projekt\P2\Program\Nyheder_Database\Koran_Bible_Same2.txt");

            // Beregner LevenshteinDistance
            LevenshteinDistance levDis = new LevenshteinDistance(tekstA.Lines, tekstB.Lines, tekstA.GetAmountOfChars(),
                                                                 tekstB.GetAmountOfChars(), tekstA.LinesInText, tekstB.LinesInText);
            levDis.Print(); // Printer LevenshteinDistance mellem de to tekster
            #endregion
            Console.WriteLine(stopwatch.ElapsedMilliseconds);
            stopwatch.Restart();

            #region CosineDistance
            //Indlæser hvert ord fra teksten til en liste af strings
            LoadEachWordToList TextA = new LoadEachWordToList(@"C:\Users\Patri\Dropbox\Projekt\P2\Program\Nyheder_Database\Koran_Bible_Same1.txt");
            LoadEachWordToList TextB = new LoadEachWordToList(@"C:\Users\Patri\Dropbox\Projekt\P2\Program\Nyheder_Database\Koran_Bible_Same2.txt");

            CalculateCosine CalcCos = new CalculateCosine(TextA.Words, TextB.Words); // Beregner CosineDistance
            CalcCos.Print();                                                         // Printer CosineSimilarity mellem de to tekster
            #endregion
            Console.WriteLine(stopwatch.ElapsedMilliseconds);
            stopwatch.Restart();

            #region JaccardDistance
            JaccardSimilarity nytekstA = new JaccardSimilarity(TextA.Words, TextB.Words); // TextA og TextB er indlæst i #region CosineDistance - (LoadEachWordToList)

            nytekstA.Print();                                                             // Printer JaccardSimilarity mellem de to tekster
            #endregion
            Console.WriteLine(stopwatch.ElapsedMilliseconds);
            stopwatch.Stop();

            #region TryDiffrentLoadMethod (Resources)
            //var TekstA = new List<string>();
            //var TekstB = new List<string>();
            //string[] stringSeparators = { ",", ".", "!", "?", ";", ":", " ", "-", "\"", "(", ")" };

            //TekstA = Resources.Pizzagate1.Split(stringSeparators, StringSplitOptions.RemoveEmptyEntries).ToList();
            //TekstB = Resources.Pizzagate2.Split(stringSeparators, StringSplitOptions.RemoveEmptyEntries).ToList();

            //CalculateCosine CalcCos2 = new CalculateCosine(TekstA, TekstB); // Beregner CosineDistance
            //CalcCos2.Print(); // Printer CosineDistance mellem de to tekster
            #endregion

            Console.ReadLine();
        }
Пример #4
0
        public void MatchNounTest()
        {
            var           test    = new CalculateCosine(Input1, Input2);
            string        Pattern = "ad";
            List <string> Input   = new List <string>();

            Input.Add("people");
            Input.Add("head");
            Input.Add("ad");
            Input.Add("the");
            Input.Add("hello");
            Input.Add("");

            Assert.AreEqual(test.MatchNoun(Pattern, Input), 1);
        }
Пример #5
0
        // Returns the greatest CosineSimilarity optained by comparing the text to all texts in the directory
        public override decimal CompareWithTexts(List <string> paths)
        {
            int greatestSimilarity = 0;

            foreach (string path in paths) // Gets CosineSimilarity for all false articles
            {
                var databaseText = new LoadEachWordToList(path);

                var compareTexts = new CalculateCosine(TextToBeCompared, databaseText.Words);

                // Happens if the CosineSimilarity between the two current texts are the greatest so far
                if (compareTexts.Procent > greatestSimilarity)
                {
                    greatestSimilarity = compareTexts.Procent;
                }
            }

            return(greatestSimilarity);
        }
Пример #6
0
        public void DotProductTest()
        {
            var        test       = new CalculateCosine(Input1, Input2);
            List <int> TryVector1 = new List <int>();

            TryVector1.Add(3);
            TryVector1.Add(5);
            TryVector1.Add(0);
            TryVector1.Add(2);
            TryVector1.Add(0);

            List <int> TryVector2 = new List <int>();

            TryVector2.Add(4);
            TryVector2.Add(6);
            TryVector2.Add(0);
            TryVector2.Add(1);
            TryVector2.Add(0);

            Assert.AreEqual(test.DotProduct(TryVector1, TryVector2), 44);
        }
Пример #7
0
        public void CreateVectorVecANotNullTest()
        {
            var test = new CalculateCosine(Input1, Input2);

            Assert.NotNull(test.vecA);
        }
Пример #8
0
        public void ReadNounIsNotEmptyTest()
        {
            var test = new CalculateCosine(Input1, Input2);

            Assert.IsNotEmpty(test.nouns);
        }
Пример #9
0
        public void CalculateCosineSimilarityLessThanTest()
        {
            var test = new CalculateCosine(Input1, Input2);

            Assert.LessOrEqual(test._cosValue, 1);
        }
Пример #10
0
        public void PrintPercentValueGreaterThanTest()
        {
            var test = new CalculateCosine(Input1, Input2);

            Assert.GreaterOrEqual(test.Procent, 0);
        }
Пример #11
0
        public void PrintPercentValueLessThanTest()
        {
            var test = new CalculateCosine(Input1, Input2);

            Assert.LessOrEqual(test.Procent, 100);
        }