class_docstr: The scansion symbols used can be configured by passing a suitable constants class to
  the constructor.
docstr: Three or more unstressed accents in a row is a broken dactyl chain, best detected and
  processed backwards.
  
  Since this method takes a Procrustean approach to modifying the scansion pattern,
  it is not used by default in the scan method; however, it is available as an optional
  keyword parameter, and users looking to further automate the generation of scansion
  candidates should consider using this as a fall back.
  
  :param scansion: scansion with broken dactyl chain; inverted amphibrachs not allowed
  :return: corrected line of scansion
  
  >>> print(HexameterScanner().correct_dactyl_chain(
  ... "-   U U  -  - U U -  - - U U  - x"))
  -   - -  -  - U U -  - - U U  - x
  >>> print(HexameterScanner().correct_dactyl_chain(
  ... "-   U  U U  U -     -   -   -  -   U  U -   U")) # doctest: +NORMALIZE_WHITESPACE
  -   -  - U  U -     -   -   -  -   U  U -   U
docstr_tok: ["Three","or","more","unstressed","accents","in","a","row","is","a","broken","dactyl","chain",",","best","detected","and","processed","backwards",".","Since","this","method","takes","a","Procrustean","approach","to","modifying","the","scansion","pattern",",","it","is","not","used","by","default","in","the","scan","method",";","however",",","it","is","available","as","an","optional","keyword","parameter",",","and","users","looking","to","further","automate","the","generation","of","scansion","candidates","should","consider","using","this","as","a","fall","back",".",":","param","scansion",":","scansion","with","broken","dactyl","chain",";","inverted","amphibrachs","not","allowed",":","return",":","corrected","line","of","scansion",">",">",">","print","(","HexameterScanner","(",")",".correct_dactyl_chain","(","...","``","-","U","U","-","-","U","U","-","-","-","U","U","-","x","''",")",")","-","-","-","-","-","U","U","-","-","-","U","U","-","x",">",">",">","print","(","HexameterScanner","(",")",".correct_dactyl_chain","(","...","``","-","U","U","U","U","-","-","-","-","-","U","U","-","U","''",")",")","#","doctest",":","+NORMALIZE_WHITESPACE","-","-","-","U","U","-","-","-","-","-","U","U","-","U"]
code: def correct_dactyl_chain(self, scansion: str) -> str:
      """
      Three or more unstressed accents in a row is a broken dactyl chain, best detected and
      processed backwards.
  
      Since this method takes a Procrustean approach to modifying the scansion pattern,
      it is not used by default in the scan method; however, it is available as an optional
      keyword parameter, and users looking to further automate the generation of scansion
      candidates should consider using this as a fall back.
  
      :param scansion: scansion with broken dactyl chain; inverted amphibrachs not allowed
      :return: corrected line of scansion
  
      >>> print(HexameterScanner().correct_dactyl_chain(
      ... "-   U U  -  - U U -  - - U U  - x"))
      -   - -  -  - U U -  - - U U  - x
      >>> print(HexameterScanner().correct_dactyl_chain(
      ... "-   U  U U  U -     -   -   -  -   U  U -   U")) # doctest: +NORMALIZE_WHITESPACE
      -   -  - U  U -     -   -   -  -   U  U -   U
      """
      mark_list = string_utils.mark_list(scansion)
      vals = list(scansion.replace(" ", ""))
      #  ignore last two positions, save them
      feet = [vals.pop(), vals.pop()]
      length = len(vals)
      idx = length - 1
      while idx > 0:
          one = vals[idx]
          two = vals[idx - 1]
          if idx > 1:
              three = vals[idx - 2]
          else:
              three = ""
          # Dactyl foot is okay, no corrections
          if (
              one == self.constants.UNSTRESSED
              and two == self.constants.UNSTRESSED
              and three == self.constants.STRESSED
          ):
              feet += [one]
              feet += [two]
              feet += [three]
              idx -= 3
              continue
          # Spondee foot is okay, no corrections
          if (
              one == self.constants.STRESSED
              and two == self.constants.STRESSED
          ):
              feet += [one]
              feet += [two]
              idx -= 2
              continue
          # handle "U U U" foot as "- U U"
          if (
              one == self.constants.UNSTRESSED
              and two == self.constants.UNSTRESSED
              and three == self.constants.UNSTRESSED
          ):
              feet += [one]
              feet += [two]
              feet += [self.constants.STRESSED]
              idx -= 3
              continue
          # handle "U U -" foot as "- -"
          if (
              one == self.constants.STRESSED
              and two == self.constants.UNSTRESSED
              and three == self.constants.UNSTRESSED
          ):
              feet += [self.constants.STRESSED]
              feet += [self.constants.STRESSED]
              idx -= 2
              continue
          # handle "-  U" foot as "- -"
          if (
              one == self.constants.UNSTRESSED
              and two == self.constants.STRESSED
          ):
              feet += [self.constants.STRESSED]
              feet += [two]
              idx -= 2
              continue
      corrected = "".join(feet[::-1])
      new_line = list(" " * len(scansion))
      for idx, car in enumerate(corrected):
          new_line[mark_list[idx]] = car
      return "".join(new_line)
  
file_path: cltk/src/cltk/prosody/lat/hexameter_scanner.py
imports: import re
  import cltk.prosody.lat.string_utils
  from cltk.prosody.lat.metrical_validator import MetricalValidator
  from cltk.prosody.lat.scansion_constants import ScansionConstants
  from cltk.prosody.lat.scansion_formatter import ScansionFormatter
  from cltk.prosody.lat.syllabifier import Syllabifier
  from cltk.prosody.lat.verse import Verse
  from cltk.prosody.lat.verse_scanner import VerseScanner
label_desc: Use image node_id 5 for calling the HexameterScanner obj's underlying member method code with example usage: obj.correct_dactyl_chain(scansion) and returns: str