Exemplo n.º 1
0
    def test_find_stress(self):
        test_string = "reflect respect recline reduce obsessively demonstrate baseball cloud brother cobblestone " +\
            "complete conspire estuary"
        raw_cmu = transcribe.get_cmu(test_string.split(" "))
        result = []
        for word_list in raw_cmu:
            for word in word_list:
                stressed = stress.find_stress(word)
                result.append(stressed)
        self.assertEqual(result, [
            'r ah ˈf l eh k t', 'r ih ˈf l eh k t', 'r ih ˈs p eh k t',
            'r iy ˈs p eh k t', 'r ih ˈk l ay n', 'r ih ˈd uw s',
            'aa b ˈs eh s ih v l iy', 'ˈd eh m ah n ˌs t r ey t',
            'ˈb ey s ˈb ao l', 'k l aw d', 'ˈb r ah dh er',
            'ˈk aa b ah l ˌs t ow n', 'k ah m ˈp l iy t', 'k ah n ˈs p ay er',
            'ˈeh s ch uw ˌeh r iy'
        ])

        # test the retrieval of only primary stress
        self.assertEqual(
            stress.find_stress("d eh1 m ah0 n s t r ey2 t", type="primary"),
            'ˈd eh m ah n s t r ey t')
        # test the retrieval of only secondary stress
        self.assertEqual(
            stress.find_stress("d eh1 m ah0 n s t r ey2 t", type="secondary"),
            'd eh m ah n ˌs t r ey t')
Exemplo n.º 2
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.º 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]
    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.º 4
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.º 5
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])
Exemplo n.º 6
0
def remove_onset(word_in):
    phone_list = get_cmu([word_in])[0][0].split(" ")
    for i, phoneme in enumerate(phone_list):
        if "1" in phoneme:
            return ' '.join(phone_list[i:])