private void IdentifyShow(File file, FuzzyString showName, int keywordWeight, Keywords keywords) { var shows = this.Database.GetShows(); var showMatches = shows.Select(s => new WeightedGuess<Show>(s, s.Name.GetSimilarity(showName)) ) .Where(s => s.Weight >= (int) FuzzyString.Resemblance.VerySimilar); foreach (var entry in showMatches) { entry.Weight *= keywordWeight; file.ShowMatches.Add(entry); } }
private void AddKeyword(string word, int weight) { var fuzzy = new FuzzyString(word); var existing = this.List.FirstOrDefault(k => k.Guess.Compare(fuzzy) >= FuzzyString.Resemblance.VerySimilar); if (existing != null) { existing.Weight += weight; } else { this.List.Add(new WeightedGuess<FuzzyString>(fuzzy, weight)); } }
public int GetSimilarity(FuzzyString other) { var key = new StringPair(this.CleanString, other.CleanString); int value; if (!CachedComparisons.TryGetValue(key, out value)) { var similarity = SiftStringSimilarity.StringMetrics.SiftSimilarity(this.CleanString, other.CleanString); value = (int)(similarity * 100); CachedComparisons.Add(key, value); } return value; }
public Resemblance Compare(FuzzyString other) { var similarity = GetSimilarity(other); if (similarity == (int)Resemblance.Identical) { return Resemblance.Identical; } if (similarity >= (int)Resemblance.VerySimilar) { return Resemblance.VerySimilar; } if (similarity >= (int)Resemblance.Similar) { return Resemblance.Similar; } return Resemblance.Different; }
public void ShouldReplaceAmpersandWithAnd() { var similarity = new FuzzyString("bob and bill").Compare(new FuzzyString("bob & bill")); Assert.AreEqual(FuzzyString.Resemblance.Identical, similarity); }
public void ShouldRecognizeIdenticalStrings() { var similarity = new FuzzyString("dot net").Compare(new FuzzyString("dot net")); Assert.AreEqual(FuzzyString.Resemblance.Identical, similarity); }
public void ShouldIgnorePunctuationAndNoiseCharacters() { var similarity = new FuzzyString("hello world").Compare(new FuzzyString(".+hello-'world_=")); Assert.AreEqual(FuzzyString.Resemblance.Identical, similarity); }
public void ShouldIgnoreCommonWords() { var similarity = new FuzzyString("the code").Compare(new FuzzyString("a code")); Assert.AreEqual(FuzzyString.Resemblance.Identical, similarity); }
public void ShouldIdentifyVerySimilarWords() { var similarity = new FuzzyString("the simpsons").Compare(new FuzzyString("the simsons")); Assert.AreEqual(FuzzyString.Resemblance.VerySimilar, similarity); }
public void ShouldIdentifySimilarWords() { var similarity = new FuzzyString("south park").Compare(new FuzzyString("north park")); Assert.AreEqual(FuzzyString.Resemblance.Similar, similarity); }
public void ShouldIdentifyDifferentWords() { var similarity = new FuzzyString("will and grace").Compare(new FuzzyString("the sopranos")); Assert.AreEqual(FuzzyString.Resemblance.Different, similarity); }
public void ShouldBeCaseInsensitive() { var similarity = new FuzzyString("Dot nEt").Compare(new FuzzyString("dot Net")); Assert.AreEqual(FuzzyString.Resemblance.Identical, similarity); }