Skip to main content

Module textsim

Module textsim 

Source
Expand description

Python’s difflib — Ratcliff/Obershelp similarity and get_close_matches.

The scanner’s near-miss cutoff (0.72) is a behavioural boundary, so the ratio has to agree with CPython to the last digit rather than merely be “a similarity measure”. This is a direct transcription of SequenceMatcher, not an equivalent algorithm.

Autojunk is on, as it is by default in CPython: once b reaches 200 elements, any element occurring more than len(b) // 100 + 1 times is dropped from the index. That rarely touches a scanner tag but decides the score of a long line of dialogue (0.295 with it, 0.873 without, for one pair of 220-character sentences).

Structs§

SequenceMatcher
difflib.SequenceMatcher(None, a, b) over character sequences.

Functions§

get_close_matches
difflib.get_close_matches(word, possibilities, n, cutoff).