Ejemplo n.º 1
0
        public void ZeroLengthInputs()
        {
            List <int> result   = FuzzyMatching.FindBestFuzzyMatch(string.Empty, string.Empty);
            List <int> expected = new List <int>();

            Assert.IsTrue(IsEqual(expected, result));
        }
Ejemplo n.º 2
0
        public void NoResult()
        {
            List <int> result   = FuzzyMatching.FindBestFuzzyMatch("what is going on?", "whatsx goin on?");
            List <int> expected = new List <int>();

            Assert.IsTrue(IsEqual(expected, result));
        }
Ejemplo n.º 3
0
        public void ZeroLengthSearchString()
        {
            List <int> result   = FuzzyMatching.FindBestFuzzyMatch("whatsapp hellow", string.Empty);
            List <int> expected = new List <int>();

            Assert.IsTrue(IsEqual(expected, result));
        }
Ejemplo n.º 4
0
        public void ZeroLengthInputs()
        {
            List <int> result   = FuzzyMatching.FindBestFuzzyMatch("", "");
            List <int> expected = new List <int>();

            Assert.IsTrue(FuzzyMatchingUnitTest.IsEqual(expected, result));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Search method that matches the title of windows with the user search text
        /// </summary>
        /// <param name="openWindows"></param>
        /// <returns>Returns search results</returns>
        private List <SearchResult> FuzzySearchOpenWindows(List <Window> openWindows)
        {
            List <SearchResult> result        = new List <SearchResult>();
            List <SearchString> searchStrings = new List <SearchString>();

            List <string> shortcuts = SettingsManager.Instance.GetShortcut(SearchText);

            foreach (var shortcut in shortcuts)
            {
                searchStrings.Add(new SearchString(shortcut, SearchResult.SearchType.Shortcut));
            }

            searchStrings.Add(new SearchString(searchText, SearchResult.SearchType.Fuzzy));

            foreach (var searchString in searchStrings)
            {
                foreach (var window in openWindows)
                {
                    var titleMatch   = FuzzyMatching.FindBestFuzzyMatch(window.Title, searchString.SearchText);
                    var processMatch = FuzzyMatching.FindBestFuzzyMatch(window.ProcessName, searchString.SearchText);

                    if ((titleMatch.Count != 0 || processMatch.Count != 0) &&
                        window.Title.Length != 0)
                    {
                        var temp = new SearchResult(window, titleMatch, processMatch, searchString.SearchType);
                        result.Add(temp);
                    }
                }
            }

            System.Diagnostics.Debug.Print("Found " + result.Count + " windows that match the search text");

            return(result);
        }
Ejemplo n.º 6
0
        public void BestScoreTest()
        {
            int score = FuzzyMatching.CalculateScoreForMatches(new List <int>()
            {
                1, 2, 3, 4
            });

            Assert.IsTrue(score == -3);
        }
Ejemplo n.º 7
0
        public void RealWorldProgramManager()
        {
            List <int> result   = FuzzyMatching.FindBestFuzzyMatch("Program Manager", "pr");
            List <int> expected = new List <int>()
            {
                0, 1
            };

            Assert.IsTrue(IsEqual(expected, result));
        }
Ejemplo n.º 8
0
        public void BestMatch()
        {
            List <int> result   = FuzzyMatching.FindBestFuzzyMatch("aaacaab", "ab");
            List <int> expected = new List <int>()
            {
                5, 6
            };

            Assert.IsTrue(IsEqual(expected, result));
        }
Ejemplo n.º 9
0
        public void SimpleMatching()
        {
            List <int> result   = FuzzyMatching.FindBestFuzzyMatch("watsapp hellow", "hello");
            List <int> expected = new List <int>()
            {
                8, 9, 10, 11, 12
            };

            Assert.IsTrue(IsEqual(expected, result));
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Calculates the score for how closely this window matches the search string
 /// </summary>
 /// <remarks>
 /// Higher Score is better
 /// </remarks>
 private void CalculateScore()
 {
     if (FuzzyMatching.CalculateScoreForMatches(SearchMatchesInProcessName) >
         FuzzyMatching.CalculateScoreForMatches(SearchMatchesInTitle))
     {
         Score           = FuzzyMatching.CalculateScoreForMatches(SearchMatchesInProcessName);
         BestScoreSource = TextType.ProcessName;
     }
     else
     {
         Score           = FuzzyMatching.CalculateScoreForMatches(SearchMatchesInTitle);
         BestScoreSource = TextType.WindowTitle;
     }
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Finds the best match (the one with the most
        /// number of letters adjecent to each other) and
        /// returns the index location of each of the letters
        /// of the matches
        /// </summary>
        /// <param name="text">The text to search inside of</param>
        /// <param name="searchText">the text to search for</param>
        /// <returns></returns>
        public static List <int> FindBestFuzzyMatch(string text, string searchText, int searchStartIndex = 0)
        {
            List <int> matchIndexes = new List <int>();

            searchText = searchText.ToLower();
            text       = text.ToLower();

            // Create a grid to march matches like
            // eg.
            //   a b c a d e c f g
            // a x     x
            // c     x       x
            bool[,] matches = new bool[text.Length, searchText.Length];
            for (int firstIndex = 0; firstIndex < text.Length; firstIndex++)
            {
                for (int secondIndex = 0; secondIndex < searchText.Length; secondIndex++)
                {
                    matches[firstIndex, secondIndex] =
                        searchText[secondIndex] == text[firstIndex] ?
                        true :
                        false;
                }
            }

            // use this table to get all the possible matches
            List <List <int> > allMatches = FuzzyMatching.GetAllMatchIndexes(matches);

            // return the score that is the max
            int        maxScore  = allMatches.Count > 0 ? FuzzyMatching.CalculateScoreForMatches(allMatches[0]) : 0;
            List <int> bestMatch = allMatches.Count > 0 ? allMatches[0] : new List <int>();

            foreach (var match in allMatches)
            {
                int score = FuzzyMatching.CalculateScoreForMatches(match);
                if (score > maxScore)
                {
                    bestMatch = match;
                    maxScore  = score;
                }
            }

            return(bestMatch);
        }