code: 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
  
file_path: textacy/src/textacy/text_stats/diversity.py
imports: from __future__ import annotations
  import logging
  import math
  import statistics
  from typing import Iterable, Literal
  from scipy.stats import hypergeom
  from spacy.tokens import Token
  from toolz import itertoolz
  from ..None import errors, types
  from .None import utils
label_desc: Use image node_id 1 for calling a global function with example usage: ttr(doc_or_tokens, variant) and returns: unknown, int, unknown, unknown