Reference

Scoring and best match picking.

single(value, argument)

Get the best matcher ratio of the two values.

>>> single('alpha', 'theta')
0.4
specific(values, argument, key=str.lower)

Get (value, score) pairs for values against the argument.

>>> values = ('aplha', 'beta', 'gamma')
>>> pairs = specific(values, 'theta')
>>> tuple(pairs) # generator
(('aplha', 0.4), ('beta', 0.6), ('gamma', 0.2))
multiple(values, argument, key=str.lower)

Get the highest best score against the argument.

>>> values = ('aplha', 'beta', 'gamma')
>>> multiple(values, 'theta')
0.6
generic(fetch, values, argument, key=str.lower)

Get (value, score) pairs for value’s attributes against argument.

>>> animals = [
>>>     {'name': 'husky', 'type': 'dog', 'colors': ['white', 'grey']},
>>>     {'name': 'ocelot', 'type': 'cat', 'colors': ['gold', 'black']},
>>>     {'name': 'flamingo', 'type': 'bird', 'colors': ['pink']},
>>>     # ...
>>> ]
>>> naty = lambda animal: (animal['name'], animal['type'])
>>> pairs = generic(naty, animals, 'ligon')
>>> tuple(pairs) # generator
(
    ({'name': 'husky', ...}, 0.25),
    ({'name': 'ocelot', ...}, 0.36),
    ({'name': 'flamingo', ...}, 0.61)
)
lead(pairs, quick=True)

Get the highest scored pair.

>>> # ...
>>> lead(pairs)
({'name': 'flamingo', ...}, 0.61)
pick(values, argument, fetch=None, key=str.lower, score=False)

Get the best value matching the argument. If fetch is used, attribute search commences.

>>> # ...
>>> pick(animals, 'ligon', fetch = naty)
{'name': 'flamingo', ...}
>>> pick(animals, 'letc', fetch = naty, score = True)
({'name', 'ocelot', ...}, 0.4)# include score