* move all matching/metrics code into the same package

This commit is contained in:
Reinhard Pointner 2011-11-23 10:52:46 +00:00
parent c2836413ef
commit c45b6dfbd0
8 changed files with 52 additions and 59 deletions

View File

@ -42,15 +42,16 @@ import net.sourceforge.filebot.format.MediaBindingBean;
import net.sourceforge.filebot.hash.HashType;
import net.sourceforge.filebot.hash.VerificationFileReader;
import net.sourceforge.filebot.hash.VerificationFileWriter;
import net.sourceforge.filebot.similarity.EpisodeMetrics;
import net.sourceforge.filebot.similarity.Match;
import net.sourceforge.filebot.similarity.Matcher;
import net.sourceforge.filebot.similarity.NameSimilarityMetric;
import net.sourceforge.filebot.similarity.SeriesNameMatcher;
import net.sourceforge.filebot.similarity.SimilarityMetric;
import net.sourceforge.filebot.similarity.StrictEpisodeMetrics;
import net.sourceforge.filebot.subtitle.SubtitleFormat;
import net.sourceforge.filebot.ui.Language;
import net.sourceforge.filebot.ui.rename.HistorySpooler;
import net.sourceforge.filebot.ui.rename.MatchSimilarityMetric;
import net.sourceforge.filebot.vfs.ArchiveType;
import net.sourceforge.filebot.vfs.MemoryFile;
import net.sourceforge.filebot.web.Episode;
@ -145,12 +146,7 @@ public class CmdlineOperations implements CmdlineInterface {
}
// similarity metrics for matching
SimilarityMetric[] sequence;
if (strict) {
sequence = new SimilarityMetric[] { StrictMetric.EpisodeIdentifier, StrictMetric.SubstringFields, StrictMetric.Name }; // use SEI for matching and SN for excluding false positives
} else {
sequence = MatchSimilarityMetric.defaultSequence(false); // same as in GUI
}
SimilarityMetric[] sequence = strict ? StrictEpisodeMetrics.defaultSequence() : EpisodeMetrics.defaultSequence(false);
List<Match<File, Episode>> matches = new ArrayList<Match<File, Episode>>();
matches.addAll(match(filter(mediaFiles, VIDEO_FILES), episodes, sequence));

View File

@ -1,33 +0,0 @@
package net.sourceforge.filebot.cli;
import static java.lang.Math.*;
import net.sourceforge.filebot.similarity.SimilarityMetric;
import net.sourceforge.filebot.ui.rename.MatchSimilarityMetric;
public enum StrictMetric implements SimilarityMetric {
EpisodeIdentifier(MatchSimilarityMetric.EpisodeIdentifier, 1), // only allow 0 or 1
SubstringFields(MatchSimilarityMetric.SubstringFields, 2), // allow 0 or .5 or 1
Name(MatchSimilarityMetric.Name, 2); // allow 0 or .5 or 1
// inner metric
private final SimilarityMetric metric;
private final float floorFactor;
private StrictMetric(SimilarityMetric metric, float floorFactor) {
this.metric = metric;
this.floorFactor = floorFactor;
}
@Override
public float getSimilarity(Object o1, Object o2) {
return (float) (floor(metric.getSimilarity(o1, o2) * floorFactor) / floorFactor);
}
}

View File

@ -1,5 +1,5 @@
package net.sourceforge.filebot.ui.rename;
package net.sourceforge.filebot.similarity;
import static java.lang.Math.*;
@ -13,14 +13,6 @@ import java.util.Collection;
import java.util.Map;
import java.util.WeakHashMap;
import net.sourceforge.filebot.similarity.DateMetric;
import net.sourceforge.filebot.similarity.FileSizeMetric;
import net.sourceforge.filebot.similarity.MetricCascade;
import net.sourceforge.filebot.similarity.NameSimilarityMetric;
import net.sourceforge.filebot.similarity.NumericSimilarityMetric;
import net.sourceforge.filebot.similarity.SeasonEpisodeMetric;
import net.sourceforge.filebot.similarity.SimilarityMetric;
import net.sourceforge.filebot.similarity.SubstringMetric;
import net.sourceforge.filebot.similarity.SeasonEpisodeMatcher.SxE;
import net.sourceforge.filebot.vfs.AbstractFile;
import net.sourceforge.filebot.web.Date;
@ -28,7 +20,7 @@ import net.sourceforge.filebot.web.Episode;
import net.sourceforge.filebot.web.Movie;
public enum MatchSimilarityMetric implements SimilarityMetric {
public enum EpisodeMetrics implements SimilarityMetric {
// Match by season / episode numbers
SeasonEpisode(new SeasonEpisodeMetric() {
@ -233,7 +225,7 @@ public enum MatchSimilarityMetric implements SimilarityMetric {
private final SimilarityMetric metric;
private MatchSimilarityMetric(SimilarityMetric metric) {
private EpisodeMetrics(SimilarityMetric metric) {
this.metric = metric;
}

View File

@ -0,0 +1,35 @@
package net.sourceforge.filebot.similarity;
import static java.lang.Math.*;
public enum StrictEpisodeMetrics implements SimilarityMetric {
EpisodeIdentifier(EpisodeMetrics.EpisodeIdentifier, 1), // only allow 0 or 1
SubstringFields(EpisodeMetrics.SubstringFields, 2), // allow 0 or .5 or 1
Name(EpisodeMetrics.Name, 2); // allow 0 or .5 or 1
// inner metric
private final SimilarityMetric metric;
private final float floorFactor;
private StrictEpisodeMetrics(SimilarityMetric metric, float floorFactor) {
this.metric = metric;
this.floorFactor = floorFactor;
}
@Override
public float getSimilarity(Object o1, Object o2) {
return (float) (floor(metric.getSimilarity(o1, o2) * floorFactor) / floorFactor);
}
public static SimilarityMetric[] defaultSequence() {
// use SEI for matching and SN for excluding false positives
return new SimilarityMetric[] { StrictEpisodeMetrics.EpisodeIdentifier, StrictEpisodeMetrics.SubstringFields, StrictEpisodeMetrics.Name };
}
}

View File

@ -31,6 +31,7 @@ import javax.swing.Action;
import javax.swing.SwingUtilities;
import net.sourceforge.filebot.Analytics;
import net.sourceforge.filebot.similarity.EpisodeMetrics;
import net.sourceforge.filebot.similarity.Match;
import net.sourceforge.filebot.similarity.Matcher;
import net.sourceforge.filebot.similarity.NameSimilarityMetric;
@ -192,7 +193,7 @@ class EpisodeListMatcher implements AutoCompleteMatcher {
// group by subtitles first and then by files in general
for (List<File> filesPerType : mapByExtension(mediaFiles).values()) {
Matcher<File, Episode> matcher = new Matcher<File, Episode>(filesPerType, episodes, false, MatchSimilarityMetric.defaultSequence(false));
Matcher<File, Episode> matcher = new Matcher<File, Episode>(filesPerType, episodes, false, EpisodeMetrics.defaultSequence(false));
matches.addAll(matcher.match());
}

View File

@ -20,6 +20,7 @@ import javax.swing.Icon;
import javax.swing.SwingWorker;
import net.sourceforge.filebot.ResourceManager;
import net.sourceforge.filebot.similarity.EpisodeMetrics;
import net.sourceforge.filebot.similarity.Match;
import net.sourceforge.filebot.similarity.Matcher;
import net.sourceforge.filebot.similarity.SimilarityMetric;
@ -49,7 +50,7 @@ class MatchAction extends AbstractAction {
Window window = getWindow(evt.getSource());
window.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
BackgroundMatcher backgroundMatcher = new BackgroundMatcher(model, MatchSimilarityMetric.defaultSequence(true));
BackgroundMatcher backgroundMatcher = new BackgroundMatcher(model, EpisodeMetrics.defaultSequence(true));
backgroundMatcher.execute();
try {

View File

@ -9,15 +9,15 @@ import org.junit.runners.Suite.SuiteClasses;
import net.sourceforge.filebot.format.ExpressionFormatTest;
import net.sourceforge.filebot.hash.VerificationFormatTest;
import net.sourceforge.filebot.mediainfo.ReleaseInfoTest;
import net.sourceforge.filebot.similarity.EpisodeMetricsTest;
import net.sourceforge.filebot.similarity.SimilarityTestSuite;
import net.sourceforge.filebot.subtitle.SubtitleReaderTestSuite;
import net.sourceforge.filebot.ui.rename.MatchModelTest;
import net.sourceforge.filebot.ui.rename.MatchSimilarityMetricTest;
import net.sourceforge.filebot.web.WebTestSuite;
@RunWith(Suite.class)
@SuiteClasses( { SimilarityTestSuite.class, WebTestSuite.class, ExpressionFormatTest.class, VerificationFormatTest.class, MatchModelTest.class, MatchSimilarityMetricTest.class, SubtitleReaderTestSuite.class, ReleaseInfoTest.class })
@SuiteClasses( { SimilarityTestSuite.class, WebTestSuite.class, ExpressionFormatTest.class, VerificationFormatTest.class, MatchModelTest.class, EpisodeMetricsTest.class, SubtitleReaderTestSuite.class, ReleaseInfoTest.class })
public class FileBotTestSuite {
}

View File

@ -1,8 +1,8 @@
package net.sourceforge.filebot.ui.rename;
package net.sourceforge.filebot.similarity;
import static net.sourceforge.filebot.ui.rename.MatchSimilarityMetric.*;
import static net.sourceforge.filebot.similarity.EpisodeMetrics.*;
import static org.junit.Assert.*;
import java.io.File;
@ -11,6 +11,7 @@ import java.util.List;
import org.junit.Test;
import net.sourceforge.filebot.similarity.EpisodeMetrics;
import net.sourceforge.filebot.similarity.Match;
import net.sourceforge.filebot.similarity.Matcher;
import net.sourceforge.filebot.similarity.SimilarityMetric;
@ -18,7 +19,7 @@ import net.sourceforge.filebot.web.Date;
import net.sourceforge.filebot.web.Episode;
public class MatchSimilarityMetricTest {
public class EpisodeMetricsTest {
@Test
public void substringMetrics() {
@ -46,7 +47,7 @@ public class MatchSimilarityMetricTest {
@Test
public void normalizeFile() {
assertEquals("abc", MatchSimilarityMetric.normalizeObject(new File("/folder/abc[EF62DF13].txt")));
assertEquals("abc", EpisodeMetrics.normalizeObject(new File("/folder/abc[EF62DF13].txt")));
}