예제 #1
0
파일: demo.py 프로젝트: Tarnasa/punisher
def random_word_replacement(word):
    phonemes = make_puns.to_phonemes(word_dict, word)
    while True:
        start = random.randint(0, len(phonemes) - 1)
        stop = random.randint(start, len(phonemes))
        substitution = ''.join(make_puns.regenerate(sorted_dict, phonemes[start:stop]))
        if substitution and substitution != word:
            print(substitution)
            break

    partitions = make_puns.match_phonemes(substitution, phonemes[start:stop])
    print(partitions)
    puns = [[[], []]]
    for pair in partitions:
        if pair[1]:
            puns[0][0].append(pair[1])
            if pair[0]:
                puns[0][1].append(pair[0])
            else:
                puns[0][1].append('')
        else:
            puns[0][1][-1] += pair[0]

    print(puns)
    return make_puns.replace_part_of_word(word_dict, word, puns)
예제 #2
0
파일: demo.py 프로젝트: Tarnasa/punisher
def full_regeneration(sentence):
    return ' '.join(make_puns.regenerate(sorted_dict, make_puns.to_phonemes(word_dict, sentence)))