public void GetBestMatchesTest1()
        {
            var prude       = "prude";
            var bestMatches = TestUtilities.DictionaryWords.Select(w => FuzzyMatcher.FuzzyMatch(w, prude)).GetBestMatches();

            Assert.IsTrue(bestMatches.Length == 1);
        }
        public void GetBestMatchesTest2()
        {
            var falcie      = "fal";
            var bestMatches = TestUtilities.DictionaryWords.Select(w => FuzzyMatcher.FuzzyMatch(w, falcie)).GetBestMatches();

            Assert.IsTrue(bestMatches.Length == 8);
        }
예제 #3
0
        private static void TestFuzzyMatch(string desiredItem, string notDesiredItem, string searchText)
        {
            (bool isMatch, int score)desiredItemResult    = FuzzyMatcher.FuzzyMatch(desiredItem, searchText);
            (bool isMatch, int score)notDesiredItemResult = FuzzyMatcher.FuzzyMatch(notDesiredItem, searchText);

            desiredItemResult.score.Should().BeGreaterThan(notDesiredItemResult.score);
        }
예제 #4
0
        public void FuzzyMatchWordsWithPartialSpellingTest()
        {
            var facility = TestUtilities.DictionaryWords[133956];
            var facilityPartialSpellingMatchTest = FuzzyMatcher.FuzzyMatch(facility, "failt");

            Assert.IsTrue(facilityPartialSpellingMatchTest.DidMatch);
            Assert.IsTrue(facilityPartialSpellingMatchTest.Score == 15);
        }
예제 #5
0
        public void FuzzyMatchWithScoreTest()
        {
            var match = FuzzyMatcher.FuzzyMatch(ReferenceString, ReferencePattern);

            Assert.IsInstanceOf <FuzzyMatchResult>(match);
            Assert.IsTrue(match.DidMatch);
            Assert.AreEqual(-16, match.Score);
        }
예제 #6
0
        public void FuzzyMatchWithNoMatchAndSubZeroScoreTest()
        {
            var faciobrachial = TestUtilities.DictionaryWords[133963];
            var test          = FuzzyMatcher.FuzzyMatch(faciobrachial, "yt");

            Assert.IsFalse(test.DidMatch);
            Assert.IsTrue(test.Score == -13);
        }
예제 #7
0
        public void FuzzyMatchWorks_Basic()
        {
            (bool isMatch, int score)goodResult = FuzzyMatcher.FuzzyMatch("Reilly Wood", "rei");
            Assert.True(goodResult.isMatch);

            (bool isMatch, int score)badResult = FuzzyMatcher.FuzzyMatch("Reilly Wood", "xcv");
            Assert.False(badResult.isMatch);

            Assert.True(goodResult.score > badResult.score);
        }
예제 #8
0
        public void FuzzyMatchUsingLinqTest1()
        {
            var results = TestUtilities.DictionaryWords
                          .Select(w => FuzzyMatcher.FuzzyMatch(w, "fal"))
                          .Where(r => r.DidMatch)
                          .ToList();

            Assert.IsNotEmpty(results);
            Assert.IsTrue(results.Count == 4956);
        }
예제 #9
0
        public void FuzzyMatchDidNotMatchButScoreAboveZeroTest()
        {
            var plantaginaceae = TestUtilities.DictionaryWords[300001];

            var test = FuzzyMatcher.FuzzyMatch(plantaginaceae, "planet", true);

            Assert.IsFalse(test.DidMatch);
            Assert.IsTrue(test.MatchedIndices.Length == 5);
            Assert.IsTrue(test.Score > 0);
            Assert.IsTrue(test.Score == 17);
        }
예제 #10
0
        public void FuzzyMatchFormattedNonConsecutiveStringTest()
        {
            var nescience = TestUtilities.DictionaryWords[252662];

            var test = FuzzyMatcher.FuzzyMatch(stringToSearch: nescience,
                                               pattern: "neie",
                                               formatString: true);

            Assert.IsTrue(test.DidMatch);
            Assert.IsTrue(test.Score == 16);
            Assert.IsNotEmpty(test.FormattedString);
        }
예제 #11
0
        public void FuzzyMatchFormattedConsecutiveStringTest()
        {
            var nescience = TestUtilities.DictionaryWords[252662];

            var test = FuzzyMatcher.FuzzyMatch(stringToSearch: nescience,
                                               pattern: "nes",
                                               formatString: true);

            Assert.IsTrue(test.DidMatch);
            Assert.IsTrue(test.Score == 15);
            Assert.IsTrue(test.FormattedString.Length > test.OriginalString.Length);
        }
        public void GetBestMatchTest()
        {
            var corvus       = "corvus";
            var matchResults = TestUtilities.DictionaryWords.Select(w => FuzzyMatcher.FuzzyMatch(w, corvus));
            var bestMatch    = matchResults.GetBestMatch();

            Assert.IsNotNull(bestMatch);
            Assert.IsInstanceOf <FuzzyMatchResult>(bestMatch);

            Assert.IsTrue(bestMatch.DidMatch);
            Assert.IsTrue(bestMatch.MatchedIndices.Length == corvus.Length);
        }
예제 #13
0
        public void FuzzyMatcherUsingLinqTest2()
        {
            var results = TestUtilities
                          .DictionaryWords
                          .Select(w => FuzzyMatcher.FuzzyMatch(w, "involute", true))
                          .Where(r => r.DidMatch || r.Score > 0)
                          .ToList();

            Assert.IsNotEmpty(results);
            Assert.IsTrue(results.Count == 13839);

            var didMatch = results.Where(r => r.DidMatch).ToList();

            Assert.IsNotEmpty(didMatch);
            Assert.IsTrue(didMatch.Count == 16);
        }
