* added missing source files (belongs to last commit)

This commit is contained in:
Reinhard Pointner 2011-10-28 06:31:19 +00:00
parent 7a83fda23b
commit 93d2e0f379
2 changed files with 62 additions and 0 deletions

View File

@ -0,0 +1,33 @@
package net.sourceforge.filebot.cli;
import static java.lang.Math.*;
import net.sourceforge.filebot.similarity.SimilarityMetric;
import net.sourceforge.filebot.ui.rename.MatchSimilarityMetric;
enum StrictMetric implements SimilarityMetric {
EpisodeIdentifier(MatchSimilarityMetric.EpisodeIdentifier, 1), // only allow 0 or 1
Title(MatchSimilarityMetric.Title, 2), // allow 0 or .5 or 1
Name(MatchSimilarityMetric.Name, 2); // allow 0 or .5 or 1
// inner metric
private final SimilarityMetric metric;
private final float floorFactor;
private StrictMetric(SimilarityMetric metric, float floorFactor) {
this.metric = metric;
this.floorFactor = floorFactor;
}
@Override
public float getSimilarity(Object o1, Object o2) {
return (float) (floor(metric.getSimilarity(o1, o2) * floorFactor) / floorFactor);
}
}

View File

@ -0,0 +1,29 @@
package net.sourceforge.filebot.similarity;
public class SubstringMetric implements SimilarityMetric {
@Override
public float getSimilarity(Object o1, Object o2) {
String s1 = normalize(o1);
String s2 = normalize(o2);
String pri = s1.length() > s2.length() ? s1 : s2;
String sub = s1.length() > s2.length() ? s2 : s1;
return sub.length() > 0 && pri.contains(sub) ? 1 : 0;
}
protected String normalize(Object object) {
// use string representation
String name = object.toString();
// normalize separators
name = name.replaceAll("[\\p{Punct}\\p{Space}]+", " ");
// normalize case and trim
return name.trim().toLowerCase();
}
}