2009-01-11 16:23:03 -05:00
|
|
|
|
|
|
|
package net.sourceforge.filebot.similarity;
|
|
|
|
|
|
|
|
|
2009-02-12 17:04:17 -05:00
|
|
|
import java.io.File;
|
2009-01-24 19:08:57 -05:00
|
|
|
import java.util.Collection;
|
2009-03-14 06:20:59 -04:00
|
|
|
|
2009-01-24 19:08:57 -05:00
|
|
|
import net.sourceforge.filebot.similarity.SeasonEpisodeMatcher.SxE;
|
2009-01-11 16:23:03 -05:00
|
|
|
|
|
|
|
|
2010-10-24 12:33:38 -04:00
|
|
|
public class SeasonEpisodeMetric implements SimilarityMetric {
|
2009-01-11 16:23:03 -05:00
|
|
|
|
2011-12-28 19:41:27 -05:00
|
|
|
private final SeasonEpisodeMatcher seasonEpisodeMatcher = new SeasonEpisodeMatcher(null, false);
|
|
|
|
|
2009-01-11 16:23:03 -05:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public float getSimilarity(Object o1, Object o2) {
|
2009-01-24 19:08:57 -05:00
|
|
|
Collection<SxE> sxeVector1 = parse(o1);
|
2011-11-27 09:35:53 -05:00
|
|
|
if (sxeVector1 == null || sxeVector1.isEmpty())
|
2009-03-01 08:52:43 -05:00
|
|
|
return 0;
|
2009-01-11 16:23:03 -05:00
|
|
|
|
2011-11-27 09:35:53 -05:00
|
|
|
Collection<SxE> sxeVector2 = parse(o2);
|
|
|
|
if (sxeVector2 == null || sxeVector2.isEmpty())
|
|
|
|
return 0;
|
2009-03-01 08:52:43 -05:00
|
|
|
|
2011-11-27 09:35:53 -05:00
|
|
|
float similarity = -1;
|
2009-03-01 08:52:43 -05:00
|
|
|
for (SxE sxe1 : sxeVector1) {
|
|
|
|
for (SxE sxe2 : sxeVector2) {
|
2011-11-27 10:41:42 -05:00
|
|
|
if (sxe1.season == sxe2.season && sxe1.episode == sxe2.episode) {
|
2009-05-03 11:21:04 -04:00
|
|
|
// vectors have at least one perfect episode match in common
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-11-27 10:41:42 -05:00
|
|
|
if (sxe1.season == sxe2.season || sxe1.episode == sxe2.episode) {
|
2009-03-01 08:52:43 -05:00
|
|
|
// at least we have a partial match
|
|
|
|
similarity = 0.5f;
|
|
|
|
}
|
|
|
|
}
|
2009-01-11 16:23:03 -05:00
|
|
|
}
|
|
|
|
|
2009-03-01 08:52:43 -05:00
|
|
|
return similarity;
|
2009-01-11 16:23:03 -05:00
|
|
|
}
|
|
|
|
|
2011-12-28 19:41:27 -05:00
|
|
|
|
2009-02-12 17:04:17 -05:00
|
|
|
protected Collection<SxE> parse(Object object) {
|
|
|
|
if (object instanceof File) {
|
|
|
|
// parse file name
|
|
|
|
object = ((File) object).getName();
|
|
|
|
}
|
|
|
|
|
|
|
|
return seasonEpisodeMatcher.match(object.toString());
|
2009-01-11 16:23:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|