Exemple #1
0
        public void WordLevensteinAlgorithm_ShouldWork_CustomCharacterSimiarityResolver()
        {
            var resolver = new CharacterSimilarityResolverDefault(null, StringComparisonOptions.CaseSensitive);

            resolver.SetMistakeSimilarity('m', 'n', 0.8f);
            resolver.SetMistakeSimilarity('o', 'u', 0.7f);
            resolver.SetMistakeSimilarity('i', 'y', 0.8f);
            resolver.SetMistakeSimilarity('c', 'k', 0.6f);

            resolver.SetMistakeSimilarity('X', 'A', 0.9f);

            var algorithm = new LevensteinAlgorithm <Word, char>(resolver);

            AreSimilar(algorithm, "XXXXX", "AAAAA");
            NotSimilar(algorithm, "xxxxx", "aaaaa");


            AreSimilar(algorithm, "Mehran", "Nehran");
            NotSimilar(algorithm, "MEHRAN", "mehran");
            AreSimilar(algorithm, "Afshin", "Aphshin");
            AreSimilar(algorithm, "Mehran", "Nahran");
            AreSimilar(algorithm, "Monica", "Monika");
            AreSimilar(algorithm, "Nonica", "Nomika");
            AreSimilar(algorithm, "Crespo", "Krespo");
            NotSimilar(algorithm, "Mehran", "RamMeh");
            NotSimilar(algorithm, "Penalty", "People");


            AreSimilar(algorithm, "Monica", "Numyka");
            NotSimilar(algorithm, "Monica", "NUmYkA");
        }
        public void CharacterMistakeBased_ShouldWork_NotCaseSensitive()
        {
            var simila = new CharacterSimilarityResolverDefault(null, StringComparisonOptions.None);

            Assert.AreEqual(simila.GetSimilarity('a', 'a'), 1);
            Assert.AreEqual(simila.GetSimilarity('A', 'a'), 1);
            Assert.AreEqual(simila.GetSimilarity('a', 'A'), 1);

            Assert.AreEqual(simila.GetSimilarity('a', 'b'), 0);
            Assert.AreEqual(simila.GetSimilarity('a', 'B'), 0);
        }
        public void CharacterMistakeBased_ShouldWork_Raw_CaseSensitive()
        {
            var simila = new CharacterSimilarityResolverDefault(null, StringComparisonOptions.CaseSensitive);

            Assert.AreEqual(1, simila.GetSimilarity('a', 'a'), "'a', 'a'");
            Assert.AreEqual(0, simila.GetSimilarity('A', 'a'), "'A', 'a'");
            Assert.AreEqual(0, simila.GetSimilarity('a', 'A'), "'a', 'A'");

            Assert.AreEqual(0, simila.GetSimilarity('a', 'b'), "'a', 'b'");
            Assert.AreEqual(0, simila.GetSimilarity('a', 'B'), "'a', 'B'");
            Assert.AreEqual(0, simila.GetSimilarity('c', 'k'), "'c', 'k'");
        }
        public void CharacterMistakeBased_ShouldWork_WithEmptyAndNumericInputs()
        {
            var simila = new CharacterSimilarityResolverDefault(null, StringComparisonOptions.None)
            {
                CostOfNumeric = 0.3f
            };

            Assert.AreEqual(0f, simila.GetSimilarity('c', 'k'));
            Assert.AreEqual(0f, simila.GetSimilarity(default(char), 'k'));
            Assert.AreEqual(0f, simila.GetSimilarity('k', default(char)));
            Assert.AreEqual(0.3f, simila.GetSimilarity('3', default(char)));
            Assert.AreEqual(0.3f, simila.GetSimilarity(default(char), '4'));
        }
Exemple #5
0
        public void WordLevensteinAlgorithm_ShouldWork_CustomCharacterSimiarityResolver_NotCaseSensitive()
        {
            var resolver = new CharacterSimilarityResolverDefault(null, StringComparisonOptions.None);

            resolver.SetMistakeSimilarity('m', 'n', 0.8f);
            resolver.SetMistakeSimilarity('o', 'u', 0.7f);
            resolver.SetMistakeSimilarity('i', 'y', 0.8f);
            resolver.SetMistakeSimilarity('c', 'k', 0.6f);
            resolver.SetMistakeSimilarity('X', 'A', 0.9f);

            var algorithm = new LevensteinAlgorithm <Word, char>(resolver);

            AreSimilar(algorithm, "XXXXX", "AAAAA");
            AreSimilar(algorithm, "xxxxx", "aaaaa");

            AreSimilar(algorithm, "Monica", "Numyka");
            AreSimilar(algorithm, "Monica", "NUmYkA");
        }
        public void CharacterMistakeBased_ShouldWork_DefinedMistakes_NotCaseSensitive()
        {
            var simila = new CharacterSimilarityResolverDefault(null, StringComparisonOptions.None);

            simila.SetMistakeSimilarity('c', 'k', 0.7f);


            Assert.AreEqual(0, simila.GetSimilarity('a', 'b'));
            Assert.AreEqual(0, simila.GetSimilarity('a', 'B'));

            Assert.AreEqual(0.7f, simila.GetSimilarity('c', 'k'));
            Assert.AreEqual(0.7f, simila.GetSimilarity('k', 'c'));

            Assert.AreEqual(0.7f, simila.GetSimilarity('c', 'K'));
            Assert.AreEqual(0.7f, simila.GetSimilarity('K', 'c'));

            Assert.AreEqual(0.7f, simila.GetSimilarity('C', 'k'));
            Assert.AreEqual(0.7f, simila.GetSimilarity('k', 'C'));
        }