class_docstr: The scansion symbols used can be configured by passing a suitable constants class to
  the constructor.
docstr: The 'inverted amphibrach': stressed_unstressed_stressed syllable pattern is invalid
  in hexameters, so here we coerce it to stressed when it occurs at the end of a line
  
  :param scansion: the scansion pattern
  :return corrected scansion: the corrected scansion pattern
  
  >>> print(HexameterScanner().correct_invalid_fifth_foot(
  ... " -   - -   U U  -  U U U -  - U U U  - x")) # doctest: +NORMALIZE_WHITESPACE
  -   - -   U U  -  U U U -  - - U U  - x
docstr_tok: ["The","'inverted","amphibrach","'",":","stressed_unstressed_stressed","syllable","pattern","is","invalid","in","hexameters",",","so","here","we","coerce","it","to","stressed","when","it","occurs","at","the","end","of","a","line",":","param","scansion",":","the","scansion","pattern",":","return","corrected","scansion",":","the","corrected","scansion","pattern",">",">",">","print","(","HexameterScanner","(",")",".correct_invalid_fifth_foot","(","...","``","-","-","-","U","U","-","U","U","U","-","-","U","U","U","-","x","''",")",")","#","doctest",":","+NORMALIZE_WHITESPACE","-","-","-","U","U","-","U","U","U","-","-","-","U","U","-","x"]
code: def correct_invalid_fifth_foot(self, scansion: str) -> str:
      """
      The 'inverted amphibrach': stressed_unstressed_stressed syllable pattern is invalid
      in hexameters, so here we coerce it to stressed when it occurs at the end of a line
  
      :param scansion: the scansion pattern
      :return corrected scansion: the corrected scansion pattern
  
      >>> print(HexameterScanner().correct_invalid_fifth_foot(
      ... " -   - -   U U  -  U U U -  - U U U  - x")) # doctest: +NORMALIZE_WHITESPACE
      -   - -   U U  -  U U U -  - - U U  - x
      """
      scansion_wo_spaces = (
          scansion.replace(" ", "")[:-1]
          + self.constants.OPTIONAL_ENDING
      )
      if scansion_wo_spaces.endswith(
          self.constants.DACTYL
          + self.constants.IAMB
          + self.constants.OPTIONAL_ENDING
      ):
          matches = list(
              re.compile(
                  r"{}\s*{}\s*{}\s*{}\s*{}".format(
                      self.constants.STRESSED,
                      self.constants.UNSTRESSED,
                      self.constants.UNSTRESSED,
                      self.constants.UNSTRESSED,
                      self.constants.STRESSED,
                  )
              ).finditer(scansion)
          )
          (start, end) = matches[len(matches) - 1].span()
          unstressed_idx = scansion.index(
              self.constants.UNSTRESSED, start
          )
          new_line = (
              scansion[:unstressed_idx]
              + self.constants.STRESSED
              + scansion[unstressed_idx + 1 :]
          )
          return new_line
      return scansion
  
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 3 for calling the HexameterScanner obj's underlying member method code with example usage: obj.correct_invalid_fifth_foot(scansion) and returns: scansion, new_line