1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-12-24 16:58:51 -05:00

* added negative/exclude matching logic

This commit is contained in:
Reinhard Pointner 2011-11-27 14:35:53 +00:00
parent 6a4709db57
commit 90d9887c20
5 changed files with 37 additions and 22 deletions

View File

@ -29,9 +29,14 @@ public class DateMetric implements SimilarityMetric {
@Override @Override
public float getSimilarity(Object o1, Object o2) { public float getSimilarity(Object o1, Object o2) {
Date d1 = parse(o1); 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;
} }

View File

@ -116,7 +116,7 @@ public enum EpisodeMetrics implements SimilarityMetric {
float title = Title.getSimilarity(o1, o2); float title = Title.getSimilarity(o1, o2);
// 1:SxE && Title, 2:SxE // 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);
}
} }

View File

@ -10,13 +10,15 @@ public class FileSizeMetric implements SimilarityMetric {
@Override @Override
public float getSimilarity(Object o1, Object o2) { public float getSimilarity(Object o1, Object o2) {
long l1 = getLength(o1); long l1 = getLength(o1);
if (l1 < 0)
if (l1 >= 0 && l1 == getLength(o2)) {
// objects have the same non-negative length
return 1;
}
return 0; return 0;
long l2 = getLength(o1);
if (l2 < 0)
return 0;
// objects have the same non-negative length
return l1 == l2 ? 1 : -1;
} }

View File

@ -19,11 +19,15 @@ public class MetricCascade implements SimilarityMetric {
public float getSimilarity(Object o1, Object o2) { public float getSimilarity(Object o1, Object o2) {
float f = 0; float f = 0;
for (SimilarityMetric metric : cascade) { for (SimilarityMetric metric : cascade) {
f = max(f, metric.getSimilarity(o1, o2)); float similarity = metric.getSimilarity(o1, o2);
if (abs(similarity) >= abs(f)) {
// perfect match, ignore remaining metrics // perfect match, ignore remaining metrics
if (f >= 1) { if (similarity >= 1) {
return f; return similarity;
}
// possible match or perfect negative match
f = similarity;
} }
} }

View File

@ -16,23 +16,22 @@ public class SeasonEpisodeMetric implements SimilarityMetric {
@Override @Override
public float getSimilarity(Object o1, Object o2) { public float getSimilarity(Object o1, Object o2) {
Collection<SxE> sxeVector1 = parse(o1); Collection<SxE> sxeVector1 = parse(o1);
Collection<SxE> sxeVector2 = parse(o2); if (sxeVector1 == null || sxeVector1.isEmpty())
if (sxeVector1 == null || sxeVector2 == null) {
// name does not match any known pattern, return numeric similarity
return 0; 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 sxe1 : sxeVector1) {
for (SxE sxe2 : sxeVector2) { 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 // vectors have at least one perfect episode match in common
return 1; 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 // at least we have a partial match
similarity = 0.5f; similarity = 0.5f;
} }