/// <summary>
        /// Returns a value between 0 and 1 how good the matching is.
        /// </summary>
        public double RateBiMatchedLines(SubtitleMatcher.BiMatchedLines biMatchedLines)
        {
            // [shared times between lines from list1 and list2] divided by [whole time]
            // ...because this value is between 0 and 0.5 we have to multiply it with 2

            // calculate "all time"
            double sharedTime      = 0;
            double allTimeSpanTime = 0;

            for (int listIndex = 0; listIndex < 2; listIndex++)
            {
                foreach (var currentLine in biMatchedLines.listlines[listIndex])
                {
                    allTimeSpanTime += UtilsCommon.GetTimeSpanLength(currentLine);
                }
            }

            // calculate "shared time"
            foreach (var lineInfoA in biMatchedLines.listlines[0])
            {
                foreach (var lineInfoB in biMatchedLines.listlines[1])
                {
                    sharedTime += UtilsCommon.OverlappingTimeSpan(lineInfoA, lineInfoB);
                }
            }

            return((sharedTime * 2) / allTimeSpanTime);
        }
Beispiel #2
0
        /// <summary>
        /// Score for overlapping of two subtitles between 0 and 1.
        ///
        /// Corner cases:
        ///     subtitles do not overlap -> 0
        ///     subtitles fully overlap -> 1
        /// </summary>
        /// <returns>The score.</returns>
        /// <param name="a">The alpha component.</param>
        /// <param name="b">The blue component.</param>
        public static double OverlappingScore(ITimeSpan a, ITimeSpan b)
        {
            double overlappingSpan = UtilsCommon.OverlappingTimeSpan(a, b);
            double line1timeSpan   = a.EndTime - a.StartTime;
            double line2timeSpan   = b.EndTime - b.StartTime;

            // ignore matchings if there is next to no overlapping
            double line1score = (double)overlappingSpan / (double)line1timeSpan;
            double line2score = (double)overlappingSpan / (double)line2timeSpan;

            return((line1score + line2score) * 0.5f);
        }