* make use of MetaAttributes to nudge matching a little bit in that direction
This commit is contained in:
parent
d0194aae25
commit
01f54f8e86
|
@ -0,0 +1,57 @@
|
|||
|
||||
package net.sourceforge.filebot.similarity;
|
||||
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import net.sourceforge.filebot.format.PropertyBindings;
|
||||
|
||||
|
||||
public class CrossPropertyMetric implements SimilarityMetric {
|
||||
|
||||
private SimilarityMetric metric;
|
||||
|
||||
|
||||
public CrossPropertyMetric(SimilarityMetric metric) {
|
||||
this.metric = metric;
|
||||
}
|
||||
|
||||
|
||||
public CrossPropertyMetric() {
|
||||
this.metric = new StringEqualsMetric();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public float getSimilarity(Object o1, Object o2) {
|
||||
Map<String, Object> m1 = getProperties(o1);
|
||||
Map<String, Object> m2 = getProperties(o2);
|
||||
|
||||
Set<String> keys = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
|
||||
keys.addAll(m1.keySet());
|
||||
keys.retainAll(m2.keySet());
|
||||
|
||||
if (keys.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
float feedback = 0;
|
||||
for (String k : keys) {
|
||||
try {
|
||||
feedback += metric.getSimilarity(m1.get(k), m2.get(k));
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
return feedback / keys.size();
|
||||
}
|
||||
|
||||
|
||||
protected Map<String, Object> getProperties(Object object) {
|
||||
return new PropertyBindings(object, null);
|
||||
}
|
||||
|
||||
}
|
|
@ -308,6 +308,31 @@ public enum EpisodeMetrics implements SimilarityMetric {
|
|||
|
||||
return super.getTimeStamp(object);
|
||||
}
|
||||
}),
|
||||
|
||||
// Match by stored MetaAttributes if possible
|
||||
MetaAttributes(new CrossPropertyMetric() {
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> getProperties(Object object) {
|
||||
// Episode / Movie objects
|
||||
if (object instanceof Episode || object instanceof Movie) {
|
||||
return super.getProperties(object);
|
||||
}
|
||||
|
||||
// deserialize MetaAttributes if available
|
||||
if (object instanceof File) {
|
||||
try {
|
||||
return super.getProperties(new net.sourceforge.filebot.media.MetaAttributes((File) object).getMetaData());
|
||||
} catch (Throwable e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
// ignore everything else
|
||||
return emptyMap();
|
||||
};
|
||||
|
||||
});
|
||||
|
||||
// inner metric
|
||||
|
@ -365,9 +390,9 @@ public enum EpisodeMetrics implements SimilarityMetric {
|
|||
// 7 pass: prefer episodes that were aired closer to the last modified date of the file
|
||||
// 8 pass: resolve remaining collisions via absolute string similarity
|
||||
if (includeFileMetrics) {
|
||||
return new SimilarityMetric[] { FileSize, new MetricCascade(FileName, EpisodeFunnel), EpisodeBalancer, SubstringFields, new MetricCascade(SubstringSequence, Name), Numeric, Name, TimeStamp, new NameSimilarityMetric() };
|
||||
return new SimilarityMetric[] { FileSize, new MetricCascade(FileName, EpisodeFunnel), EpisodeBalancer, SubstringFields, MetaAttributes, new MetricCascade(SubstringSequence, Name), Numeric, Name, TimeStamp, new NameSimilarityMetric() };
|
||||
} else {
|
||||
return new SimilarityMetric[] { EpisodeFunnel, EpisodeBalancer, SubstringFields, new MetricCascade(SubstringSequence, Name), Numeric, Name, TimeStamp, new NameSimilarityMetric() };
|
||||
return new SimilarityMetric[] { EpisodeFunnel, EpisodeBalancer, SubstringFields, MetaAttributes, new MetricCascade(SubstringSequence, Name), Numeric, Name, TimeStamp, new NameSimilarityMetric() };
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
|
||||
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();
|
||||
|
||||
if (s1.isEmpty() || s2.isEmpty())
|
||||
return 0;
|
||||
|
||||
return s1.equalsIgnoreCase(s2) ? 1 : 0;
|
||||
}
|
||||
|
||||
}
|
|
@ -16,7 +16,7 @@ public class ReleaseInfoTest {
|
|||
ReleaseInfo info = new ReleaseInfo();
|
||||
File f = new File("Jurassic.Park[1993]DvDrip-aXXo.avi");
|
||||
|
||||
assertEquals("DVDRip", info.getVideoSource(f));
|
||||
assertEquals("DVDRip", info.getVideoSource(f.getName()));
|
||||
}
|
||||
|
||||
|
||||
|
@ -25,7 +25,7 @@ public class ReleaseInfoTest {
|
|||
ReleaseInfo info = new ReleaseInfo();
|
||||
File f = new File("Jurassic.Park[1993]DvDrip-aXXo.avi");
|
||||
|
||||
assertEquals("aXXo", info.getReleaseGroup(f));
|
||||
assertEquals("aXXo", info.getReleaseGroup(f.getName()));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue