make_levenshtein_ranker#
- scikitplot.corpus.make_levenshtein_ranker(*, backend='auto', strict=False, use_normalized_text=True, score_cutoff=0.0)[source]#
Make a
CustomRetrievalIndexranker by Levenshtein similarity.- Parameters:
- backendstr, default=”auto”
A backend of
scikitplot.levenshtein.available_backends.- strictbool, default=False
Raise instead of falling back when
backendis unavailable.- use_normalized_textbool, default=True
Compare with
normalized_textwhen a document has one.- score_cutofffloat, default=0.0
Minimum normalised similarity in [0, 1].
config.top_kis an upper bound: a cutoff may return fewer hits.
- Returns:
- LevenshteinRanker
- Raises:
- ImportError
If
scikitplot.levenshteinis not installed, orstrict=Trueandbackendis unavailable.- TypeError, ValueError
For an invalid argument, including an unknown backend name.
- Parameters:
- Return type:
See also
make_pairwise_rankerAny pairwise function.
Notes
The backend name is checked here, and
scikitplot.levenshtein.rankresolves 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')]