Example #1
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>();
        }
        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()));
            }
        }
Example #3
0
 public void TestTokenSortRatio()
 {
     Assert.AreEqual(Fuzz.TokenSortRatio(_s1, _s1A), 100);
 }
 static bool mainCheck(string input1, string input2)
 => (Fuzz.TokenSortRatio(input1, input2) == 100) && (Fuzz.TokenSetRatio(input1, input2) == 100);