src.dackar.similarity.stringSimilarity ====================================== .. py:module:: src.dackar.similarity.stringSimilarity .. autoapi-nested-parse:: 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 :mod:`dackar.similarity` and make good fallbacks when those heavier measures are unavailable. Only the standard library is required. Functions --------- .. autoapisummary:: src.dackar.similarity.stringSimilarity.token_jaccard src.dackar.similarity.stringSimilarity.trigram_jaccard Module Contents --------------- .. py:function:: token_jaccard(text_a, text_b) 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). .. py:function:: trigram_jaccard(text_a, text_b) 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.