public double GetSimilarPoints(Trip source, Trip other) { double points = 0; // Same tour type if (source.Tour.Type == other.Tour.Type) { points += 75; } // Same start place and/or destination if (Fuzz.PartialRatio(source.Tour.StartPlace, other.Tour.StartPlace) >= 85) { points += 50; } if (Fuzz.PartialRatio(source.Tour.Destination, other.Tour.Destination) >= 85) { points += 50; } // Similar Price points -= Convert.ToDouble(Math.Abs(source.GetSalePrice() - other.GetSalePrice())); // Similar Start Time and End Time points += 25 - (source.StartTime - other.StartTime).TotalDays; points += 25 - (source.EndTime - other.EndTime).TotalDays; // Similar Description points += Fuzz.TokenSetRatio(source.Tour.Description, other.Tour.Description) * .25; return(points); }
public void TestTokenSetRatio() { Assert.AreEqual(Fuzz.TokenSetRatio(_s4, _s5, PreprocessMode.Full), 100); Assert.AreEqual(Fuzz.TokenSetRatio(_s8, _s8A), 100); Assert.AreEqual(Fuzz.TokenSetRatio(_s9, _s9A, PreprocessMode.Full), 100); Assert.AreEqual(Fuzz.TokenSetRatio(_s9, _s9A), 100); Assert.AreEqual(Fuzz.TokenSetRatio(_s10, _s10A), 50); }
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())); } }
static bool mainCheck(string input1, string input2) => (Fuzz.TokenSortRatio(input1, input2) == 100) && (Fuzz.TokenSetRatio(input1, input2) == 100);