* fix for alias-aware matching
This commit is contained in:
parent
56424aafe1
commit
bd136671ff
|
@ -540,7 +540,7 @@ public class MediaDetection {
|
|||
try {
|
||||
Movie movie = (Movie) xattr.getObject();
|
||||
if (movie != null) {
|
||||
options.add(new Movie(movie)); // normalize as movie object
|
||||
options.add(movie.clone()); // normalize as movie object
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// can't read meta attributes => ignore
|
||||
|
|
|
@ -303,6 +303,8 @@ public enum EpisodeMetrics implements SimilarityMetric {
|
|||
}
|
||||
}),
|
||||
|
||||
NameBalancer(new MetricCascade(NameSubstringSequence, Name)),
|
||||
|
||||
// Match by generic name similarity (absolute)
|
||||
SeriesName(new NameSimilarityMetric() {
|
||||
|
||||
|
@ -539,7 +541,11 @@ public enum EpisodeMetrics implements SimilarityMetric {
|
|||
public float getSimilarity(Object o1, Object o2) {
|
||||
float r1 = getRating(o1);
|
||||
float r2 = getRating(o2);
|
||||
return max(r1, r2) >= 0.4 ? 1 : min(r1, r2) < 0 ? -1 : 0;
|
||||
|
||||
if (r1 < 0 || r2 < 0)
|
||||
return -1;
|
||||
|
||||
return max(r1, r2);
|
||||
}
|
||||
|
||||
private final Map<String, SeriesInfo> seriesInfoCache = new HashMap<String, SeriesInfo>();
|
||||
|
@ -561,12 +567,16 @@ public enum EpisodeMetrics implements SimilarityMetric {
|
|||
}
|
||||
|
||||
if (seriesInfo != null) {
|
||||
if (seriesInfo.getRatingCount() > 0) {
|
||||
float rating = max(0, seriesInfo.getRating().floatValue());
|
||||
return seriesInfo.getRatingCount() >= 15 ? rating : 0; // PENALIZE SHOWS WITH FEW RATINGS
|
||||
} else {
|
||||
return -1; // BIG PENALTY FOR SHOWS WITH 0 RATINGS
|
||||
if (seriesInfo.getRatingCount() >= 100) {
|
||||
return (float) floor(seriesInfo.getRating() / 3) + 1; // BOOST POPULAR SHOWS
|
||||
}
|
||||
if (seriesInfo.getRatingCount() >= 10) {
|
||||
return (float) floor(seriesInfo.getRating() / 3); // PUT INTO 3 GROUPS
|
||||
}
|
||||
if (seriesInfo.getRatingCount() >= 1) {
|
||||
return 0; // PENALIZE SHOWS WITH FEW RATINGS
|
||||
}
|
||||
return -1; // BIG PENALTY FOR SHOWS WITH 0 RATINGS
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
@ -642,7 +652,7 @@ public enum EpisodeMetrics implements SimilarityMetric {
|
|||
|
||||
// ignore everything else
|
||||
return emptyMap();
|
||||
};
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
@ -706,9 +716,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, AirDate, MetaAttributes, SubstringFields, new MetricCascade(NameSubstringSequence, Name), Numeric, NumericSequence, SeriesName, RegionHint, SeriesRating, TimeStamp, AbsolutePath };
|
||||
return new SimilarityMetric[] { FileSize, new MetricCascade(FileName, EpisodeFunnel), EpisodeBalancer, AirDate, MetaAttributes, SubstringFields, NameBalancer, Numeric, NumericSequence, SeriesName, RegionHint, SeriesRating, TimeStamp, AbsolutePath };
|
||||
} else {
|
||||
return new SimilarityMetric[] { EpisodeFunnel, EpisodeBalancer, AirDate, MetaAttributes, SubstringFields, new MetricCascade(NameSubstringSequence, Name), Numeric, NumericSequence, SeriesName, RegionHint, SeriesRating, TimeStamp, AbsolutePath };
|
||||
return new SimilarityMetric[] { EpisodeFunnel, EpisodeBalancer, AirDate, MetaAttributes, SubstringFields, NameBalancer, Numeric, NumericSequence, SeriesName, RegionHint, SeriesRating, TimeStamp, AbsolutePath };
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
|
||||
package net.sourceforge.filebot.similarity;
|
||||
|
||||
|
||||
import static java.util.Collections.*;
|
||||
|
||||
import java.util.AbstractList;
|
||||
|
@ -20,7 +18,6 @@ import java.util.Set;
|
|||
import java.util.SortedMap;
|
||||
import java.util.TreeMap;
|
||||
|
||||
|
||||
public class Matcher<V, C> {
|
||||
|
||||
protected final List<V> values;
|
||||
|
@ -31,7 +28,6 @@ public class Matcher<V, C> {
|
|||
|
||||
protected final DisjointMatchCollection<V, C> disjointMatchCollection;
|
||||
|
||||
|
||||
public Matcher(Collection<? extends V> values, Collection<? extends C> candidates, boolean strict, SimilarityMetric[] metrics) {
|
||||
this.values = new LinkedList<V>(values);
|
||||
this.candidates = new LinkedList<C>(candidates);
|
||||
|
@ -42,7 +38,6 @@ public class Matcher<V, C> {
|
|||
this.disjointMatchCollection = new DisjointMatchCollection<V, C>();
|
||||
}
|
||||
|
||||
|
||||
public synchronized List<Match<V, C>> match() throws InterruptedException {
|
||||
// list of all combinations of values and candidates
|
||||
List<Match<V, C>> possibleMatches = new ArrayList<Match<V, C>>(values.size() * candidates.size());
|
||||
|
@ -80,17 +75,14 @@ public class Matcher<V, C> {
|
|||
return result;
|
||||
}
|
||||
|
||||
|
||||
public synchronized List<V> remainingValues() {
|
||||
return Collections.unmodifiableList(values);
|
||||
}
|
||||
|
||||
|
||||
public synchronized List<C> remainingCandidates() {
|
||||
return Collections.unmodifiableList(candidates);
|
||||
}
|
||||
|
||||
|
||||
protected void deepMatch(Collection<Match<V, C>> possibleMatches, int level) throws InterruptedException {
|
||||
if (level >= metrics.length || possibleMatches.isEmpty()) {
|
||||
// add the first possible match if non-strict, otherwise ignore ambiguous matches
|
||||
|
@ -131,7 +123,6 @@ public class Matcher<V, C> {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
protected void removeCollected(Collection<Match<V, C>> matches) {
|
||||
for (Iterator<Match<V, C>> iterator = matches.iterator(); iterator.hasNext();) {
|
||||
if (!disjointMatchCollection.disjoint(iterator.next()))
|
||||
|
@ -139,7 +130,6 @@ public class Matcher<V, C> {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
protected SortedMap<Float, Set<Match<V, C>>> mapBySimilarity(Collection<Match<V, C>> possibleMatches, SimilarityMetric metric) throws InterruptedException {
|
||||
// map sorted by similarity descending
|
||||
SortedMap<Float, Set<Match<V, C>>> similarityMap = new TreeMap<Float, Set<Match<V, C>>>(Collections.reverseOrder());
|
||||
|
@ -167,7 +157,6 @@ public class Matcher<V, C> {
|
|||
return similarityMap;
|
||||
}
|
||||
|
||||
|
||||
protected List<Match<V, C>> disjointMatches(Collection<Match<V, C>> collection) {
|
||||
Map<V, List<Match<V, C>>> matchesByValue = new HashMap<V, List<Match<V, C>>>();
|
||||
Map<C, List<Match<V, C>>> matchesByCandidate = new HashMap<C, List<Match<V, C>>>();
|
||||
|
@ -208,7 +197,6 @@ public class Matcher<V, C> {
|
|||
return disjointMatches;
|
||||
}
|
||||
|
||||
|
||||
protected static class DisjointMatchCollection<V, C> extends AbstractList<Match<V, C>> {
|
||||
|
||||
private final List<Match<V, C>> matches = new ArrayList<Match<V, C>>();
|
||||
|
@ -216,7 +204,6 @@ public class Matcher<V, C> {
|
|||
private final Map<V, Match<V, C>> values = new IdentityHashMap<V, Match<V, C>>();
|
||||
private final Map<C, Match<V, C>> candidates = new IdentityHashMap<C, Match<V, C>>();
|
||||
|
||||
|
||||
@Override
|
||||
public boolean add(Match<V, C> match) {
|
||||
if (disjoint(match)) {
|
||||
|
@ -229,34 +216,28 @@ public class Matcher<V, C> {
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
public boolean disjoint(Match<V, C> match) {
|
||||
return !values.containsKey(match.getValue()) && !candidates.containsKey(match.getCandidate());
|
||||
}
|
||||
|
||||
|
||||
public Match<V, C> getByValue(V value) {
|
||||
return values.get(value);
|
||||
}
|
||||
|
||||
|
||||
public Match<V, C> getByCandidate(C candidate) {
|
||||
return candidates.get(candidate);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Match<V, C> get(int index) {
|
||||
return matches.get(index);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return matches.size();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
matches.clear();
|
||||
|
|
|
@ -16,10 +16,6 @@ public class Movie extends SearchResult {
|
|||
// used by serializer
|
||||
}
|
||||
|
||||
public Movie(Movie obj) {
|
||||
this(obj.name, obj.aliasNames, obj.year, obj.imdbId, obj.tmdbId);
|
||||
}
|
||||
|
||||
public Movie(String name, int year, int imdbId, int tmdbId) {
|
||||
this(name, new String[0], year, imdbId, tmdbId);
|
||||
}
|
||||
|
@ -90,7 +86,7 @@ public class Movie extends SearchResult {
|
|||
|
||||
@Override
|
||||
public Movie clone() {
|
||||
return new Movie(this);
|
||||
return new Movie(name, aliasNames, year, imdbId, tmdbId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -42,7 +42,7 @@ public class TheTVDBSearchResult extends SearchResult {
|
|||
|
||||
@Override
|
||||
public TheTVDBSearchResult clone() {
|
||||
return new TheTVDBSearchResult(name, seriesId);
|
||||
return new TheTVDBSearchResult(name, aliasNames, seriesId);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue