From b7f0529d88870cd9c47d2eac033c091a822a97b0 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sun, 22 Feb 2009 12:38:25 +0000 Subject: [PATCH] * find probable show using name similarity in auto-matching --- .../filebot/ui/panel/rename/RenamePanel.java | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/source/net/sourceforge/filebot/ui/panel/rename/RenamePanel.java b/source/net/sourceforge/filebot/ui/panel/rename/RenamePanel.java index 673faa45..115e7145 100644 --- a/source/net/sourceforge/filebot/ui/panel/rename/RenamePanel.java +++ b/source/net/sourceforge/filebot/ui/panel/rename/RenamePanel.java @@ -34,6 +34,8 @@ import net.miginfocom.swing.MigLayout; import net.sourceforge.filebot.ResourceManager; import net.sourceforge.filebot.Settings; import net.sourceforge.filebot.similarity.Match; +import net.sourceforge.filebot.similarity.NameSimilarityMetric; +import net.sourceforge.filebot.similarity.SimilarityMetric; import net.sourceforge.filebot.ui.FileBotPanel; import net.sourceforge.filebot.ui.SelectDialog; import net.sourceforge.filebot.web.AnidbClient; @@ -227,22 +229,25 @@ public class RenamePanel extends FileBotPanel { @Override - protected SearchResult selectSearchResult(String query, final Collection searchResults) throws Exception { + protected SearchResult selectSearchResult(final String query, final Collection searchResults) throws Exception { if (searchResults.size() == 1) { return searchResults.iterator().next(); } - List exactMatches = new LinkedList(); + List probableMatches = new LinkedList(); - // find exact matches + // use name similarity metric + SimilarityMetric metric = new NameSimilarityMetric(); + + // find probable matches using name similarity > 0.9 for (SearchResult result : searchResults) { - if (result.getName().toLowerCase().startsWith(query.toLowerCase())) { - exactMatches.add(result); + if (metric.getSimilarity(query, result.getName()) > 0.9) { + probableMatches.add(result); } } - if (exactMatches.size() == 1) { - return exactMatches.get(0); + if (probableMatches.size() == 1) { + return probableMatches.get(0); } // show selection dialog on EDT @@ -253,6 +258,8 @@ public class RenamePanel extends FileBotPanel { // multiple results have been found, user must select one SelectDialog selectDialog = new SelectDialog(SwingUtilities.getWindowAncestor(RenamePanel.this), searchResults); + selectDialog.getHeaderLabel().setText(String.format("Shows matching '%s':", query)); + selectDialog.setVisible(true); // selected value or null if the dialog was canceled by the user