Example #1
0
        public void TestSimilarity()
        {
            var instance = new NormalizedLevenshtein();

            NullEmptyTests.TestSimilarity(instance);

            // TODO: regular (non-null/empty) similarity tests
        }
Example #2
0
        public void TestSimilarity()
        {
            var instance = new Cosine();

            var result = instance.Similarity("ABC", "ABCE");

            Assert.Equal(
                expected: 0.71,
                actual: result,
                precision: 2 // 0.01
                );

            NullEmptyTests.TestSimilarity(instance);
        }
Example #3
0
        public void TestSimilarity()
        {
            var instance = new Jaccard(k: 2);

            // AB BC CD DE DF
            // 1  1  1  1  0
            // 1  1  1  0  1
            // => 3 / 5 = 0.6
            var result = instance.Similarity("ABCDE", "ABCDF");

            Assert.Equal(expected: 0.6, actual: result);

            NullEmptyTests.TestSimilarity(instance);
        }
Example #4
0
        public void TestSimilarity()
        {
            var instance = new JaroWinkler();

            Assert.Equal(
                expected: 0.974074,
                actual: instance.Similarity("My string", "My tsring"),
                precision: 6 // 0.000001
                );

            Assert.Equal(
                expected: 0.896296,
                actual: instance.Similarity("My string", "My ntrisg"),
                precision: 6 // 0.000001
                );

            NullEmptyTests.TestSimilarity(instance);
        }
        public void TestSimilarity()
        {
            var instance = new SorensenDice(2);

            // AB BC CD DE DF FG
            // 1  1  1  1  0  0
            // 1  1  1  0  1  1
            // => 2 x 3 / (4 + 5) = 6/9 = 0.6666
            var result = instance.Similarity("ABCDE", "ABCDFG");

            Assert.Equal(
                expected: 0.6667, // last digit should be 7 because of rounding
                actual: result,
                precision: 4      //0.0001
                );

            NullEmptyTests.TestSimilarity(instance);
        }
Example #6
0
        public void TestSimilarity()
        {
            var instance = new RatcliffObershelp();

            /// test data from other algorithms
            /// "My string" vs "My tsring"
            /// Substrings:
            /// "ring" ==> 4, "My s" ==> 3, "s" ==> 1
            /// Ratcliff-Obershelp = 2*(sum of substrings)/(length of s1 + length of s2)
            ///                    = 2*(4 + 3 + 1) / (9 + 9)
            ///                    = 16/18
            ///                    = 0.888888888888889
            Assert.Equal(
                expected: 0.888888888888889,
                actual: instance.Similarity("My string", "My tsring"),
                precision: 15 /// 0.000000000000001
                );

            /// test data from other algorithms
            /// "My string" vs "My tsring"
            /// Substrings:
            /// "My " ==> 3, "tri" ==> 3, "g" ==> 1
            /// Ratcliff-Obershelp = 2*(sum of substrings)/(length of s1 + length of s2)
            ///                    = 2*(3 + 3 + 1) / (9 + 9)
            ///                    = 14/18
            ///                    = 0.777777777777778
            Assert.Equal(
                expected: 0.777777777777778,
                actual: instance.Similarity("My string", "My ntrisg"),
                precision: 15 /// 0.000000000000001
                );

            /// test data from essay by Ilya Ilyankou
            /// "Comparison of Jaro-Winkler and Ratcliff/Obershelp algorithms
            /// in spell check"
            /// https://ilyankou.files.wordpress.com/2015/06/ib-extended-essay.pdf
            /// p13, expected result is 0.857
            Assert.Equal(
                expected: 0.857,
                actual: instance.Similarity("MATEMATICA", "MATHEMATICS"),
                precision: 3 /// 0.001
                );

            /// test data from stringmetric
            /// https://github.com/rockymadden/stringmetric
            /// expected output is 0.736842105263158
            Assert.Equal(
                expected: 0.736842105263158,
                actual: instance.Similarity("aleksander", "alexandre"),
                precision: 15 /// 0.000000000000001
                );

            /// test data from stringmetric
            /// https://github.com/rockymadden/stringmetric
            /// expected output is 0.666666666666667
            Assert.Equal(
                expected: 0.666666666666667,
                actual: instance.Similarity("pennsylvania", "pencilvaneya"),
                precision: 15 /// 0.000000000000001
                );

            /// test data from wikipedia
            /// https://en.wikipedia.org/wiki/Gestalt_Pattern_Matching
            /// expected output is 14/18 = 0.777777777777778‬
            Assert.Equal(
                expected: 0.777777777777778,
                actual: instance.Similarity("WIKIMEDIA", "WIKIMANIA"),
                precision: 15 /// 0.000000000000001
                );

            /// test data from wikipedia
            /// https://en.wikipedia.org/wiki/Gestalt_Pattern_Matching
            /// expected output is 24/40 = 0.6
            Assert.Equal(
                expected: 0.6,
                actual: instance.Similarity("GESTALT PATTERN MATCHING", "GESTALT PRACTICE"),
                precision: 15 /// 0.000000000000001
                );

            NullEmptyTests.TestSimilarity(instance);
        }