2011-11-24 12:27:39 -05:00
|
|
|
|
2014-04-19 02:30:29 -04:00
|
|
|
package net.filebot.similarity;
|
2011-11-24 12:27:39 -05:00
|
|
|
|
|
|
|
|
2014-04-19 02:30:29 -04:00
|
|
|
import static net.filebot.util.FileUtilities.*;
|
2011-11-24 12:27:39 -05:00
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
|
|
|
|
|
|
|
public class FileNameMetric implements SimilarityMetric {
|
2015-07-25 18:47:19 -04:00
|
|
|
|
2011-11-24 12:27:39 -05:00
|
|
|
@Override
|
|
|
|
public float getSimilarity(Object o1, Object o2) {
|
|
|
|
String s1 = getFileName(o1);
|
|
|
|
if (s1 == null || s1.isEmpty())
|
|
|
|
return 0;
|
2015-07-25 18:47:19 -04:00
|
|
|
|
2011-11-24 12:27:39 -05:00
|
|
|
String s2 = getFileName(o2);
|
|
|
|
if (s2 == null || s2.isEmpty())
|
|
|
|
return 0;
|
2015-07-25 18:47:19 -04:00
|
|
|
|
2011-11-24 12:27:39 -05:00
|
|
|
return s1.startsWith(s2) || s2.startsWith(s1) ? 1 : 0;
|
|
|
|
}
|
2015-07-25 18:47:19 -04:00
|
|
|
|
2011-11-24 12:27:39 -05:00
|
|
|
|
|
|
|
protected String getFileName(Object object) {
|
|
|
|
if (object instanceof File) {
|
|
|
|
// name without extension normalized to lower-case
|
|
|
|
return getName((File) object).trim().toLowerCase();
|
|
|
|
}
|
2015-07-25 18:47:19 -04:00
|
|
|
|
2011-11-24 12:27:39 -05:00
|
|
|
return null;
|
|
|
|
}
|
2015-07-25 18:47:19 -04:00
|
|
|
|
2011-11-24 12:27:39 -05:00
|
|
|
}
|