* fix series detection regression issues

This commit is contained in:
Reinhard Pointner 2013-03-09 12:29:49 +00:00
parent 2fa6be847e
commit 173d5e95c6
4 changed files with 13 additions and 6 deletions

View File

@ -826,7 +826,7 @@ public class MediaDetection {
public HighPerformanceMatcher(int maxStartIndex) {
super(collator, maxStartIndex);
super(collator, maxStartIndex, true);
}

View File

@ -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 extends Comparable<E>> E[] firstCommonSequence(E[] seq1, E[] seq2, int maxStartIndex) {
protected <E extends Comparable<E>> 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;
}
}
}
}

View File

@ -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

View File

@ -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) {