code: 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()
  
file_path: textacy/src/textacy/similarity/edits.py
imports: from __future__ import annotations
  from typing import Optional
  import sklearn.feature_extraction
  import sklearn.metrics
  from jellyfish import hamming_distance
  from jellyfish import jaro_similarity
  from jellyfish import levenshtein_distance
  from ..None import constants
label_desc: Use image node_id 5 for calling a global function with example usage: character_ngrams(str1, str2) and returns: sklearn