Permalink
Browse files

report better ratio()s

redundant import try
  • Loading branch information...
medecau committed Jun 6, 2012
1 parent 916983a commit dbcbdffdbc67c7c637ddcb6b99dbe45abccaf61d
Showing with 13 additions and 12 deletions.
  1. +10 −11 fuzzywuzzy/fuzz.py
  2. +3 −1 fuzzywuzzy/utils.py
View
@@ -28,10 +28,9 @@
import sys
import os
import re
-import utils
+from utils import *
try:
- import Levenshtein
from StringMatcher import StringMatcher as SequenceMatcher
except:
from difflib import SequenceMatcher
@@ -48,7 +47,7 @@ def ratio(s1, s2):
if s2 is None: raise TypeError("s2 is None")
m = SequenceMatcher(None, s1, s2)
- return int(100 * m.ratio())
+ return intr(100 * m.ratio())
# todo: skip duplicate indexes for a little more speed
def partial_ratio(s1, s2):
@@ -178,20 +177,20 @@ def partial_token_set_ratio(s1, s2):
# q is for quick
def QRatio(s1, s2):
- if not utils.validate_string(s1): return 0
- if not utils.validate_string(s2): return 0
+ if not validate_string(s1): return 0
+ if not validate_string(s2): return 0
- p1 = utils.full_process(s1)
- p2 = utils.full_process(s2)
+ p1 = full_process(s1)
+ p2 = full_process(s2)
return ratio(p1, p2)
# w is for weighted
def WRatio(s1, s2):
- p1 = utils.full_process(s1)
- p2 = utils.full_process(s2)
- if not utils.validate_string(p1): return 0
- if not utils.validate_string(p2): return 0
+ p1 = full_process(s1)
+ p2 = full_process(s2)
+ if not validate_string(p1): return 0
+ if not validate_string(p2): return 0
# should we look at partials?
try_partial = True
View
@@ -33,6 +33,8 @@ def full_process(s):
s = asciidammit(s)
return s.translate(trans_table, bad_chars).strip()
-
+def intr(n):
+ '''Returns a correctly rounded integer'''
+ return int(round(n))

0 comments on commit dbcbdff

Please sign in to comment.