Skip to content

Commit

Permalink
Made it so that word matches make for a reduction in ambiguity, so 'A…
Browse files Browse the repository at this point in the history
…ulin' doesnt match PAULING
  • Loading branch information
kfsone committed Oct 7, 2014
1 parent 80aab11 commit a643881
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion tradedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,16 @@ def listSearch(listType, lookup, values, key=lambda item: item, val=lambda item:
if normVal == needle:
return val(entry)
if matchVal and matchVal != val(entry):
raise AmbiguityError(listType, lookup, matchKey, entryKey)
# Check if one match matches a whole word and prefer that.
wordStr = r'\b{}\b'.format(lookup)
wordRe = re.compile(wordStr, re.IGNORECASE)
prevWholeWord = wordRe.match(matchKey)
newWholeWord = wordRe.match(entryKey)
print("%s %s %s / %s" % (wordStr, wordRe, prevWholeWord, newWholeWord))
if prevWholeWord:
if not newWholeWord:
continue
raise AmbiguityError(listType, lookup, matchKey, entryKey)
matchKey, matchVal = entryKey, val(entry)
if not matchKey:
raise LookupError("Error: '%s' doesn't match any %s" % (lookup, listType))
Expand Down

0 comments on commit a643881

Please sign in to comment.