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

View File

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

View File

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

View File

@ -1,8 +1,11 @@
package net.filebot.web; package net.filebot.web;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Set;
public class Episode implements Serializable { public class Episode implements Serializable {
@ -82,6 +85,24 @@ public class Episode implements Serializable {
return Arrays.asList(season, episode, special); 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 @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (obj instanceof Episode) { if (obj instanceof Episode) {

View File

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

View File

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