Overview
Comment: | [graphspell][py] suggestion: use Jaro-Winkler |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | graphspell | bdic_opt |
Files: | files | file ages | folders |
SHA3-256: |
7db21c89fd739ab350943e005913b071 |
User & Date: | olr on 2020-09-15 16:57:04 |
Other Links: | branch diff | manifest | tags |
Context
2020-09-15
| ||
17:04 | [fr] update suggest tests Closed-Leaf check-in: a8c66433af user: olr tags: fr, bdic_opt | |
16:57 | [graphspell][py] suggestion: use Jaro-Winkler check-in: 7db21c89fd user: olr tags: graphspell, bdic_opt | |
14:09 | [graphspell][js] str_transform: fix cleanWord() check-in: 2bfe79e9aa user: olr tags: graphspell, bdic_opt | |
Changes
Modified graphspell/char_player.py from [e2b351100d] to [24cf38a4cb].
1 2 3 4 5 6 7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + | """ List of similar chars useful for suggestion mechanism """ dDistanceBetweenChars = { # dDistanceBetweenChars: # - with Jaro-Winkler, values between 1 and 10 # - with Damerau-Levenshtein, values / 10 (between 0 and 1: 0.1, 0.2 ... 0.9) |
︙ | |||
313 314 315 316 317 318 319 | 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 | - - + + + + | # End of word dFinal1 = { "a": ("as", "at", "ant", "ah"), "A": ("AS", "AT", "ANT", "AH"), |
︙ |
Modified graphspell/ibdawg.py from [bda5a789eb] to [d672255b46].
︙ | |||
11 12 13 14 15 16 17 18 19 20 21 22 23 24 | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | + | import re from functools import wraps import time import json import binascii import importlib from collections import OrderedDict from math import floor #import logging #logging.basicConfig(filename="suggestions.log", level=logging.DEBUG) from . import str_transform as st from . import char_player as cp from .echo import echo |
︙ | |||
36 37 38 39 40 41 42 | 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | - + + - - - + + + + + + + + - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - + - - - - - - - + + + - - + - - - - + + + + + + + - + | return result return wrapper class SuggResult: """Structure for storing, classifying and filtering suggestions""" |
︙ | |||
318 319 320 321 322 323 324 | 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 | - + + - + | sSfx = "" if self.lexicographer: sPfx, sWord, sSfx = self.lexicographer.split(sWord) nMaxSwitch = max(len(sWord) // 3, 1) nMaxDel = len(sWord) // 5 nMaxHardRepl = max((len(sWord) - 5) // 4, 1) nMaxJump = max(len(sWord) // 4, 1) |
︙ |
Modified graphspell/str_transform.py from [e27e70d363] to [98c57fa9ba].
1 2 3 4 5 6 7 8 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | + - + | """ Operations on strings: - calculate distance between two strings - transform strings with transformation codes """ import unicodedata import re |
︙ | |||
48 49 50 51 52 53 54 55 56 57 58 59 60 61 | 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | + + + + + | sWord = sWord.lower().translate(_xTransCharsForSimplification) sNewWord = "" for i, c in enumerate(sWord, 1): if c != sWord[i:i+1] or (c == 'e' and sWord[i:i+2] != "ee"): # exception for <e> to avoid confusion between crée / créai sNewWord += c return sNewWord.replace("eau", "o").replace("au", "o").replace("ai", "éi").replace("ei", "é").replace("ph", "f") def cleanWord (sWord): "remove letters repeated more than 2 times" return re.sub("(.)\\1{2,}", '\\1\\1', sWord) _xTransNumbersToExponent = str.maketrans({ "0": "⁰", "1": "¹", "2": "²", "3": "³", "4": "⁴", "5": "⁵", "6": "⁶", "7": "⁷", "8": "⁸", "9": "⁹" }) def numbersToExponent (sWord): "convert numeral chars to exponant chars" |
︙ | |||
102 103 104 105 106 107 108 109 110 111 112 113 114 115 | 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | d[i, j-1] + 1, # Insertion d[i-1, j-1] + nCost, # Substitution ) if i and j and s1[i] == s2[j-1] and s1[i-1] == s2[j]: d[i, j] = min(d[i, j], d[i-2, j-2] + nCost) # Transposition return d[nLen1-1, nLen2-1] def distanceJaroWinkler (a, b, boost = .666): # https://github.com/thsig/jaro-winkler-JS #if (a == b): return 1.0 a_len = len(a) b_len = len(b) nMax = max(a_len, b_len) a_flag = [None for _ in range(nMax)] b_flag = [None for _ in range(nMax)] search_range = (max(a_len, b_len) // 2) - 1 minv = min(a_len, b_len) # Looking only within the search range, count and flag the matched pairs. Num_com = 0 yl1 = b_len - 1 for i in range(a_len): lowlim = i - search_range if i >= search_range else 0 hilim = i + search_range if (i + search_range) <= yl1 else yl1 for j in range(lowlim, hilim+1): if b_flag[j] != 1 and a[j:j+1] == b[i:i+1]: a_flag[j] = 1 b_flag[i] = 1 Num_com += 1 break # Return if no characters in common if Num_com == 0: return 0.0 # Count the number of transpositions k = 0 N_trans = 0 for i in range(a_len): if a_flag[i] == 1: for j in range(k, b_len): if b_flag[j] == 1: k = j + 1 break if a[i] != b[j]: N_trans += 1 N_trans = N_trans // 2 # Adjust for similarities in nonmatched characters N_simi = 0 if minv > Num_com: for i in range(a_len): if not a_flag[i]: for j in range(b_len): if not b_flag[j]: if a[i] in dDistanceBetweenChars and b[j] in dDistanceBetweenChars[a[i]]: N_simi += dDistanceBetweenChars[a[i]][b[j]] b_flag[j] = 2 break Num_sim = (N_simi / 10.0) + Num_com # Main weight computation weight = Num_sim / a_len + Num_sim / b_len + (Num_com - N_trans) / Num_com weight = weight / 3 # Continue to boost the weight if the strings are similar if weight > boost: # Adjust for having up to the first 4 characters in common j = 4 if minv >= 4 else minv i = 0 while i < j and a[i] == b[i]: i += 1 if i: weight += i * 0.1 * (1.0 - weight) # Adjust for long strings. # After agreeing beginning chars, at least two more must agree # and the agreeing characters must be more than half of the # remaining characters. if minv > 4 and Num_com > i + 1 and 2 * Num_com >= minv + i: weight += (1 - weight) * ((Num_com - i - 1) / (a_len * b_len - i*2 + 2)) return weight def distanceSift4 (s1, s2, nMaxOffset=5): "implementation of general Sift4." # https://siderite.blogspot.com/2014/11/super-fast-and-accurate-string-distance.html if not s1: return len(s2) if not s2: |
︙ |