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