Exemplo n.º 1
0
def get_rhymes(word):
    if len(word.split()) > 1:
        return [get_rhymes(w) for w in word.split()]
    phones = remove_onset(preprocess(word))
    phones_full = get_cmu([preprocess(word)])[0][0]
    c.execute(
        f"SELECT word, phonemes FROM dictionary WHERE phonemes "
        f"LIKE \"%{phones}\" AND NOT word=\"{word}\" "  # don't count word as its own rhyme
        f"AND NOT phonemes=\"{phones_full}\""
    )  # don't return results that are the same but spelled differently
    return sorted(list(set([r[0] for r in c.fetchall()])))
Exemplo n.º 2
0
def get_rhymes(word, mode="sql"):
    if len(word.split()) > 1:
        return [get_rhymes(w) for w in word.split()]
    phones = remove_onset(preprocess(word))
    phones_full = get_cmu([preprocess(word)])[0][0]
    if mode == "sql":
        c = mode_type(mode)
        c.execute(f"SELECT word, phonemes FROM dictionary WHERE phonemes " 
                  f"LIKE \"%{phones}\" AND NOT word=\"{word}\" "  # don't count word as its own rhyme
                  f"AND NOT phonemes=\"{phones_full}\"")
        # also don't return results that are the same but spelled differently
        return sorted(list(set([r[0] for r in c.fetchall()])))
    elif mode == "json":
        r_list = []
        for key, val in mode_type(mode).items():
            for v in val:
                if v.endswith(phones) and word != key and v != phones_full:
                    r_list.append(key)
        return sorted(set(r_list))
Exemplo n.º 3
0
def get_rhymes(word, mode="sql"):
    if len(word.split()) > 1:
        return [get_rhymes(w) for w in word.split()]
    phones = remove_onset(preprocess(word))
    phones_full = get_cmu([preprocess(word)])[0][0]
    asset = ModeType(mode=mode).mode
    if mode == "sql":
        asset.execute(
            "SELECT word, phonemes FROM dictionary WHERE phonemes "
            "LIKE \"%{0}\" AND NOT word=\"{1}\" ".format(phones, word) +
            "AND NOT phonemes=\"{0}\"".format(phones_full))
        # also don't return results that are the same but spelled differently
        return sorted(list(set([r[0] for r in asset.fetchall()])))
    elif mode == "json":
        r_list = []
        for key, val in asset.items():
            for v in val:
                if v.endswith(phones) and word != key and v != phones_full:
                    r_list.append(key)
        return sorted(set(r_list))
Exemplo n.º 4
0
def syllable_count(word: str, db_type="sql"):
    """transcribes a regular word to CMU to fetch syllable count"""
    if len(word.split()) > 1:
        return [syllable_count(w) for w in word.split()]
    word = transcribe.get_cmu([transcribe.preprocess(word)], db_type=db_type)
    return cmu_syllable_count(word[0][0])