def _readWord(word, words, db_con): (word, meaning, kana, syntax_class, dialect, decorations, syllables) = lookup.readWord(word, words, db_con)[0] if syntax_class > 0: l_decorations = decorations if l_decorations: l_decorations = [d for d in decorations if d] if l_decorations or dialect % 50 == lookup.DIALECT['New Testament of Pastalie']: reason = ["'", word, "'",] if l_decorations and not dialect % 50 == lookup.DIALECT['New Testament of Pastalie']: reason += [" (carried markup: ", l_decorations, ")",] raise ContentError("Only Central Standard Note and related dialects are Binasphere-supported (offending word: %(reason)s)" % { 'reason': ''.join(reason) }) return (word, syntax_class, dialect, syllables)
def applyPersistentEmotionSounds(lines, db_con): m = _PERSISTANT_START_REGEXP.match(lines[0]) if not _PERSISTANT_END_REGEXP.match(lines[-1]): if not m: raise FormatError("Persistant syntax not detected") else: raise ContentError("Persistent Emotion Sounds terminator not found") elif not m: raise ContentError("Persistent Emotion Sounds initiator not found") lookup.initialiseEmotionVerbRegexps(db_con) new_lines = [] processed = [] unknown_set = set() es_i = None es_ii = None es_iii = None es_i_values = lookup.SYNTAX_CLASS_REV['ES(I)'] words = lookup.readWord(m.group(1).lower(), None, db_con) for (word, meaning, kana, syntax_class, dialect, decorations, syllables) in words: if syntax_class in es_i_values: es_i = word break if not es_i: es_i = m.group(1).title() unknown.add(es_i) es_ii_values = lookup.SYNTAX_CLASS_REV['ES(II)'] words = lookup.readWord(m.group(2).lower(), None, db_con) for (word, meaning, kana, syntax_class, dialect, decorations, syllables) in words: if syntax_class in es_ii_values: es_ii = word break if not es_ii: es_ii = m.group(2).lower() unknown.add(es_ii) es_iii_values = lookup.SYNTAX_CLASS_REV['ES(III)'] words = lookup.readWord(m.group(3).lower(), None, db_con) for (word, meaning, kana, syntax_class, dialect, decorations, syllables) in words: if syntax_class in es_iii_values: es_iii = word break if not es_iii: es_iii = m.group(3).title() unknown.add(es_iii) for line in lines[1:-1]: if not _GENERAL_CONTENT_REGEXP.match(line): raise ContentError("Non-Hymmnos content provided") (line, processed_lines, unknown) = _applyPersistentEmotionSounds(es_i, es_ii, es_iii, line.split(), db_con) new_lines.append(line) processed.append(processed_lines) unknown_set.update(unknown) return ( ["%(es_i)s %(es_ii)s %(es_iii)s 0x vvi." % { 'es_i': es_i, 'es_ii': es_ii, 'es_iii': es_iii, }] + new_lines + lines[-1:], processed, sorted(unknown_set) )