예제 #14
0
    void OnInputChanged(string searchString)
    {
        autocompleteSearchField.ClearResults();
        matches.Clear();
        if (!string.IsNullOrEmpty(searchString.Trim(' ', '\t', '\n')))
        {
            int score = 0;
            int count = 0;

            foreach (var searchPath in searchPaths)
            {
                if (FuzzyMatcher.FuzzyMatch(searchPath, searchString, out score))
                {
                    matches.Add(new SearchMatch()
                    {
                        searchPath  = searchPath,
                        searchValue = mapSearchObject.ContainsKey(searchPath) ? mapSearchObject[searchPath] : null,
                        score       = score
                    });
                    count++;
                    if (count > 90)
                    {
                        break;
                    }
                }
            }

            matches.Sort((m1, m2) => m2.score.CompareTo(m1.score));
            for (var i = 0; i < Mathf.Min(matches.Count, autocompleteSearchField.maxResults); i++)
            {
                autocompleteSearchField.AddResult(matches[i].searchPath, null);
            }
        }
        else
        {
            int count = 0;
            foreach (var searchPath in searchPaths)
            {
                autocompleteSearchField.AddResult(searchPath, null);
                count++;
                if (count > 20)
                {
                    break;
                }
            }
        }
    }
예제 #15
0
        private static float InstanceBenchmark(int iterations = 10, bool formatString = false, bool includeOriginal = true)
        {
            var instanceResult = new float[iterations];
            var words          = TestUtilities.DictionaryWords;

            for (int i = 0; i < iterations; i++)
            {
                var stopWatch2 = new Stopwatch();
                stopWatch2.Start();

                var instance = new FuzzyMatcher(words);
                var results  = instance.FuzzyMatch("corvus", formatString, includeOriginal);

                stopWatch2.Stop();
                Debug.WriteLine($"Time for iteration {i + 1}: {stopWatch2.ElapsedMilliseconds}");
                instanceResult[i] = stopWatch2.ElapsedMilliseconds;
            }

            return(instanceResult.Average());
        }
예제 #16
0
        private static float LinqBenchmark(int iterations = 10, bool formatString = false, bool includeOriginal = true)
        {
            var linqResults = new float[iterations];
            var words       = TestUtilities.DictionaryWords;

            for (int i = 0; i < iterations; i++)
            {
                var stopWatch1 = new Stopwatch();
                stopWatch1.Start();

                var linqWay = words.Select(w => FuzzyMatcher.FuzzyMatch(w, "corvus", formatString, includeOriginal))
                              .Where(r => r.DidMatch).ToList();

                stopWatch1.Stop();
                Debug.WriteLine($"Time for iteration {i + 1}: {stopWatch1.ElapsedMilliseconds}");

                linqResults[i] = stopWatch1.ElapsedMilliseconds;
            }

            return(linqResults.Average());
        }
예제 #17
0
        private void UpdateSearchResult(string searchString)
        {
            if (searchString == "" || searchString == "Rechercher...")
            {
                ProductsView = new ObservableCollection <Product>(fullProductList as Collection <Product>);
                return;
            }
            //TO DO : voir LINQ
            var list = fullProductList.Where(item => FuzzyMatcher.FuzzyMatch(item.Name, searchString)).ToList();
            ObservableCollection <Product> filteredList;

            if (list == null)
            {
                filteredList = new ObservableCollection <Product>();
            }
            else
            {
                filteredList = new ObservableCollection <Product>(list);
            }

            ProductsView = filteredList;
        }
예제 #18
0
        public void FuzzyMatchFormattedWithCustomFormatterFuncTest()
        {
            var plantagenet = TestUtilities.DictionaryWords[300000];

            Func <string, IEnumerable <int>, string> formatterFunc = (str, indices) =>
            {
                var insertedCount = 0;
                return(indices.Aggregate(str, (theStr, theIndex) => theStr.Insert(theIndex + (insertedCount++), "(")
                                         .Insert(theIndex + (insertedCount++) + 1, ")")));
            };

            var test = FuzzyMatcher.FuzzyMatch(stringToSearch: plantagenet,
                                               pattern: "planet",
                                               formatterFunc: formatterFunc);

            Assert.IsTrue(test.DidMatch);
            Assert.IsTrue(test.Score == 25);
            Assert.IsTrue(test.MatchedIndices.Length == 6);
            var parenthesesCount = test.FormattedString.Count(c => c == '(' || c == ')');

            Assert.IsTrue(parenthesesCount == 12);
        }
예제 #19
0
        public async Task FilterItems(string filterString)
        {
            Stopwatch sw = Stopwatch.StartNew();

            if (!string.IsNullOrEmpty(filterString))
            {
                ObservableCollection <LibraryItem> filteredItems = await Task.Run(() => FuzzyMatcher.FuzzyMatch(filterString, LibraryItems));

                _logger.Information("Fuzzy match time: {ElapsedMs}", sw.ElapsedMilliseconds);

                VisibleItems = filteredItems;
            }
            else
            {
                SetVisibleItemsToDefaultSortedAllLibraryItems();
            }

            _logger.Information("Total filter time: {ElapsedMs}", sw.ElapsedMilliseconds);
        }