* fine-tune seriesName/aliasNames based matching

This commit is contained in:
Reinhard Pointner 2015-01-18 08:57:37 +00:00
parent 6315ea9c05
commit 9b0806f01f
6 changed files with 40 additions and 17 deletions

View File

@ -17,6 +17,7 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
@ -1011,17 +1012,21 @@ public class MediaBindingBean {
}
private List<String> getKeywords() {
List<Object> keys = new ArrayList<Object>();
// collect key information
Set<Object> keys = new HashSet<Object>();
keys.add(getName());
keys.add(getYear());
keys.addAll(getAliasNames());
if (infoObject instanceof Episode) {
for (Episode it : getEpisodes()) {
keys.addAll(it.getSeriesNames());
keys.add(it.getTitle());
}
}
List<String> words = new ArrayList<String>();
// word list for exclude pattern
List<String> words = new ArrayList<String>(keys.size());
for (Object it : keys) {
String w = normalizePunctuation(normalizeSpace(Objects.toString(it, ""), " "));
if (w != null && w.length() > 0) {

View File

@ -207,10 +207,10 @@ public enum EpisodeMetrics implements SimilarityMetric {
protected Object[] fields(Object object) {
if (object instanceof Episode) {
Episode episode = (Episode) object;
LinkedHashSet<String> keywords = new LinkedHashSet<String>(4);
Set<String> keywords = new LinkedHashSet<String>();
keywords.add(removeTrailingBrackets(episode.getSeriesName()));
keywords.add(removeTrailingBrackets(episode.getTitle()));
for (String it : episode.getSeriesInfo().getAliasNames()) {
for (String it : episode.getSeriesNames()) {
keywords.add(removeTrailingBrackets(it));
}
@ -275,7 +275,7 @@ public enum EpisodeMetrics implements SimilarityMetric {
protected List<?> getEffectiveIdentifiers(Object object) {
if (object instanceof Episode) {
return ((Episode) object).getSeriesInfo().getAliasNames();
return ((Episode) object).getSeriesNames();
} else if (object instanceof Movie) {
return ((Movie) object).getEffectiveNames();
} else if (object instanceof File) {
@ -344,7 +344,7 @@ public enum EpisodeMetrics implements SimilarityMetric {
List<String> names = null;
if (object instanceof Episode) {
names = ((Episode) object).getSeriesInfo().getAliasNames();
names = ((Episode) object).getSeriesNames();
} else if (object instanceof File) {
File file = (File) object;
@ -594,9 +594,11 @@ public enum EpisodeMetrics implements SimilarityMetric {
public Set<String> getHint(Object o) {
if (o instanceof Episode) {
Matcher m = hint.matcher(((Episode) o).getSeriesName());
if (m.find()) {
return singleton(m.group(1).trim().toLowerCase());
for (String sn : ((Episode) o).getSeriesNames()) {
Matcher m = hint.matcher(sn);
if (m.find()) {
return singleton(m.group(1).trim().toLowerCase());
}
}
} else if (o instanceof File) {
Set<String> h = new HashSet<String>();
@ -605,7 +607,6 @@ public enum EpisodeMetrics implements SimilarityMetric {
String n = f.getName();
String sn = seriesNameMatcher.matchByEpisodeIdentifier(n);
// tokenize
String[] tokens = punctuation.split(sn != null ? sn : n);
for (String s : tokens) {
if (s.length() > 0) {

View File

@ -169,7 +169,7 @@ public class AnidbClient extends AbstractEpisodeListProvider {
}
// make sure episodes are in ordered correctly
sortEpisodes(episodes);
sort(episodes, episodeComparator());
// sanity check
if (episodes.isEmpty()) {

View File

@ -1,8 +1,11 @@
package net.filebot.web;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
public class Episode implements Serializable {
@ -82,6 +85,24 @@ public class Episode implements Serializable {
return Arrays.asList(season, episode, special);
}
public List<String> getSeriesNames() {
Set<String> names = new LinkedHashSet<String>();
if (seriesName != null) {
names.add(seriesName);
}
if (seriesInfo != null) {
if (seriesInfo.name != null) {
names.add(seriesInfo.name);
}
if (seriesInfo.aliasNames != null) {
for (String it : seriesInfo.aliasNames) {
names.add(it);
}
}
}
return new ArrayList<String>(names);
}
@Override
public boolean equals(Object obj) {
if (obj instanceof Episode) {

View File

@ -1,7 +1,6 @@
package net.filebot.web;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
@ -33,10 +32,6 @@ public final class EpisodeUtilities {
return lastSeason;
}
public static void sortEpisodes(List<Episode> episodes) {
Collections.sort(episodes, episodeComparator());
}
public static Comparator<Episode> episodeComparator() {
return new Comparator<Episode>() {

View File

@ -1,6 +1,7 @@
package net.filebot.web;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static net.filebot.util.XPathUtilities.*;
import static net.filebot.web.EpisodeUtilities.*;
import static net.filebot.web.WebRequest.*;
@ -209,7 +210,7 @@ public class TheTVDBClient extends AbstractEpisodeListProvider {
}
// episodes my not be ordered by DVD episode number
sortEpisodes(episodes);
sort(episodes, episodeComparator());
// add specials at the end
episodes.addAll(specials);