From 90d9887c2037b0d01acba73f8c4883294e8ea115 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sun, 27 Nov 2011 14:35:53 +0000 Subject: [PATCH] * added negative/exclude matching logic --- .../filebot/similarity/DateMetric.java | 9 +++++++-- .../filebot/similarity/EpisodeMetrics.java | 9 +++++++-- .../filebot/similarity/FileSizeMetric.java | 12 +++++++----- .../filebot/similarity/MetricCascade.java | 14 +++++++++----- .../filebot/similarity/SeasonEpisodeMetric.java | 15 +++++++-------- 5 files changed, 37 insertions(+), 22 deletions(-) diff --git a/source/net/sourceforge/filebot/similarity/DateMetric.java b/source/net/sourceforge/filebot/similarity/DateMetric.java index 4b399183..9d20feff 100644 --- a/source/net/sourceforge/filebot/similarity/DateMetric.java +++ b/source/net/sourceforge/filebot/similarity/DateMetric.java @@ -29,9 +29,14 @@ public class DateMetric implements SimilarityMetric { @Override public float getSimilarity(Object o1, Object o2) { Date d1 = parse(o1); - Date d2 = parse(o2); + if (d1 == null) + return 0; - return d1 != null && d2 != null && d1.equals(d2) ? 1 : 0; + Date d2 = parse(o2); + if (d2 == null) + return 0; + + return d1.equals(d2) ? 1 : -1; } diff --git a/source/net/sourceforge/filebot/similarity/EpisodeMetrics.java b/source/net/sourceforge/filebot/similarity/EpisodeMetrics.java index 01f61b7c..519d5897 100644 --- a/source/net/sourceforge/filebot/similarity/EpisodeMetrics.java +++ b/source/net/sourceforge/filebot/similarity/EpisodeMetrics.java @@ -106,7 +106,7 @@ public enum EpisodeMetrics implements SimilarityMetric { // Match by SxE and airdate EpisodeIdentifier(new MetricCascade(SeasonEpisode, AirDate)), - // Advanced episode<->file matching + // Advanced episode <-> file matching EpisodeFunnel(new MetricCascade(SeasonEpisode, AirDate, Title)), EpisodeBalancer(new SimilarityMetric() { @@ -116,7 +116,7 @@ public enum EpisodeMetrics implements SimilarityMetric { float title = Title.getSimilarity(o1, o2); // 1:SxE && Title, 2:SxE - return (sxe * title) + (sxe / 10f); + return (float) ((max(sxe, 0) * title) + (floor(sxe) / 10)); } }), @@ -283,4 +283,9 @@ public enum EpisodeMetrics implements SimilarityMetric { } } + + public static SimilarityMetric verificationMetric() { + return new MetricCascade(FileSize, FileName, SeasonEpisode, AirDate, Title, Name); + } + } diff --git a/source/net/sourceforge/filebot/similarity/FileSizeMetric.java b/source/net/sourceforge/filebot/similarity/FileSizeMetric.java index f28c2c38..af370497 100644 --- a/source/net/sourceforge/filebot/similarity/FileSizeMetric.java +++ b/source/net/sourceforge/filebot/similarity/FileSizeMetric.java @@ -10,13 +10,15 @@ public class FileSizeMetric implements SimilarityMetric { @Override public float getSimilarity(Object o1, Object o2) { long l1 = getLength(o1); + if (l1 < 0) + return 0; - if (l1 >= 0 && l1 == getLength(o2)) { - // objects have the same non-negative length - return 1; - } + long l2 = getLength(o1); + if (l2 < 0) + return 0; - return 0; + // objects have the same non-negative length + return l1 == l2 ? 1 : -1; } diff --git a/source/net/sourceforge/filebot/similarity/MetricCascade.java b/source/net/sourceforge/filebot/similarity/MetricCascade.java index 20962f55..34aa8499 100644 --- a/source/net/sourceforge/filebot/similarity/MetricCascade.java +++ b/source/net/sourceforge/filebot/similarity/MetricCascade.java @@ -19,11 +19,15 @@ public class MetricCascade implements SimilarityMetric { public float getSimilarity(Object o1, Object o2) { float f = 0; for (SimilarityMetric metric : cascade) { - f = max(f, metric.getSimilarity(o1, o2)); - - // perfect match, ignore remaining metrics - if (f >= 1) { - return f; + float similarity = metric.getSimilarity(o1, o2); + if (abs(similarity) >= abs(f)) { + // perfect match, ignore remaining metrics + if (similarity >= 1) { + return similarity; + } + + // possible match or perfect negative match + f = similarity; } } diff --git a/source/net/sourceforge/filebot/similarity/SeasonEpisodeMetric.java b/source/net/sourceforge/filebot/similarity/SeasonEpisodeMetric.java index 12cf36ee..f1594549 100644 --- a/source/net/sourceforge/filebot/similarity/SeasonEpisodeMetric.java +++ b/source/net/sourceforge/filebot/similarity/SeasonEpisodeMetric.java @@ -16,23 +16,22 @@ public class SeasonEpisodeMetric implements SimilarityMetric { @Override public float getSimilarity(Object o1, Object o2) { Collection sxeVector1 = parse(o1); - Collection sxeVector2 = parse(o2); - - if (sxeVector1 == null || sxeVector2 == null) { - // name does not match any known pattern, return numeric similarity + if (sxeVector1 == null || sxeVector1.isEmpty()) return 0; - } - float similarity = 0; + Collection sxeVector2 = parse(o2); + if (sxeVector2 == null || sxeVector2.isEmpty()) + return 0; + float similarity = -1; for (SxE sxe1 : sxeVector1) { for (SxE sxe2 : sxeVector2) { - if (sxe1.season == sxe2.season && sxe1.episode == sxe2.episode) { + if (sxe1.season >= 0 && sxe1.season == sxe2.season && sxe1.episode >= 0 && sxe1.episode == sxe2.episode) { // vectors have at least one perfect episode match in common return 1; } - if (sxe1.season == sxe2.season || sxe1.episode == sxe2.episode) { + if ((sxe1.season >= 0 && sxe1.season == sxe2.season) || (sxe1.episode >= 0 && sxe1.episode == sxe2.episode)) { // at least we have a partial match similarity = 0.5f; }