Пример #1
0
        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);
            }
        }
Пример #2
0
        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));
            }
        }
Пример #3
0
        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;
        }
Пример #4
0
        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;
        }
Пример #5
0
 public void ShouldReplaceAmpersandWithAnd()
 {
     var similarity = new FuzzyString("bob and bill").Compare(new FuzzyString("bob & bill"));
     Assert.AreEqual(FuzzyString.Resemblance.Identical, similarity);
 }
Пример #6
0
 public void ShouldRecognizeIdenticalStrings()
 {
     var similarity = new FuzzyString("dot net").Compare(new FuzzyString("dot net"));
     Assert.AreEqual(FuzzyString.Resemblance.Identical, similarity);
 }
Пример #7
0
 public void ShouldIgnorePunctuationAndNoiseCharacters()
 {
     var similarity = new FuzzyString("hello world").Compare(new FuzzyString(".+hello-'world_="));
     Assert.AreEqual(FuzzyString.Resemblance.Identical, similarity);
 }
Пример #8
0
 public void ShouldIgnoreCommonWords()
 {
     var similarity = new FuzzyString("the code").Compare(new FuzzyString("a code"));
     Assert.AreEqual(FuzzyString.Resemblance.Identical, similarity);
 }
Пример #9
0
 public void ShouldIdentifyVerySimilarWords()
 {
     var similarity = new FuzzyString("the simpsons").Compare(new FuzzyString("the simsons"));
     Assert.AreEqual(FuzzyString.Resemblance.VerySimilar, similarity);
 }
Пример #10
0
 public void ShouldIdentifySimilarWords()
 {
     var similarity = new FuzzyString("south park").Compare(new FuzzyString("north park"));
     Assert.AreEqual(FuzzyString.Resemblance.Similar, similarity);
 }
Пример #11
0
 public void ShouldIdentifyDifferentWords()
 {
     var similarity = new FuzzyString("will and grace").Compare(new FuzzyString("the sopranos"));
     Assert.AreEqual(FuzzyString.Resemblance.Different, similarity);
 }
Пример #12
0
 public void ShouldBeCaseInsensitive()
 {
     var similarity = new FuzzyString("Dot nEt").Compare(new FuzzyString("dot Net"));
     Assert.AreEqual(FuzzyString.Resemblance.Identical, similarity);
 }