2014-04-19 02:30:29 -04:00
|
|
|
package net.filebot.similarity;
|
2009-01-11 16:23:03 -05:00
|
|
|
|
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
|
|
|
|
2014-04-19 02:30:29 -04:00
|
|
|
import net.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 {
|
2014-04-07 02:00:14 -04:00
|
|
|
|
|
|
|
private SeasonEpisodeMatcher seasonEpisodeMatcher;
|
|
|
|
|
|
|
|
public SeasonEpisodeMetric() {
|
|
|
|
this.seasonEpisodeMatcher = new SeasonEpisodeMatcher(null, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public SeasonEpisodeMetric(SeasonEpisodeMatcher seasonEpisodeMatcher) {
|
|
|
|
this.seasonEpisodeMatcher = seasonEpisodeMatcher;
|
|
|
|
}
|
|
|
|
|
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;
|
2014-04-07 02:00:14 -04:00
|
|
|
|
2011-11-27 09:35:53 -05:00
|
|
|
Collection<SxE> sxeVector2 = parse(o2);
|
|
|
|
if (sxeVector2 == null || sxeVector2.isEmpty())
|
|
|
|
return 0;
|
2014-04-07 02:00:14 -04: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) {
|
2013-02-21 02:42:29 -05:00
|
|
|
if (sxe1.season == sxe2.season && sxe1.episode == sxe2.episode && sxe1.season >= 0 && sxe2.season >= 0) {
|
|
|
|
// vectors have at least one perfect episode match in common (require season >= 0 as to put less trust in single-number matches)
|
2009-05-03 11:21:04 -04:00
|
|
|
return 1;
|
|
|
|
}
|
2014-04-07 02:00:14 -04:00
|
|
|
|
2012-03-17 23:43:38 -04:00
|
|
|
if ((sxe1.season >= 0 && sxe1.season == sxe2.season) || (sxe1.episode >= 0 && 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
|
|
|
}
|
2014-04-07 02:00:14 -04:00
|
|
|
|
2009-03-01 08:52:43 -05:00
|
|
|
return similarity;
|
2009-01-11 16:23:03 -05:00
|
|
|
}
|
2014-04-07 02:00:14 -04:00
|
|
|
|
2009-02-12 17:04:17 -05:00
|
|
|
protected Collection<SxE> parse(Object object) {
|
|
|
|
if (object instanceof File) {
|
2013-04-18 06:03:41 -04:00
|
|
|
return seasonEpisodeMatcher.match((File) object);
|
2009-02-12 17:04:17 -05:00
|
|
|
}
|
2014-04-07 02:00:14 -04:00
|
|
|
|
2009-02-12 17:04:17 -05:00
|
|
|
return seasonEpisodeMatcher.match(object.toString());
|
2009-01-11 16:23:03 -05:00
|
|
|
}
|
2014-04-07 02:00:14 -04:00
|
|
|
|
2009-01-11 16:23:03 -05:00
|
|
|
}
|