From 173d5e95c6adc91707ed66057bd8c7c15ac490db Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sat, 9 Mar 2013 12:29:49 +0000 Subject: [PATCH] * fix series detection regression issues --- .../sourceforge/filebot/media/MediaDetection.java | 2 +- .../filebot/similarity/CommonSequenceMatcher.java | 13 ++++++++++--- .../filebot/similarity/SequenceMatchSimilarity.java | 2 +- .../filebot/similarity/SeriesNameMatcher.java | 2 +- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/source/net/sourceforge/filebot/media/MediaDetection.java b/source/net/sourceforge/filebot/media/MediaDetection.java index 95fa0f0f..899ab3f1 100644 --- a/source/net/sourceforge/filebot/media/MediaDetection.java +++ b/source/net/sourceforge/filebot/media/MediaDetection.java @@ -826,7 +826,7 @@ public class MediaDetection { public HighPerformanceMatcher(int maxStartIndex) { - super(collator, maxStartIndex); + super(collator, maxStartIndex, true); } diff --git a/source/net/sourceforge/filebot/similarity/CommonSequenceMatcher.java b/source/net/sourceforge/filebot/similarity/CommonSequenceMatcher.java index 9fce86a3..3b865d0e 100644 --- a/source/net/sourceforge/filebot/similarity/CommonSequenceMatcher.java +++ b/source/net/sourceforge/filebot/similarity/CommonSequenceMatcher.java @@ -24,11 +24,13 @@ public class CommonSequenceMatcher { protected final Collator collator; protected final int commonSequenceMaxStartIndex; + protected final boolean returnFirstMatch; - public CommonSequenceMatcher(Collator collator, int commonSequenceMaxStartIndex) { + public CommonSequenceMatcher(Collator collator, int commonSequenceMaxStartIndex, boolean returnFirstMatch) { this.collator = collator; this.commonSequenceMaxStartIndex = commonSequenceMaxStartIndex; + this.returnFirstMatch = returnFirstMatch; } @@ -48,7 +50,7 @@ public class CommonSequenceMatcher { common = words; } else { // find common sequence - common = firstCommonSequence(common, words, commonSequenceMaxStartIndex); + common = firstCommonSequence(common, words, commonSequenceMaxStartIndex, returnFirstMatch); if (common == null) { // no common sequence @@ -96,7 +98,7 @@ public class CommonSequenceMatcher { } - protected > E[] firstCommonSequence(E[] seq1, E[] seq2, int maxStartIndex) { + protected > E[] firstCommonSequence(E[] seq1, E[] seq2, int maxStartIndex, boolean returnFirstMatch) { E[] matchSeq = null; for (int i = 0; i < seq1.length && i <= maxStartIndex; i++) { for (int j = 0; j < seq2.length && j <= maxStartIndex; j++) { @@ -111,6 +113,11 @@ public class CommonSequenceMatcher { // check if a common sequence was found if (len > (matchSeq == null ? 0 : matchSeq.length)) { matchSeq = copyOfRange(seq1, i, i + len); + + // look for first match + if (returnFirstMatch) { + return matchSeq; + } } } } diff --git a/source/net/sourceforge/filebot/similarity/SequenceMatchSimilarity.java b/source/net/sourceforge/filebot/similarity/SequenceMatchSimilarity.java index 52896b47..7c3a47bb 100644 --- a/source/net/sourceforge/filebot/similarity/SequenceMatchSimilarity.java +++ b/source/net/sourceforge/filebot/similarity/SequenceMatchSimilarity.java @@ -11,7 +11,7 @@ import java.util.Locale; public class SequenceMatchSimilarity implements SimilarityMetric { - private final CommonSequenceMatcher commonSequenceMatcher = new CommonSequenceMatcher(getLenientCollator(Locale.ROOT), 10); + private final CommonSequenceMatcher commonSequenceMatcher = new CommonSequenceMatcher(getLenientCollator(Locale.ROOT), 10, false); @Override diff --git a/source/net/sourceforge/filebot/similarity/SeriesNameMatcher.java b/source/net/sourceforge/filebot/similarity/SeriesNameMatcher.java index 6ecf8738..5114833c 100644 --- a/source/net/sourceforge/filebot/similarity/SeriesNameMatcher.java +++ b/source/net/sourceforge/filebot/similarity/SeriesNameMatcher.java @@ -46,7 +46,7 @@ public class SeriesNameMatcher { public SeriesNameMatcher(Locale locale) { - commonSequenceMatcher = new CommonSequenceMatcher(getLenientCollator(locale), 3) { + commonSequenceMatcher = new CommonSequenceMatcher(getLenientCollator(locale), 3, true) { @Override protected CollationKey[] split(String sequence) {