예제 #1
0
        public void UpdateOrderScore(string SearchString)
        {
            int score1 = Fuzz.Ratio(SearchString, CargoCollection.PreciseCargoName);
            int score2 = Fuzz.Ratio(SearchString, CargoCollection.Cargo.CargoName);

            OrderScore = Math.Max(score1, score2);
        }
예제 #2
0
 public void TestEmptyStringsScore0()
 {
     Assert.That(Fuzz.Ratio("test_string", ""), Is.EqualTo(0));
     Assert.That(Fuzz.PartialRatio("test_string", ""), Is.EqualTo(0));
     Assert.That(Fuzz.Ratio("", ""), Is.EqualTo(0));
     Assert.That(Fuzz.PartialRatio("", ""), Is.EqualTo(0));
 }
        public async Task <IActionResult> SubmitAnswer(int qId, string answer)
        {
            Question question = await _context.Questions.Include(q => q.QuestionCategory).FirstOrDefaultAsync(q => q.QuestionId == qId);

            string stored = question.Answer.ToLower();
            string input  = answer.ToLower().Trim();

            //Check for number vs word digit representation match by converting number to word.
            if (int.TryParse(stored, out int numStored))
            {
                stored = numStored.ToWords();
            }

            if (int.TryParse(input, out int inputStored))
            {
                input = inputStored.ToWords();
            }

            //Perform fuzzy matching using Levenshtein distance and consider 90% match a success
            int  ratio   = Fuzz.Ratio(stored, input);
            bool success = ratio >= 90;

            if (success)
            {
                CurrentScore       += question.QuestionCategory.ScoreWeight;
                _currentUser.Money += question.QuestionCategory.ScoreWeight;

                _context.Entry(_currentUser).State = EntityState.Modified;
                await _context.SaveChangesAsync();

                Visited.Add(qId);
            }

            return(Json(new { success, currentScore = CurrentScore }));
        }
        private int FuzzyMatchAPIName(string apiName, string name)
        {
            Regex  rgx           = new Regex("[^a-zA-Z ]");
            string processedName = string.Concat("achievement_", rgx.Replace(name, "").Replace(" ", "_").ToLower());

            return(Fuzz.Ratio(apiName, processedName));
        }
예제 #5
0
        public void TestRatioUnicodeString()
        {
            _s1 = "\u00C1";
            _s2 = "ABCD";
            var score = Fuzz.Ratio(_s1, _s2);

            Assert.AreEqual(0, score);
        }
