(
    doc_or_tokens: types.DocOrTokens,
    variant: Literal["standard", "root", "corrected"] = "standard",
)
Compute the Type-Token Ratio (TTR) of ``doc_or_tokens``,
    a direct ratio of the number of unique words (types) to all words (tokens).

    Higher values indicate higher lexical diversity.

    Args:
        doc_or_tokens: If a spaCy ``Doc``, non-punctuation tokens (words) are extracted;
            if an iterable of spaCy ``Token`` s, all non-punct elements are used.
        variant: Particular variant of TTR.
            - "standard" => ``n_types / n_words``
            - "root" => ``n_types / sqrt(n_words)``
            - "corrected" => ``n_types / sqrt(2 * n_words)``

    Note:
        All variants of this measure are sensitive to document length,
        so values from texts with different lengths should not be compared.

    References:
        - Templin, M. (1957). Certain language skills in children. Minneapolis:
          University of Minnesota Press.
        - RTTR: Guiraud 1954, 1960
        - CTTR: 1964 Carrol
Compute the Type-Token Ratio (TTR) of ``doc_or_tokens``,
    a direct ratio of the number of unique words (types) to all words (tokens).
Compute the Type - Token Ratio ( TTR ) of doc_or_tokens a direct ratio of the number of unique words ( types ) to all words ( tokens ) .
def ttr(
    doc_or_tokens: types.DocOrTokens,
    variant: Literal["standard", "root", "corrected"] = "standard",
) -> float:
    """
    Compute the Type-Token Ratio (TTR) of ``doc_or_tokens``,
    a direct ratio of the number of unique words (types) to all words (tokens).

    Higher values indicate higher lexical diversity.

    Args:
        doc_or_tokens: If a spaCy ``Doc``, non-punctuation tokens (words) are extracted;
            if an iterable of spaCy ``Token`` s, all non-punct elements are used.
        variant: Particular variant of TTR.
            - "standard" => ``n_types / n_words``
            - "root" => ``n_types / sqrt(n_words)``
            - "corrected" => ``n_types / sqrt(2 * n_words)``

    Note:
        All variants of this measure are sensitive to document length,
        so values from texts with different lengths should not be compared.

    References:
        - Templin, M. (1957). Certain language skills in children. Minneapolis:
          University of Minnesota Press.
        - RTTR: Guiraud 1954, 1960
        - CTTR: 1964 Carrol
    """
    n_words, n_types = utils.compute_n_words_and_types(utils.get_words(doc_or_tokens))
    try:
        if variant == "standard":
            return n_types / n_words
        elif variant == "root":
            return n_types / math.sqrt(n_words)
        elif variant == "corrected":
            return n_types / math.sqrt(2 * n_words)
        else:
            raise ValueError(
                errors.value_invalid_msg(
                    "variant", variant, {"standard", "root", "corrected"}
                )
            )
    except ZeroDivisionError:
        return 0.0
def ttr ( doc_or_tokens : types . DocOrTokens , variant : Literal [ "standard" , "root" , "corrected" ] = "standard" , ) -> float : n_words , n_types = utils . compute_n_words_and_types ( utils . get_words ( doc_or_tokens ) ) try : if variant == "standard" : return n_types / n_words elif variant == "root" : return n_types / math . sqrt ( n_words ) elif variant == "corrected" : return n_types / math . sqrt ( 2 * n_words ) else : raise ValueError ( errors . value_invalid_msg ( "variant" , variant , { "standard" , "root" , "corrected" } ) ) except ZeroDivisionError : return 0.0