コード例 #1
0
ファイル: VerseScanner.py プロジェクト: TylerKirby/cltk
 def flag_dipthongs(self, syllables: list) -> list:
     """Return a list of syllables that contain a dipthong"""
     long_positions = []
     for idx, syl in enumerate(syllables):
         for dipthong in self.constants.DIPTHONGS:
             if dipthong in syllables[idx]:
                 if not StringUtils.starts_with_qu(syllables[idx]):
                     long_positions.append(idx)
     return long_positions
コード例 #2
0
 def flag_dipthongs(self, syllables: list) -> list:
     """Return a list of syllables that contain a dipthong"""
     long_positions = []
     for idx, syl in enumerate(syllables):
         for dipthong in self.constants.DIPTHONGS:
             if dipthong in syllables[idx]:
                 if not StringUtils.starts_with_qu(syllables[idx]):
                     long_positions.append(idx)
     return long_positions
コード例 #3
0
ファイル: VerseScanner.py プロジェクト: TylerKirby/cltk
 def calc_offset(self, syllables_spaces: list) -> dict:
     """Calculate a dictionary of accent positions from a list of syllables with spaces."""
     line = StringUtils.flatten(syllables_spaces)
     mydict = defaultdict(lambda: None)
     for idx, syl in enumerate(syllables_spaces):
         target_syllable = syllables_spaces[idx]
         skip_qu = StringUtils.starts_with_qu(target_syllable)
         matches = list(self.syllable_matcher.finditer(target_syllable))
         for position, possible in enumerate(matches):
             if skip_qu:
                 skip_qu = False
                 continue
             (start, end) = possible.span()
             if target_syllable[start:end] in \
                             self.constants.VOWELS + self.constants.ACCENTED_VOWELS:
                 part = line[:len("".join(syllables_spaces[:idx]))]
                 offset = len(part) + start
                 if line[offset] not in self.constants.VOWELS + self.constants.ACCENTED_VOWELS:
                     LOG.error("Problem at line {} offset {}".format(line, offset))
                 mydict[idx] = offset
     return mydict
コード例 #4
0
 def calc_offset(self, syllables_spaces: list) -> dict:
     """Calculate a dictionary of accent positions from a list of syllables with spaces."""
     line = StringUtils.flatten(syllables_spaces)
     mydict = defaultdict(lambda: None)
     for idx, syl in enumerate(syllables_spaces):
         target_syllable = syllables_spaces[idx]
         skip_qu = StringUtils.starts_with_qu(target_syllable)
         matches = list(self.syllable_matcher.finditer(target_syllable))
         for position, possible in enumerate(matches):
             if skip_qu:
                 skip_qu = False
                 continue
             (start, end) = possible.span()
             if target_syllable[start:end] in \
                             self.constants.VOWELS + self.constants.ACCENTED_VOWELS:
                 part = line[:len("".join(syllables_spaces[:idx]))]
                 offset = len(part) + start
                 if line[offset] not in self.constants.VOWELS + self.constants.ACCENTED_VOWELS:
                     print("Problem at line %s offset %s" % (line, offset))
                 mydict[idx] = offset
     return mydict