예제 #6
0
        public void Evaluate()
        {
            var a1 = Fuzz.Ratio("mysmilarstring", "myawfullysimilarstirng");
            var a2 = Fuzz.Ratio("mysmilarstring", "mysimilarstring");

            var b1 = Fuzz.PartialRatio("similar", "somewhresimlrbetweenthisstring");

            var c1 = Fuzz.TokenSortRatio("order words out of", "  words out of order");
            var c2 = Fuzz.PartialTokenSortRatio("order words out of", "  words out of order");

            var d1 = Fuzz.TokenSetRatio("fuzzy was a bear", "fuzzy fuzzy fuzzy bear");
            var d2 = Fuzz.PartialTokenSetRatio("fuzzy was a bear", "fuzzy fuzzy fuzzy bear");

            var e1 = Fuzz.WeightedRatio("The quick brown fox jimps ofver the small lazy dog", "the quick brown fox jumps over the small lazy dog");

            var f1 = Fuzz.TokenInitialismRatio("NASA", "National Aeronautics and Space Administration");
            var f2 = Fuzz.TokenInitialismRatio("NASA", "National Aeronautics Space Administration");

            var f3 = Fuzz.TokenInitialismRatio("NASA", "National Aeronautics Space Administration, Kennedy Space Center, Cape Canaveral, Florida 32899");
            var f4 = Fuzz.PartialTokenInitialismRatio("NASA", "National Aeronautics Space Administration, Kennedy Space Center, Cape Canaveral, Florida 32899");

            var g1 = Fuzz.TokenAbbreviationRatio("bl 420", "Baseline section 420", PreprocessMode.Full);
            var g2 = Fuzz.PartialTokenAbbreviationRatio("bl 420", "Baseline section 420", PreprocessMode.Full);



            var h1 = Process.ExtractOne("cowboys", new[] { "Atlanta Falcons", "New York Jets", "New York Giants", "Dallas Cowboys" });
            var h2 = string.Join(", ", Process.ExtractTop("goolge", new[] { "google", "bing", "facebook", "linkedin", "twitter", "googleplus", "bingnews", "plexoogl" }, limit: 3));
            var h3 = string.Join(", ", Process.ExtractAll("goolge", new [] { "google", "bing", "facebook", "linkedin", "twitter", "googleplus", "bingnews", "plexoogl" }));
            var h4 = string.Join(", ", Process.ExtractAll("goolge", new[] { "google", "bing", "facebook", "linkedin", "twitter", "googleplus", "bingnews", "plexoogl" }, cutoff: 40));
            var h5 = string.Join(", ", Process.ExtractSorted("goolge", new [] { "google", "bing", "facebook", "linkedin", "twitter", "googleplus", "bingnews", "plexoogl" }));

            var i1 = Process.ExtractOne("cowboys", new[] { "Atlanta Falcons", "New York Jets", "New York Giants", "Dallas Cowboys" }, s => s, ScorerCache.Get <DefaultRatioScorer>());

            var events = new[]
            {
                new[] { "chicago cubs vs new york mets", "CitiField", "2011-05-11", "8pm" },
                new[] { "new york yankees vs boston red sox", "Fenway Park", "2011-05-11", "8pm" },
                new[] { "atlanta braves vs pittsburgh pirates", "PNC Park", "2011-05-11", "8pm" },
            };
            var query = new[] { "new york mets vs chicago cubs", "CitiField", "2017-03-19", "8pm" };

            var best = Process.ExtractOne(query, events, strings => strings[0]);

            var ratio                    = ScorerCache.Get <DefaultRatioScorer>();
            var partial                  = ScorerCache.Get <PartialRatioScorer>();
            var tokenSet                 = ScorerCache.Get <TokenSetScorer>();
            var partialTokenSet          = ScorerCache.Get <PartialTokenSetScorer>();
            var tokenSort                = ScorerCache.Get <TokenSortScorer>();
            var partialTokenSort         = ScorerCache.Get <PartialTokenSortScorer>();
            var tokenAbbreviation        = ScorerCache.Get <TokenAbbreviationScorer>();
            var partialTokenAbbreviation = ScorerCache.Get <PartialTokenAbbreviationScorer>();
            var weighted                 = ScorerCache.Get <WeightedRatioScorer>();
        }
