def processSyntax(line, db_con): lookup.initialiseEmotionVerbRegexps(db_con) tree = _SyntaxTree() (display_string, result) = _processInput(tree, line.split(), db_con) return (tree, display_string, result)
def encodeBinasphere(lines, db_con): lookup.initialiseEmotionVerbRegexps(db_con) new_lines = [] syllable_lines = [] unknown_set = set() for line in lines: if not _GENERAL_CONTENT_REGEXP.match(line): raise ContentError("Non-Hymmnos content provided for Binasphere encoding") (lines, syllable_line, unknown) = _dissectSyllables(line.split(), db_con) new_lines.append(lines) syllable_lines.append(syllable_line) unknown_set.update(unknown) return (_multiplexBinasphere(syllable_lines, ''.join(lines).lower()), new_lines, sorted(unknown))
def decodeBinasphere(line, db_con): match = _BINASPHERE_REGEXP.match(line) if not match: raise FormatError("Non-Binasphere input provided") if not _BINASPHERE_CONTENT_REGEXP.match(match.group(1)): raise ContentError("Invalid Binasphere content provided") tokens = match.group(1).strip().split() size = int(match.group(2)) sequence = match.group(3).strip().split() if len(sequence) == 1: if size > 9: raise ContentError("For line-counts greater than 9, sequence entries must be space-delimited") sequence = sequence[0] sequence = [int(i) for i in sequence] lookup.initialiseEmotionVerbRegexps(db_con) return _divideAndCapitalise(_reconstructBinasphere(tokens, sequence, size), db_con)
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) )