(str1: str, str2: str)
return sklearn.metrics.pairwise.cosine_similarity(mat[0, :], mat[1, :]).item()
Measure the similarity between two strings using a character ngrams similarity
    metric, in which strings are transformed into trigrams of alnum-only characters,
    vectorized and weighted by tf-idf, then compared by cosine similarity.

    Args:
        str1
        str2

    Returns:
        Similarity between ``str1`` and ``str2`` in the interval [0.0, 1.0],
        where larger values correspond to more similar strings

    Note:
        This method has been used in cross-lingual plagiarism detection and
        authorship attribution, and seems to work better on longer texts.
        At the very least, it is *slow* on shorter texts relative to the other
        similarity measures.
Measure the similarity between two strings using a character ngrams similarity
    metric, in which strings are transformed into trigrams of alnum-only characters,
    vectorized and weighted by tf-idf, then compared by cosine similarity.
Measure the similarity between two strings using a character ngrams similarity metric in which strings are transformed into trigrams of alnum - only characters vectorized and weighted by tf - idf then compared by cosine similarity .
def character_ngrams(str1: str, str2: str) -> float:
    """
    Measure the similarity between two strings using a character ngrams similarity
    metric, in which strings are transformed into trigrams of alnum-only characters,
    vectorized and weighted by tf-idf, then compared by cosine similarity.

    Args:
        str1
        str2

    Returns:
        Similarity between ``str1`` and ``str2`` in the interval [0.0, 1.0],
        where larger values correspond to more similar strings

    Note:
        This method has been used in cross-lingual plagiarism detection and
        authorship attribution, and seems to work better on longer texts.
        At the very least, it is *slow* on shorter texts relative to the other
        similarity measures.
    """
    # TODO: figure out where this method falls -- not edit-based??
    vectorizer = sklearn.feature_extraction.text.TfidfVectorizer(
        preprocessor=lambda s: " ".join(constants.RE_ALNUM.findall(s.lower())),
        analyzer="char",
        token_pattern="(?u)\\b\\w+\\b",
        ngram_range=(3, 3),
    )
    mat = vectorizer.fit_transform([str1, str2])
    return sklearn.metrics.pairwise.cosine_similarity(mat[0, :], mat[1, :]).item()
def character_ngrams ( str1 : str , str2 : str ) -> float : # TODO: figure out where this method falls -- not edit-based?? vectorizer = sklearn . feature_extraction . text . TfidfVectorizer ( preprocessor = lambda s : " " . join ( constants . RE_ALNUM . findall ( s . lower ( ) ) ) , analyzer = "char" , token_pattern = "(?u)\\b\\w+\\b" , ngram_range = ( 3 , 3 ) , ) mat = vectorizer . fit_transform ( [ str1 , str2 ] ) return sklearn . metrics . pairwise . cosine_similarity ( mat [ 0 , : ] , mat [ 1 , : ] ) . item ( )