예제 #7
0
        public static void searchPkgList(string searchQuery)
        {
            var client = new WebClient();

            Console.WriteLine("\n-- Updating packagelist...");
            client.DownloadFile("https://hexpm-installer-script-mirrors.crazywillbear.repl.co/packagelist.txt", @"C:\Users\" + Environment.UserName + @"\AppData\Roaming\HexPM\packagelist.txt");
            Console.WriteLine("     (Updated packagelist)");
            Console.WriteLine("-- Searching packagelist for: " + searchQuery);
            string[] text = File.ReadAllLines(@"C:\Users\" + Environment.UserName + @"\AppData\Roaming\HexPM\packagelist.txt");
            for (int i = 0; i < text.Length; i++)
            {
                if (Fuzz.Ratio(searchQuery.ToLower(), text[i].Split(';')[0].ToLower()) >= 65)
                {
                    Console.WriteLine("     (Found: " + text[i].Split(';')[0] + ")");
                }
            }
        }
예제 #8
0
        public override double Score(string input1, string input2)
        {
            int len1 = input1.Length;
            int len2 = input2.Length;

            if (len1 == 0 || len2 == 0)
            {
                return(0);
            }

            bool   tryPartials  = TRY_PARTIALS;
            double unbaseScale  = UNBASE_SCALE;
            double partialScale = PARTIAL_SCALE;

            double baseRatio = Fuzz.Ratio(input1, input2);
            double lenRatio  = ((double)Math.Max(len1, len2)) / Math.Min(len1, len2);

            // if strings are similar length don't use partials
            if (lenRatio < 1.5)
            {
                tryPartials = false;
            }

            // if one string is much shorter than the other
            if (lenRatio > 8)
            {
                partialScale = .6;
            }

            if (tryPartials)
            {
                double partial    = Fuzz.PartialRatio(input1, input2) * partialScale;
                double partialSor = Fuzz.TokenSortRatio(input1, input2) * unbaseScale * partialScale;
                double partialSet = Fuzz.TokenSetRatio(input1, input2) * unbaseScale * partialScale;

                return((double)Math.Round(new[] { baseRatio, partial, partialSor, partialSet }.Max()));
            }
            else
            {
                double tokenSort = Fuzz.TokenSortRatio(input1, input2) * unbaseScale;
                double tokenSet  = Fuzz.TokenSetRatio(input1, input2) * unbaseScale;

                return((double)Math.Round(new[] { baseRatio, tokenSort, tokenSet }.Max()));
            }
        }
예제 #9
0
        public List <int> searchByNickname(string nickname = "")
        {
            var foundAccountsIndexes = new List <int>();

            if (nickname != "")
            {
                for (int i = 0; i < accounts.Count; i++)
                {
                    if (accounts[i].nickname.ToLower().StartsWith(nickname) ||
                        Fuzz.Ratio(nickname.ToLower(), accounts[i].nickname.ToLower()) > 40)
                    {
                        foundAccountsIndexes.Add(i);
                    }
                }
            }
            else
            {
                for (int i = 0; i < accounts.Count; i++)
                {
                    foundAccountsIndexes.Add(i);
                }
            }
            return(foundAccountsIndexes);

            /*if (nickname != "")
             * {
             *  var foundAccounts = new List<Account>(); ;
             *  foreach (var account in accounts)
             *      if (account.nickname.ToLower().StartsWith(nickname) ||
             *          Fuzz.Ratio(nickname.ToLower(),
             *                     account.nickname.ToLower()
             *                     ) > 50)
             *      {
             *          foundAccounts.Add(account);
             *      }
             *  return foundAccounts;
             * }
             * else
             * {
             *  return accounts;
             * }*/
        }
예제 #10
0
        public int SimpleRatio(string input1, string input2)
        {
            var f = Fuzz.Ratio(input1, input2);

            return(f);
        }
예제 #11
0
 public void Test_Case_Insensitive()
 {
     Assert.AreNotEqual(Fuzz.Ratio(_s1, _s2), 100);
     Assert.AreEqual(Fuzz.Ratio(_s1, _s2, PreprocessMode.Full), 100);
 }
예제 #12
0
 public void Test_Equal()
 {
     Assert.AreEqual(Fuzz.Ratio(_s1, _s1A), 100);
     Assert.AreEqual(Fuzz.Ratio(_s8, _s8A), 100);
     Assert.AreEqual(Fuzz.Ratio(_s9, _s9A), 100);
 }
예제 #13
0
 public void TestEmptyStringsScore100()
 {
     Assert.AreEqual(Fuzz.Ratio("", ""), 100);
     Assert.AreEqual(Fuzz.PartialRatio("", ""), 100);
 }
예제 #14
0
        public static void GuessCommand(this CommandContext context, string query)
        {
            var searchedCommands = context.CommandsNext.RegisteredCommands.Values
                                   .SelectMany(FlattenCommand)
                                   .Select(y => new { name = y.QualifiedName, score = Fuzz.Ratio(y.QualifiedName, query) });

            var bestGuess = searchedCommands
                            .OrderBy(y => y.score)
                            .Last();

            if (bestGuess.score < 60)
            {
                bestGuess = null;
            }

            if (bestGuess != null)
            {
                context.RespondAsync(
                    $"Could not find command `{query}`. Did you mean `{bestGuess.name}`?"
                    );
            }
            else
            {
                context.RespondAsync($"Could not find command `{query}`.");
            }
        }
예제 #15
0
        public void GetStringDifferenceRatio(string text, string toCompareText, int expectedDistance)
        {
            var ratio = Fuzz.Ratio(text, toCompareText);

            Assert.True(ratio == expectedDistance);
        }
        private int FuzzyMatchImageName(string imageName, string name)
        {
            string decodedName = imageName.Replace("_", " ").Substring(0, imageName.Length - 4);

            return(Fuzz.Ratio(decodedName, name));
        }