Browse files

integrated fuzzywuzzy string matching.

  • Loading branch information...
1 parent 80b5d1d commit 711f494baef418a5e8d61ca848eefdb491af32be @MusikPolice committed Jul 14, 2012
Showing with 21 additions and 30 deletions.
  1. +5 −23 app.py
  2. +16 −7 music-cleanup.sublime-workspace
View
28 app.py
@@ -3,9 +3,9 @@
from distutils import dir_util
import os
import re
-from sys import exit
from collections import defaultdict
from difflib import SequenceMatcher
+from fuzzywuzzy import fuzz
# Interprets user response to a boolean query. Returns boolean flag for y/n/Y/N/yes/no/YES/NO
@@ -38,28 +38,10 @@ def CombineDirectoryContents (dirToKeep, dirToCopy):
return True
# returns true if string1 is like string2
-# if string1/string2 are paths, they MUST end with a trailing slash
+# utilizes fuzzywuzzy string matching library
+# TODO: make acceptance ratio configurable
def like(string1, string2):
- # both strings might be paths - find parent dir of each
- # this is next dir above current location - basically, the thing before the trailing slash
- tokens1 = os.path.dirname(path).split('/')
- tokens2 = os.path.dirname(path).split('/')
- folder1 = tokens1[len(tokens1) - 1]
- folder2 = tokens2[len(tokens2) - 1]
-
- # split parent folder name into tokens - each word will be considered individually
- tokens1 = string.split(tokens1, ' ')
- tokens2 = string.split(tokens2, ' ')
-
- accumulatedRatio = 1
-
- for t1 in tokens1:
- for t2 in tokens2:
- ratio = SequenceMatcher(None, t1, t2).ratio()
- if ratio > 0.8:
- accumulatedRatio *= ratio
-
- return accumulatedRatio > 0.8
+ return fuzz.partial_ratio(string1, string2) > 80
# a new approach that pre-computes the merges
@@ -88,7 +70,7 @@ def CombineSimilarlyNamedFolders2(dirsToCompare):
# if directory names are similar, mark for combination
if (like(dirsToCompare[i], dirsToCompare[j])):
- matches dirsToCompare[i]].append(dirsToCompare[j])
+ matches[dirsToCompare[i]].append(dirsToCompare[j])
skipdirs.append(dirsToCompare[j])
# do the combination in a (sort of) user-friendly manner
View
23 music-cleanup.sublime-workspace
@@ -8,10 +8,10 @@
"buffers":
[
{
- "file": "music-cleanup.py",
+ "file": "app.py",
"settings":
{
- "buffer_size": 16395,
+ "buffer_size": 15827,
"line_ending": "Unix"
}
}
@@ -40,6 +40,7 @@
},
"file_history":
[
+ "/home/jfritz/Desktop/Storage/Documents/Jonathan/git/MusicDirCleanup/music-cleanup.py"
],
"find":
{
@@ -79,18 +80,18 @@
[
{
"buffer": 0,
- "file": "music-cleanup.py",
+ "file": "app.py",
"settings":
{
- "buffer_size": 16395,
+ "buffer_size": 15827,
"regions":
{
},
"selection":
[
[
- 1656,
- 1656
+ 2286,
+ 2286
]
],
"settings":
@@ -99,7 +100,7 @@
"translate_tabs_to_spaces": false
},
"translation.x": 0.0,
- "translation.y": 510.0,
+ "translation.y": 824.0,
"zoom_level": 1.0
},
"type": "text"
@@ -138,6 +139,10 @@
]
},
"menu_visible": true,
+ "output.exec":
+ {
+ "height": 112.0
+ },
"replace":
{
"height": 0.0
@@ -148,6 +153,10 @@
"height": 0.0,
"selected_items":
[
+ [
+ "app",
+ "app.py"
+ ]
],
"width": 0.0
},

0 comments on commit 711f494

Please sign in to comment.