mirror of
https://github.com/mitb-archive/filebot
synced 2024-12-24 08:48:51 -05:00
* improved name cleanup a little bit
This commit is contained in:
parent
ae06df9312
commit
b4532f1832
@ -110,7 +110,7 @@ class EpisodeListMatcher implements AutoCompleteMatcher {
|
|||||||
|
|
||||||
private String normalizeName(String value) {
|
private String normalizeName(String value) {
|
||||||
// remove trailing braces, e.g. Doctor Who (2005) -> doctor who
|
// remove trailing braces, e.g. Doctor Who (2005) -> doctor who
|
||||||
return removeTrailingBraces(value).toLowerCase();
|
return removeTrailingBrackets(value).toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,8 +3,6 @@ package net.sourceforge.filebot.ui.rename;
|
|||||||
|
|
||||||
|
|
||||||
import static java.lang.Math.*;
|
import static java.lang.Math.*;
|
||||||
import static net.sourceforge.filebot.hash.VerificationUtilities.*;
|
|
||||||
import static net.sourceforge.filebot.web.EpisodeUtilities.*;
|
|
||||||
import static net.sourceforge.tuned.FileUtilities.*;
|
import static net.sourceforge.tuned.FileUtilities.*;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -104,8 +102,8 @@ public enum MatchSimilarityMetric implements SimilarityMetric {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getSimilarity(Object o1, Object o2) {
|
public float getSimilarity(Object o1, Object o2) {
|
||||||
String[] f1 = fields(o1);
|
String[] f1 = normalize(fields(o1));
|
||||||
String[] f2 = fields(o2);
|
String[] f2 = normalize(fields(o2));
|
||||||
|
|
||||||
// match all fields and average similarity
|
// match all fields and average similarity
|
||||||
float sum = 0;
|
float sum = 0;
|
||||||
@ -121,28 +119,38 @@ public enum MatchSimilarityMetric implements SimilarityMetric {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected String[] fields(Object object) {
|
protected String[] normalize(Object[] objects) {
|
||||||
|
String[] names = new String[objects.length];
|
||||||
|
|
||||||
|
for (int i = 0; i < objects.length; i++) {
|
||||||
|
names[i] = normalizeObject(objects[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected Object[] fields(Object object) {
|
||||||
if (object instanceof Episode) {
|
if (object instanceof Episode) {
|
||||||
Episode episode = (Episode) object;
|
Episode episode = (Episode) object;
|
||||||
return new String[] { removeTrailingBraces(episode.getSeriesName()), episode.getTitle() };
|
return new Object[] { episode.getSeriesName(), episode.getTitle() };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (object instanceof File) {
|
if (object instanceof File) {
|
||||||
File file = (File) object;
|
File file = (File) object;
|
||||||
return new String[] { getName(file.getParentFile()), getName(file) };
|
return new Object[] { file.getParentFile(), file };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (object instanceof Movie) {
|
if (object instanceof Movie) {
|
||||||
Movie movie = (Movie) object;
|
Movie movie = (Movie) object;
|
||||||
return new String[] { movie.getName(), Integer.toString(movie.getYear()) };
|
return new Object[] { movie.getName(), movie.getYear() };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (object instanceof AbstractFile) {
|
if (object instanceof AbstractFile) {
|
||||||
AbstractFile file = (AbstractFile) object;
|
return new Object[] { (AbstractFile) object };
|
||||||
return new String[] { getNameWithoutExtension(file.getName()) };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new String[] { object.toString() };
|
return new Object[] { object };
|
||||||
}
|
}
|
||||||
|
|
||||||
}),
|
}),
|
||||||
@ -161,7 +169,7 @@ public enum MatchSimilarityMetric implements SimilarityMetric {
|
|||||||
@Override
|
@Override
|
||||||
protected String normalize(Object object) {
|
protected String normalize(Object object) {
|
||||||
// simplify file name, if possible
|
// simplify file name, if possible
|
||||||
return super.normalize(normalizeFile(object));
|
return normalizeObject(object);
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
|
||||||
@ -171,7 +179,7 @@ public enum MatchSimilarityMetric implements SimilarityMetric {
|
|||||||
@Override
|
@Override
|
||||||
protected String normalize(Object object) {
|
protected String normalize(Object object) {
|
||||||
// simplify file name, if possible
|
// simplify file name, if possible
|
||||||
return super.normalize(normalizeFile(object));
|
return normalizeObject(object);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -190,7 +198,7 @@ public enum MatchSimilarityMetric implements SimilarityMetric {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected static String normalizeFile(Object object) {
|
protected static String normalizeObject(Object object) {
|
||||||
String name = object.toString();
|
String name = object.toString();
|
||||||
|
|
||||||
// use name without extension
|
// use name without extension
|
||||||
@ -200,8 +208,15 @@ public enum MatchSimilarityMetric implements SimilarityMetric {
|
|||||||
name = getNameWithoutExtension(((AbstractFile) object).getName());
|
name = getNameWithoutExtension(((AbstractFile) object).getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove embedded checksum from name, if any
|
// remove group names and checksums, any [...] or (...)
|
||||||
return removeEmbeddedChecksum(name);
|
name = name.replaceAll("\\([^\\(]*\\)", "");
|
||||||
|
name = name.replaceAll("\\[[^\\[]*\\]", "");
|
||||||
|
|
||||||
|
// remove/normalize special characters
|
||||||
|
name = name.replaceAll("['`´]+", "");
|
||||||
|
name = name.replaceAll("[\\p{Punct}\\p{Space}]+", " ");
|
||||||
|
|
||||||
|
return name.trim().toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ import java.util.List;
|
|||||||
|
|
||||||
public final class EpisodeUtilities {
|
public final class EpisodeUtilities {
|
||||||
|
|
||||||
public static String removeTrailingBraces(String name) {
|
public static String removeTrailingBrackets(String name) {
|
||||||
// remove trailing braces, e.g. Doctor Who (2005) -> Doctor Who
|
// remove trailing braces, e.g. Doctor Who (2005) -> Doctor Who
|
||||||
return name.replaceAll("[(]([^)]*)[)]", "").trim();
|
return name.replaceAll("[(]([^)]*)[)]", "").trim();
|
||||||
}
|
}
|
||||||
|
@ -123,7 +123,10 @@ class LocalSearch<T> {
|
|||||||
|
|
||||||
protected String normalize(String value) {
|
protected String normalize(String value) {
|
||||||
// normalize separator, normalize case and trim
|
// normalize separator, normalize case and trim
|
||||||
return value.replaceAll("[\\p{Punct}\\p{Space}]+", " ").trim().toLowerCase();
|
value = value.replaceAll("['`´]+", "");
|
||||||
|
value = value.replaceAll("[\\p{Punct}\\p{Space}]+", " ");
|
||||||
|
|
||||||
|
return value.trim().toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ public class MatchSimilarityMetricTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void normalizeFile() {
|
public void normalizeFile() {
|
||||||
assertEquals("abc", MatchSimilarityMetric.normalizeFile(new File("/folder/abc[EF62DF13].txt")));
|
assertEquals("abc", MatchSimilarityMetric.normalizeObject(new File("/folder/abc[EF62DF13].txt")));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user