src.dackar.similarity.stringSimilarity¶
Lightweight, dependency-free string-similarity measures.
These are surface (lexical) measures that compare the characters or tokens of
two strings directly, with no linguistic resources. They complement the
WordNet/embedding measures elsewhere in dackar.similarity and make good
fallbacks when those heavier measures are unavailable.
Only the standard library is required.
Functions¶
|
Return the Jaccard index of the two strings' lowercased token sets. |
|
Return the Jaccard index of the two strings' character-trigram sets. |
Module Contents¶
- src.dackar.similarity.stringSimilarity.token_jaccard(text_a, text_b)[source]¶
Return the Jaccard index of the two strings’ lowercased token sets.
Tokens are whitespace-separated. Two empty strings are defined as fully similar (1.0); one empty and one non-empty are fully dissimilar (0.0).
- Parameters:
text_a (str)
text_b (str)
- Return type:
float
- src.dackar.similarity.stringSimilarity.trigram_jaccard(text_a, text_b)[source]¶
Return the Jaccard index of the two strings’ character-trigram sets.
Character trigrams give better recall than word Jaccard for short strings because they handle partial word matches (e.g. “calibr” in both “calibrate” and “calibration”) and minor typos (edit distance <= 1 on a trigram). Strings shorter than 3 characters are treated as a single “trigram” equal to the whole (lowercased) string.
- Parameters:
text_a (str)
text_b (str)
- Return type:
float