Cache SeriesNameMatcher objects
This commit is contained in:
parent
d84b11a850
commit
9c8da51277
|
@ -118,7 +118,7 @@ public class CmdlineOperations implements CmdlineInterface {
|
||||||
|
|
||||||
Collection<String> cwsList = emptySet();
|
Collection<String> cwsList = emptySet();
|
||||||
if (max >= 5) {
|
if (max >= 5) {
|
||||||
cwsList = getSeriesNameMatcher().matchAll(mediaFiles.toArray(new File[0]));
|
cwsList = getSeriesNameMatcher(true).matchAll(mediaFiles.toArray(new File[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (File f : mediaFiles) {
|
for (File f : mediaFiles) {
|
||||||
|
@ -129,7 +129,7 @@ public class CmdlineOperations implements CmdlineInterface {
|
||||||
|
|
||||||
// count CWS matches
|
// count CWS matches
|
||||||
for (String base : cwsList) {
|
for (String base : cwsList) {
|
||||||
if (base.equalsIgnoreCase(getSeriesNameMatcher().matchByFirstCommonWordSequence(base, f.getName()))) {
|
if (base.equalsIgnoreCase(getSeriesNameMatcher(true).matchByFirstCommonWordSequence(base, f.getName()))) {
|
||||||
cws++;
|
cws++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,8 +117,7 @@ public class MediaDetection {
|
||||||
|
|
||||||
private static final SeasonEpisodeMatcher seasonEpisodeMatcherStrict = new SmartSeasonEpisodeMatcher(SeasonEpisodeMatcher.DEFAULT_SANITY, true);
|
private static final SeasonEpisodeMatcher seasonEpisodeMatcherStrict = new SmartSeasonEpisodeMatcher(SeasonEpisodeMatcher.DEFAULT_SANITY, true);
|
||||||
private static final SeasonEpisodeMatcher seasonEpisodeMatcherNonStrict = new SmartSeasonEpisodeMatcher(SeasonEpisodeMatcher.DEFAULT_SANITY, false);
|
private static final SeasonEpisodeMatcher seasonEpisodeMatcherNonStrict = new SmartSeasonEpisodeMatcher(SeasonEpisodeMatcher.DEFAULT_SANITY, false);
|
||||||
private static final DateMatcher dateMatcher = new DateMatcher(Locale.getDefault(), DateMatcher.DEFAULT_SANITY);
|
private static final DateMatcher dateMatcher = new DateMatcher(DateMatcher.DEFAULT_SANITY, Locale.ENGLISH, Locale.getDefault());
|
||||||
private static final SeriesNameMatcher seriesNameMatcher = new SeriesNameMatcher(Locale.ENGLISH, true);
|
|
||||||
|
|
||||||
public static SeasonEpisodeMatcher getSeasonEpisodeMatcher(boolean strict) {
|
public static SeasonEpisodeMatcher getSeasonEpisodeMatcher(boolean strict) {
|
||||||
return strict ? seasonEpisodeMatcherStrict : seasonEpisodeMatcherNonStrict;
|
return strict ? seasonEpisodeMatcherStrict : seasonEpisodeMatcherNonStrict;
|
||||||
|
@ -128,8 +127,8 @@ public class MediaDetection {
|
||||||
return dateMatcher;
|
return dateMatcher;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SeriesNameMatcher getSeriesNameMatcher() {
|
public static SeriesNameMatcher getSeriesNameMatcher(boolean strict) {
|
||||||
return seriesNameMatcher;
|
return new SeriesNameMatcher(strict ? seasonEpisodeMatcherStrict : seasonEpisodeMatcherNonStrict, dateMatcher);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isEpisode(String name, boolean strict) {
|
public static boolean isEpisode(String name, boolean strict) {
|
||||||
|
@ -330,7 +329,7 @@ public class MediaDetection {
|
||||||
}
|
}
|
||||||
|
|
||||||
// strict series name matcher for recognizing 1x01 patterns
|
// strict series name matcher for recognizing 1x01 patterns
|
||||||
SeriesNameMatcher strictSeriesNameMatcher = new SeriesNameMatcher(locale, true);
|
SeriesNameMatcher strictSeriesNameMatcher = getSeriesNameMatcher(true);
|
||||||
|
|
||||||
// cross-reference known series names against file structure
|
// cross-reference known series names against file structure
|
||||||
try {
|
try {
|
||||||
|
@ -396,7 +395,7 @@ public class MediaDetection {
|
||||||
for (boolean strict : new boolean[] { true, false }) {
|
for (boolean strict : new boolean[] { true, false }) {
|
||||||
if (matches.isEmpty()) {
|
if (matches.isEmpty()) {
|
||||||
// check CWS matches
|
// check CWS matches
|
||||||
SeriesNameMatcher seriesNameMatcher = new SeriesNameMatcher(Locale.ENGLISH, strict);
|
SeriesNameMatcher seriesNameMatcher = getSeriesNameMatcher(strict);
|
||||||
matches.addAll(strictSeriesNameMatcher.matchAll(files.toArray(new File[files.size()])));
|
matches.addAll(strictSeriesNameMatcher.matchAll(files.toArray(new File[files.size()])));
|
||||||
|
|
||||||
// try before SxE pattern
|
// try before SxE pattern
|
||||||
|
|
|
@ -303,7 +303,7 @@ public enum EpisodeMetrics implements SimilarityMetric {
|
||||||
// Match by generic name similarity (absolute)
|
// Match by generic name similarity (absolute)
|
||||||
SeriesName(new NameSimilarityMetric() {
|
SeriesName(new NameSimilarityMetric() {
|
||||||
|
|
||||||
private SeriesNameMatcher seriesNameMatcher = new SeriesNameMatcher(Locale.ENGLISH, false);
|
private final SeriesNameMatcher seriesNameMatcher = getSeriesNameMatcher(false);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getSimilarity(Object o1, Object o2) {
|
public float getSimilarity(Object o1, Object o2) {
|
||||||
|
@ -591,8 +591,10 @@ public enum EpisodeMetrics implements SimilarityMetric {
|
||||||
// Match by (region) or (year) hints
|
// Match by (region) or (year) hints
|
||||||
RegionHint(new SimilarityMetric() {
|
RegionHint(new SimilarityMetric() {
|
||||||
|
|
||||||
private Pattern hint = compile("[(](\\p{Alpha}+|\\p{Digit}+)[)]$");
|
private final Pattern hint = compile("[(](\\p{Alpha}+|\\p{Digit}+)[)]$");
|
||||||
private Pattern punctuation = compile("[\\p{Punct}\\p{Space}]+");
|
private final Pattern punctuation = compile("[\\p{Punct}\\p{Space}]+");
|
||||||
|
|
||||||
|
private final SeriesNameMatcher seriesNameMatcher = getSeriesNameMatcher(true);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getSimilarity(Object o1, Object o2) {
|
public float getSimilarity(Object o1, Object o2) {
|
||||||
|
@ -615,7 +617,7 @@ public enum EpisodeMetrics implements SimilarityMetric {
|
||||||
for (File f : listPathTail((File) o, 3, true)) {
|
for (File f : listPathTail((File) o, 3, true)) {
|
||||||
// try to focus on series name
|
// try to focus on series name
|
||||||
String n = f.getName();
|
String n = f.getName();
|
||||||
String sn = getSeriesNameMatcher().matchByEpisodeIdentifier(n);
|
String sn = seriesNameMatcher.matchByEpisodeIdentifier(n);
|
||||||
|
|
||||||
String[] tokens = punctuation.split(sn != null ? sn : n);
|
String[] tokens = punctuation.split(sn != null ? sn : n);
|
||||||
for (String s : tokens) {
|
for (String s : tokens) {
|
||||||
|
|
|
@ -36,8 +36,12 @@ public class SeriesNameMatcher {
|
||||||
protected final DateMatcher dateMatcher;
|
protected final DateMatcher dateMatcher;
|
||||||
protected final CommonSequenceMatcher commonSequenceMatcher;
|
protected final CommonSequenceMatcher commonSequenceMatcher;
|
||||||
|
|
||||||
public SeriesNameMatcher(Locale locale, boolean strict) {
|
public SeriesNameMatcher(boolean strict) {
|
||||||
this(new NameSimilarityMetric(), getLenientCollator(locale), new SmartSeasonEpisodeMatcher(SeasonEpisodeMatcher.DEFAULT_SANITY, strict), new DateMatcher(locale, DateMatcher.DEFAULT_SANITY));
|
this(new NameSimilarityMetric(), getLenientCollator(Locale.ENGLISH), new SmartSeasonEpisodeMatcher(SeasonEpisodeMatcher.DEFAULT_SANITY, strict), new DateMatcher(DateMatcher.DEFAULT_SANITY, Locale.ENGLISH));
|
||||||
|
}
|
||||||
|
|
||||||
|
public SeriesNameMatcher(SeasonEpisodeMatcher seasonEpisodeMatcher, DateMatcher dateMatcher) {
|
||||||
|
this(new NameSimilarityMetric(), getLenientCollator(Locale.ENGLISH), seasonEpisodeMatcher, dateMatcher);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SeriesNameMatcher(SimilarityMetric metric, Collator collator, SeasonEpisodeMatcher seasonEpisodeMatcher, DateMatcher dateMatcher) {
|
public SeriesNameMatcher(SimilarityMetric metric, Collator collator, SeasonEpisodeMatcher seasonEpisodeMatcher, DateMatcher dateMatcher) {
|
||||||
|
|
|
@ -129,7 +129,7 @@ public class ListPanel extends JComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
// try to match title from the first five names
|
// try to match title from the first five names
|
||||||
Collection<String> title = getSeriesNameMatcher().matchAll((names.size() < 5 ? names : names.subList(0, 4)).toArray(new String[0]));
|
Collection<String> title = getSeriesNameMatcher(true).matchAll((names.size() < 5 ? names : names.subList(0, 4)).toArray(new String[0]));
|
||||||
|
|
||||||
list.setTitle(title.isEmpty() ? "List" : title.iterator().next());
|
list.setTitle(title.isEmpty() ? "List" : title.iterator().next());
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ class MovieEditor implements TableCellEditor {
|
||||||
String fn = FileUtilities.getName(mapping.getVideo() != null ? mapping.getVideo() : mapping.getSubtitle());
|
String fn = FileUtilities.getName(mapping.getVideo() != null ? mapping.getVideo() : mapping.getSubtitle());
|
||||||
|
|
||||||
// check if query contain an episode identifier
|
// check if query contain an episode identifier
|
||||||
String sn = getSeriesNameMatcher().matchByEpisodeIdentifier(fn);
|
String sn = getSeriesNameMatcher(true).matchByEpisodeIdentifier(fn);
|
||||||
if (sn != null) {
|
if (sn != null) {
|
||||||
return stripReleaseInfo(sn, true);
|
return stripReleaseInfo(sn, true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import org.junit.Test;
|
||||||
|
|
||||||
public class DateMatcherTest {
|
public class DateMatcherTest {
|
||||||
|
|
||||||
DateMatcher m = new DateMatcher(Locale.ENGLISH, DateMatcher.DEFAULT_SANITY);
|
DateMatcher m = new DateMatcher(DateMatcher.DEFAULT_SANITY, Locale.ENGLISH);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parse() {
|
public void parse() {
|
||||||
|
@ -25,8 +25,8 @@ public class DateMatcherTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parseLocale() {
|
public void parseLocale() {
|
||||||
assertEquals("2016-03-01", new DateMatcher(Locale.GERMAN, DateMatcher.DEFAULT_SANITY).match("01 März 2016").toString());
|
assertEquals("2016-03-01", new DateMatcher(DateMatcher.DEFAULT_SANITY, Locale.GERMAN).match("01 März 2016").toString());
|
||||||
assertEquals("2016-03-01", new DateMatcher(Locale.GERMAN, DateMatcher.DEFAULT_SANITY).match("1 March 2016").toString()); // always parse English
|
assertEquals("2016-03-01", new DateMatcher(DateMatcher.DEFAULT_SANITY, Locale.GERMAN).match("1 March 2016").toString()); // always parse English
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -8,7 +8,7 @@ import org.junit.Test;
|
||||||
|
|
||||||
public class DateMetricTest {
|
public class DateMetricTest {
|
||||||
|
|
||||||
DateMetric metric = new DateMetric(new DateMatcher(Locale.ENGLISH, DateMatcher.DEFAULT_SANITY));
|
DateMetric metric = new DateMetric(new DateMatcher(DateMatcher.DEFAULT_SANITY, Locale.ENGLISH));
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getSimilarity() {
|
public void getSimilarity() {
|
||||||
|
|
|
@ -1,16 +1,13 @@
|
||||||
package net.filebot.similarity;
|
package net.filebot.similarity;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
import net.filebot.similarity.SeriesNameMatcher.SeriesNameCollection;
|
import net.filebot.similarity.SeriesNameMatcher.SeriesNameCollection;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class SeriesNameMatcherTest {
|
public class SeriesNameMatcherTest {
|
||||||
|
|
||||||
private static SeriesNameMatcher matcher = new SeriesNameMatcher(Locale.ENGLISH, true);
|
SeriesNameMatcher matcher = new SeriesNameMatcher(true);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whitelist() {
|
public void whitelist() {
|
||||||
|
|
Loading…
Reference in New Issue