Calculate a dictionary of accent positions from a list of syllables with spaces.

        :param syllables_spaces:
        :return:
773382
def calc_offset(self, syllables_spaces: List[str]) -> Dict[int, int]:
        
        line = string_utils.flatten(syllables_spaces)
        mydict = {} # type: Dict[int, int]
        # #defaultdict(int) #type: Dict[int, int]
        for idx, syl in enumerate(syllables_spaces):
            target_syllable = syllables_spaces[idx]
            skip_qu = string_utils.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
931452
def _full_default(self, pronunciation):
        

        token_default = self['metadata']['token_default']['full']

        key = pronunciation
        if isinstance(key, list):
            if not all([isinstance(phoneme, basestring) for phoneme in key]):
                raise ValueError('The pronunciation must be of type string (a sequence of space separated phonemes) '
                                 'or of type list (containing phonemes of type strings).'
                                 'User supplied: {}'.format(key))

            key = ' '.join(pronunciation)

        predictions = {key: token_default['='],
                       '*': token_default['*']}

        return predictions
470583
def pinyin_syllable_to_zhuyin(s):
    """"""
    pinyin_syllable, tone = _parse_pinyin_syllable(s)
    try:
        zhuyin_syllable = _PINYIN_MAP[pinyin_syllable.lower()]['Zhuyin']
    except KeyError:
        raise ValueError('Not a valid syllable: %s' % s)
    return zhuyin_syllable + _ZHUYIN_TONES[tone]
827591
def make_speaker_utters(utterances: List[Utterance]) -> Dict[str, List[Utterance]]:
    

    speaker_utters = defaultdict(list) # type: DefaultDict[str, List[Utterance]]
    for utter in utterances:
        speaker_utters[utter.speaker].append(utter)

    return speaker_utters
210469
def SpacesInsideBrackets( logical_line, tokens ):
  """"""
  for index in range( len( tokens ) ):
    _, prev_text, _, prev_end, _ = ( tokens[ index - 1 ] if index - 1 >= 0 else
                                     ( None, None, None, None, None ) )
    token_type, text, start, end, _ = tokens[ index ]
    next_token_type, next_text, next_start, _, _ = (
      tokens[ index + 1 ] if index + 1 < len( tokens ) else
      ( None, None, None, None, None ) )
    if text in LEFT_BRACKETS:
      if ( next_text == CORRESPONDING_BRACKET[ text ] and
           next_start != end ):
        code = 'YCM204'
        message = ( ' no spaces between {} and {}'
                    ' for empty content'.format( text, next_text ) )
        yield end, code + message
      if ( next_token_type not in [ tokenize.NL, tokenize.NEWLINE ] and
           next_text != CORRESPONDING_BRACKET[ text ] and
           next_start and
           next_start[ 0 ] == start[ 0 ] and
           next_start[ 1 ] - start[ 1 ] != 2 ):
        code = 'YCM201'
        message = ' exactly one space required after {}'.format( text )
        yield end, code + message
    if text in RIGHT_BRACKETS:
      if ( prev_text != CORRESPONDING_BRACKET[ text ] and
           prev_end and
           prev_end[ 0 ] == end[ 0 ] and
           end[ 1 ] - prev_end[ 1 ] != 2 ):
        code = 'YCM202'
        message = ' exactly one space required before {}'.format( text )
        yield start, code + message
720033
def segment_str(text: str, phoneme_inventory: Set[str] = PHONEMES) -> str:
    

    text = text.lower()
    text = segment_into_tokens(text, phoneme_inventory)
    return text
1359057
def __get_idxs(self, words):
        """"""
        if self.bow:
            return list(itertools.chain.from_iterable(
                [self.positions[z] for z in words]))
        else:
            return self.positions[words]
934696
def numbered_to_accented(s):
    """"""
    return _convert(s, zhon.pinyin.syllable, numbered_syllable_to_accented,
                    add_apostrophes=True)
1326635
def pk_prom(word):
    ''''''
    LIGHT = r'[ieaAoO]{1}[\.]*(u|y)(\.|$)'

    # # if the word is not monosyllabic, lop off the final syllable, which is
    # # extrametrical
    # if '.' in word:
    #     word = word[:word.rindex('.')]

    # gather the indices of syllable boundaries
    delimiters = [0, ] + [i for i, char in enumerate(word) if char == '.']

    if len(delimiters) % 2 != 0:
        delimiters.append(len(word))

    stressed = []

    # gather the indices of stressed positions
    for i, d in enumerate(delimiters):
        if i % 2 == 0:
            stressed.extend(range(d + 1, delimiters[i + 1]))

    # find the number of stressed light syllables
    heavies = re.finditer(LIGHT, word)
    violations = sum(1 for m in heavies if m.start(1) in stressed)

    return violations
