(self, text)
return result
Calculates repetition scores in text.

    Args:
      text: text that may contain repetitions.

    Returns:
      A dict mapping each repetition type to a float.
    Raises:
      ValueError: If an invalid repetition type is encountered.
Calculates repetition scores in text.
Calculates repetition scores in text .
def _score_single(self, text) -> Dict[Text, float]:
    """Calculates repetition scores in text.

    Args:
      text: text that may contain repetitions.

    Returns:
      A dict mapping each repetition type to a float.
    Raises:
      ValueError: If an invalid repetition type is encountered.
    """
    tokens = self._tokenize(text)
    result = {}
    if any([t.endswith("CR") for t in self.repetition_types]):
      spans = [s for s in _find_consecutive_repeating_subsequence_spans(tokens)]
    else:
      spans = []

    num_tokens = len(tokens)
    for repetition_type in self.repetition_types:
      if repetition_type == "regsLCR":
        max_len = max([end - start for start, end in spans]) if spans else 0
        score = max_len / num_tokens if num_tokens > 0 else 0
      elif repetition_type == "regsTCR":
        score = _get_spans_total_length(
            spans) / num_tokens if num_tokens > 0 else 0
      elif re.match(r"regs[0-9]$", repetition_type):
        n = int(repetition_type[4:])
        if n <= 0:
          raise ValueError("regsn requires positive n: %s" % repetition_type)
        ngrams = _create_ngrams(tokens, n)
        score = _score_ngrams(ngrams)
      else:
        raise ValueError("Invalid repetition type: %s" % repetition_type)
      result[repetition_type] = score

    return result
def _score_single ( self , text ) -> Dict [ Text , float ] : tokens = self . _tokenize ( text ) result = { } if any ( [ t . endswith ( "CR" ) for t in self . repetition_types ] ) : spans = [ s for s in _find_consecutive_repeating_subsequence_spans ( tokens ) ] else : spans = [ ] num_tokens = len ( tokens ) for repetition_type in self . repetition_types : if repetition_type == "regsLCR" : max_len = max ( [ end - start for start , end in spans ] ) if spans else 0 score = max_len / num_tokens if num_tokens > 0 else 0 elif repetition_type == "regsTCR" : score = _get_spans_total_length ( spans ) / num_tokens if num_tokens > 0 else 0 elif re . match ( r"regs[0-9]$" , repetition_type ) : n = int ( repetition_type [ 4 : ] ) if n <= 0 : raise ValueError ( "regsn requires positive n: %s" % repetition_type ) ngrams = _create_ngrams ( tokens , n ) score = _score_ngrams ( ngrams ) else : raise ValueError ( "Invalid repetition type: %s" % repetition_type ) result [ repetition_type ] = score return result