Example #1
0
        private static float GetMatch(Movie movie, AnalyzedItem item)
        {
            float res = 0;

            var   dtt    = LevenshteinDistance.ComputeIgnoreCase(item.Title, movie.Title);
            var   dto    = LevenshteinDistance.ComputeIgnoreCase(item.Title, movie.OriginalTitle);
            float score1 = Math.Max(0, 5 - Math.Min(dtt, dto));

            res += score1;

            //if (string.Equals(item.Title, movie.Title, StringComparison.OrdinalIgnoreCase)
            //    || string.Equals(item.Title, movie.OriginalTitle, StringComparison.OrdinalIgnoreCase))
            //{
            //    res += 3;
            //}

            if (!string.IsNullOrEmpty(item.SubTitle))
            {
                var   dst    = LevenshteinDistance.ComputeIgnoreCase(item.SubTitle, movie.Title);
                var   dso    = LevenshteinDistance.ComputeIgnoreCase(item.SubTitle, movie.OriginalTitle);
                float score2 = Math.Max(0, 3 - Math.Min(dst, dso));
                res += score2;
            }

            //if (string.Equals(item.SubTitle, movie.Title, StringComparison.OrdinalIgnoreCase)
            //    || string.Equals(item.SubTitle, movie.OriginalTitle, StringComparison.OrdinalIgnoreCase))
            //{
            //    res += 2;
            //}

            if (LooksLike(item.Year, movie.ReleaseDate))
            {
                res += 3;
            }


            if (item.Duration > TimeSpan.Zero && movie.Runtime.HasValue)
            {
                var mtime = TimeSpan.FromMinutes(movie.Runtime.Value);
                var diff  = Math.Abs(item.Duration.Subtract(mtime).TotalMinutes);
                var score = (int)Math.Max(5 - diff, 0);
                {
                    res += score;
                }
            }
            else
            {
                res += 1;
            }

            return(res / 16);
        }
 public int ComputeIgnoreCase_test(string a, string b)
 {
     return(LevenshteinDistance.ComputeIgnoreCase(a, b));
 }