diff --git a/source/net/sourceforge/filebot/media/MediaDetection.java b/source/net/sourceforge/filebot/media/MediaDetection.java index 8d5052eb..1fb3c845 100644 --- a/source/net/sourceforge/filebot/media/MediaDetection.java +++ b/source/net/sourceforge/filebot/media/MediaDetection.java @@ -56,6 +56,7 @@ import net.sourceforge.filebot.similarity.SequenceMatchSimilarity; import net.sourceforge.filebot.similarity.SeriesNameMatcher; import net.sourceforge.filebot.similarity.SimilarityComparator; import net.sourceforge.filebot.similarity.SimilarityMetric; +import net.sourceforge.filebot.similarity.StringEqualsMetric; import net.sourceforge.filebot.vfs.FileInfo; import net.sourceforge.filebot.web.Date; import net.sourceforge.filebot.web.Episode; @@ -654,7 +655,13 @@ public class MediaDetection { } public static SimilarityMetric getMovieMatchMetric() { - return new MetricAvg(new SequenceMatchSimilarity(), new NameSimilarityMetric(), new SequenceMatchSimilarity(0, true), new NumericSimilarityMetric() { + return new MetricAvg(new SequenceMatchSimilarity(), new NameSimilarityMetric(), new SequenceMatchSimilarity(0, true), new StringEqualsMetric() { + + @Override + protected String normalize(Object object) { + return super.normalize(removeTrailingBrackets(object.toString())); + } + }, new NumericSimilarityMetric() { private Pattern year = Pattern.compile("\\b\\d{4}\\b"); diff --git a/source/net/sourceforge/filebot/similarity/MetricAvg.java b/source/net/sourceforge/filebot/similarity/MetricAvg.java index e043f2c1..d2e1069b 100644 --- a/source/net/sourceforge/filebot/similarity/MetricAvg.java +++ b/source/net/sourceforge/filebot/similarity/MetricAvg.java @@ -1,17 +1,17 @@ - package net.sourceforge.filebot.similarity; - public class MetricAvg implements SimilarityMetric { - + private final SimilarityMetric[] metrics; - - + public MetricAvg(SimilarityMetric... metrics) { this.metrics = metrics; } - - + + public SimilarityMetric[] getMetrics() { + return metrics.clone(); + } + @Override public float getSimilarity(Object o1, Object o2) { float f = 0; @@ -20,5 +20,5 @@ public class MetricAvg implements SimilarityMetric { } return f / metrics.length; } - + } diff --git a/source/net/sourceforge/filebot/similarity/StringEqualsMetric.java b/source/net/sourceforge/filebot/similarity/StringEqualsMetric.java index cabd887d..d03d9978 100644 --- a/source/net/sourceforge/filebot/similarity/StringEqualsMetric.java +++ b/source/net/sourceforge/filebot/similarity/StringEqualsMetric.java @@ -1,21 +1,23 @@ - package net.sourceforge.filebot.similarity; - public class StringEqualsMetric implements SimilarityMetric { - + @Override public float getSimilarity(Object o1, Object o2) { if (o1 == null || o2 == null) return 0; - - String s1 = o1.toString(); - String s2 = o2.toString(); - + + String s1 = normalize(o1); + String s2 = normalize(o2); + if (s1.isEmpty() || s2.isEmpty()) return 0; - - return s1.equalsIgnoreCase(s2) ? 1 : 0; + + return s1.equals(s2) ? 1 : 0; } - + + protected String normalize(Object object) { + return object.toString().trim().toLowerCase(); + } + } diff --git a/source/net/sourceforge/filebot/similarity/SubstringMetric.java b/source/net/sourceforge/filebot/similarity/SubstringMetric.java index 060cb40f..1e198e3f 100644 --- a/source/net/sourceforge/filebot/similarity/SubstringMetric.java +++ b/source/net/sourceforge/filebot/similarity/SubstringMetric.java @@ -4,6 +4,18 @@ import static net.sourceforge.filebot.similarity.Normalization.*; public class SubstringMetric implements SimilarityMetric { + private boolean o1c2; + private boolean o2c1; + + public SubstringMetric() { + this(true, true); + } + + public SubstringMetric(boolean o2c1, boolean o1c2) { + this.o1c2 = o1c2; + this.o2c1 = o2c1; + } + @Override public float getSimilarity(Object o1, Object o2) { String s1 = normalize(o1); @@ -14,7 +26,7 @@ public class SubstringMetric implements SimilarityMetric { if (s2 == null || s2.isEmpty()) return 0; - return s1.contains(s2) || s2.contains(s1) ? 1 : 0; + return (o1c2 && s1.contains(s2)) || (o2c1 && s2.contains(s1)) ? 1 : 0; } protected String normalize(Object object) {