make_levenshtein_ranker#

scikitplot.corpus.make_levenshtein_ranker(*, backend='auto', strict=False, use_normalized_text=True, score_cutoff=0.0)[source]#

Make a CustomRetrievalIndex ranker by Levenshtein similarity.

Parameters:
backendstr, default=”auto”

A backend of scikitplot.levenshtein.available_backends.

strictbool, default=False

Raise instead of falling back when backend is unavailable.

use_normalized_textbool, default=True

Compare with normalized_text when a document has one.

score_cutofffloat, default=0.0

Minimum normalised similarity in [0, 1]. config.top_k is an upper bound: a cutoff may return fewer hits.

Returns:
LevenshteinRanker
Raises:
ImportError

If scikitplot.levenshtein is not installed, or strict=True and backend is unavailable.

TypeError, ValueError

For an invalid argument, including an unknown backend name.

Parameters:
Return type:

LevenshteinRanker

See also

make_pairwise_ranker

Any pairwise function.

Notes

The backend name is checked here, and scikitplot.levenshtein.rank resolves it once per search, so an unavailable backend warns once per search rather than once per document.

Examples

>>> from scikitplot.corpus import (
...     CorpusDocument,
...     RetrievalConfig,
...     make_levenshtein_ranker,
... )
>>> ranker = make_levenshtein_ranker(backend="python", score_cutoff=0.5)
>>> docs = [
...     CorpusDocument.create("a.txt", 0, "colour"),
...     CorpusDocument.create("b.txt", 0, "cloud"),
... ]
>>> [
...     (hit.doc.text, hit.backend)
...     for hit in ranker("color", docs, RetrievalConfig(top_k=5))
... ]
[('colour', 'levenshtein:python')]