mirror of
https://github.com/mitb-archive/filebot
synced 2024-11-04 08:25:03 -05:00
* added negative/exclude matching logic
This commit is contained in:
parent
6a4709db57
commit
90d9887c20
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,23 +16,22 @@ public class SeasonEpisodeMetric implements SimilarityMetric {
|
||||
@Override
|
||||
public float getSimilarity(Object o1, Object o2) {
|
||||
Collection<SxE> sxeVector1 = parse(o1);
|
||||
Collection<SxE> 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<SxE> 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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user