320344
def _scansion(self, sentence_syllables):
        

        scanned_text = []
        for sentence in sentence_syllables:
            scanned_sent = []
            for syllable in sentence:
                if self._long_by_position(syllable, sentence) or \
                   self._long_by_nature(syllable):
                    scanned_sent.append('¯')
                else:
                    scanned_sent.append('˘')
            if len(scanned_sent) > 1:
                del scanned_sent[-1]
                scanned_sent.append('x')
            scanned_text.append(''.join(scanned_sent))
        return scanned_text
681906
def _buildDict(self):
        '''
        
        '''
        lexDict = {}
        with io.open(self.islePath, "r", encoding='utf-8') as fd:
            wordList = [line.rstrip('\n') for line in fd]
        
        for row in wordList:
            word, pronunciation = row.split(" ", 1)
            word, extraInfo = word.split("(", 1)
            
            extraInfo = extraInfo.replace(")", "")
            extraInfoList = [segment for segment in extraInfo.split(",")
                             if ("_" not in segment and "+" not in segment and
                                 ':' not in segment and segment != '')]
            
            lexDict.setdefault(word, [])
            lexDict[word].append((pronunciation, extraInfoList))
        
        return lexDict
143024
def text_to_phonemes(self, word: str) -> list:
        
        phonemes = []
        is_repeted = False
        if len(word) >= 2:
            for index in range(len(word) - 1):
                if is_repeted:
                    is_repeted = False
                    continue
                if word[index:index + 2] in self.diphthongs_ipa:  # diphthongs
                    phonemes.append(self.diphthongs_ipa_class[word[index] + word[index + 1]])
                    is_repeted = True
                elif word[index] == word[index + 1]:
                    phonemes.append(self.ipa_class[word[index]].lengthen())
                    is_repeted = True
                else:
                    phonemes.append(self.ipa_class[word[index]])
            if not is_repeted:
                phonemes.append(self.ipa_class[word[len(word) - 1]])
        else:
            phonemes.append(self.ipa_class[word[0]])
        return phonemes
1066707
function(str) {
            
            var accent = [
                /[\300-\306]/g, /[\340-\346]/g, // A, a
                /[\310-\313]/g, /[\350-\353]/g, // E, e
                /[\314-\317]/g, /[\354-\357]/g, // I, i
                /[\322-\330]/g, /[\362-\370]/g, // O, o
                /[\331-\334]/g, /[\371-\374]/g, // U, u
                /[\321]/g, /[\361]/g, // N, n
                /[\307]/g, /[\347]/g // C, c
            ];
            
            var noaccent = ['A','a','E','e','I','i','O','o','U','u','N','n','C','c'];
            
            for(var i = 0; i < accent.length; i++) str = str.replace(accent[i], noaccent[i]);
            
            return str;
        }
767245
def _spoken_representation_L2(lst_lst_char):
    
    s = ''
    inter_char = ' '
    inter_word = ' (space) '
    for i, word in enumerate(lst_lst_char):
        if i >= 1:
            s += inter_word
        for j, c in enumerate(word):
            if j != 0:
                s += inter_char
            s += mtalk.encoding.morsetab[c]
    return s
1151540
def syllable_tokenize(text: str) -> List[str]:
    

    if not text or not isinstance(text, str):
        return []

    tokens = []
    if text:
        words = word_tokenize(text)
        trie = dict_trie(dict_source=thai_syllables())
        for word in words:
            tokens.extend(word_tokenize(text=word, custom_dict=trie))

    return tokens
18918
def word_break(s, word_dict):
    
    dp = [False] * (len(s)+1)
    dp[0] = True
    for i in range(1, len(s)+1):
        for j in range(0, i):
            if dp[j] and s[j:i] in word_dict:
                dp[i] = True
                break
    return dp[-1]
1058692
def ipa_to_pinyin(s, accented=True):
    
    if accented:
        function = _ipa_syllable_to_accented
    else:
        function = _ipa_syllable_to_numbered
    return _convert(s, _IPA_SYLLABLE, function)