コード例 #1
0
        private int matchTitle(string title)
        {
            string otherTitle = title.Equalize();
            int    score      = AdvancedStringComparer.Levenshtein(baseTitle, otherTitle);

            return(score);
        }
コード例 #2
0
        private int matchTitle(string title)
        {
            logger.Debug("Normalize : " + title);
            string otherTitle = title.Equalize();
            int    score      = AdvancedStringComparer.Levenshtein(baseTitle, otherTitle);

            return(score);
        }
コード例 #3
0
        public static int Score(string searchStr, string target)
        {
            int bestScore      = int.MaxValue;
            int position       = 0;
            int lastWhiteSpace = -1;

            searchStr = cleaner.Replace(searchStr, "").ToLower().Trim();
            string cleanTarget = cleaner.Replace(target, "").ToLower().Trim();

            // start off with a full string compare
            bestScore = AdvancedStringComparer.Levenshtein(searchStr, cleanTarget);

            // step through the movie title and try to match substrings of the same length as the search string
            while (position + searchStr.Length <= cleanTarget.Length)
            {
                string targetSubStr = cleanTarget.Substring(position, searchStr.Length);

                // base score
                int currScore = AdvancedStringComparer.Levenshtein(searchStr, targetSubStr);

                // penalty if the match starts mid word
                if (position - lastWhiteSpace > 1)
                {
                    currScore += 1;
                }

                // penalty if the match ends mid word
                int trailingPos = position + searchStr.Length;
                if (trailingPos < cleanTarget.Length)
                {
                    char trailingChar = cleanTarget[trailingPos];
                    if (!char.IsWhiteSpace(trailingChar) && !char.IsPunctuation(trailingChar))
                    {
                        currScore++;
                    }
                }

                // penalty if it is a substring match
                currScore++;

                // store our new score as needed, upate state variables and move on
                if (bestScore > currScore)
                {
                    bestScore = currScore;
                }
                if (targetSubStr.Length > 0 && (char.IsWhiteSpace(targetSubStr[0]) || char.IsPunctuation(targetSubStr[0])))
                {
                    lastWhiteSpace = position;
                }
                position++;
            }

            return(bestScore);
        }
コード例 #4
0
        public override void Execute(Dictionary <string, string> variables)
        {
            if (ScriptSettings.DebugMode)
            {
                logger.Debug("executing distance: " + xmlNode.OuterXml);
            }

            string parsedString1 = parseString(variables, string1);
            string parsedString2 = parseString(variables, string2);

            if (ScriptSettings.DebugMode)
            {
                logger.Debug("executing distance: " + parsedString1 + " vs. " + parsedString2);
            }

            int distance = AdvancedStringComparer.Levenshtein(parsedString1, parsedString2);

            setVariable(variables, parseString(variables, Name), distance.ToString());
        }
コード例 #5
0
        private bool CloseEnough(string title, DBMovieInfo movie)
        {
            int distance;

            distance = AdvancedStringComparer.Levenshtein(title, movie.Title);
            if (distance <= MovingPicturesCore.Settings.AutoApproveThreshold)
            {
                return(true);
            }

            foreach (string currAltTitle in movie.AlternateTitles)
            {
                distance = AdvancedStringComparer.Levenshtein(title, currAltTitle);
                if (distance <= MovingPicturesCore.Settings.AutoApproveThreshold)
                {
                    return(true);
                }
            }

            return(false);
        }