1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-11-16 06:15:02 -05:00

* make auto-selection aware of alias titles

This commit is contained in:
Reinhard Pointner 2013-12-02 14:41:15 +00:00
parent b4dd50b73b
commit f89ee90f72
2 changed files with 26 additions and 16 deletions

View File

@ -1019,6 +1019,31 @@ public class MediaDetection {
return new Movie(info.getName(), info.getReleased().getYear(), info.getImdbId(), info.getId()); return new Movie(info.getName(), info.getReleased().getYear(), info.getImdbId(), info.getId());
} }
public static List<SearchResult> getProbableMatches(String query, Collection<SearchResult> options) {
// auto-select most probable search result
List<SearchResult> probableMatches = new LinkedList<SearchResult>();
// use name similarity metric
SimilarityMetric metric = new NameSimilarityMetric();
float threshold = 0.85f;
// remove trailing braces, e.g. Doctor Who (2005) -> Doctor Who
query = removeTrailingBrackets(query);
// find probable matches using name similarity >= 0.85
for (SearchResult option : options) {
float f = 0;
for (String n : option.getEffectiveNames()) {
f = Math.max(f, metric.getSimilarity(query, removeTrailingBrackets(n)));
}
if (f >= threshold) {
probableMatches.add(option);
}
}
return probableMatches;
}
/* /*
* Heavy-duty name matcher used for matching a file to or more movies (out of a list of ~50k) * Heavy-duty name matcher used for matching a file to or more movies (out of a list of ~50k)
*/ */

View File

@ -4,7 +4,6 @@ import static java.util.Collections.*;
import static net.sourceforge.filebot.MediaTypes.*; import static net.sourceforge.filebot.MediaTypes.*;
import static net.sourceforge.filebot.Settings.*; import static net.sourceforge.filebot.Settings.*;
import static net.sourceforge.filebot.media.MediaDetection.*; import static net.sourceforge.filebot.media.MediaDetection.*;
import static net.sourceforge.filebot.similarity.Normalization.*;
import static net.sourceforge.tuned.FileUtilities.*; import static net.sourceforge.tuned.FileUtilities.*;
import static net.sourceforge.tuned.StringUtilities.*; import static net.sourceforge.tuned.StringUtilities.*;
import static net.sourceforge.tuned.ui.TunedUtilities.*; import static net.sourceforge.tuned.ui.TunedUtilities.*;
@ -18,7 +17,6 @@ import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
@ -42,8 +40,6 @@ import net.sourceforge.filebot.Settings;
import net.sourceforge.filebot.similarity.CommonSequenceMatcher; import net.sourceforge.filebot.similarity.CommonSequenceMatcher;
import net.sourceforge.filebot.similarity.EpisodeMatcher; import net.sourceforge.filebot.similarity.EpisodeMatcher;
import net.sourceforge.filebot.similarity.Match; import net.sourceforge.filebot.similarity.Match;
import net.sourceforge.filebot.similarity.NameSimilarityMetric;
import net.sourceforge.filebot.similarity.SimilarityMetric;
import net.sourceforge.filebot.ui.SelectDialog; import net.sourceforge.filebot.ui.SelectDialog;
import net.sourceforge.filebot.web.Episode; import net.sourceforge.filebot.web.Episode;
import net.sourceforge.filebot.web.EpisodeListProvider; import net.sourceforge.filebot.web.EpisodeListProvider;
@ -67,18 +63,7 @@ class EpisodeListMatcher implements AutoCompleteMatcher {
} }
// auto-select most probable search result // auto-select most probable search result
List<SearchResult> probableMatches = new LinkedList<SearchResult>(); List<SearchResult> probableMatches = getProbableMatches(query, searchResults);
// use name similarity metric
SimilarityMetric metric = new NameSimilarityMetric();
// find probable matches using name similarity >= 0.85
for (SearchResult result : searchResults) {
// remove trailing braces, e.g. Doctor Who (2005) -> Doctor Who
if (metric.getSimilarity(removeTrailingBrackets(query), removeTrailingBrackets(result.getName())) >= 0.85) {
probableMatches.add(result);
}
}
// auto-select first and only probable search result // auto-select first and only probable search result
if (probableMatches.size() == 1) { if (probableMatches.size() == 1) {