Update app.py
Browse files
app.py
CHANGED
@@ -18,10 +18,15 @@ def _get_rhyming_tail(phones, syllable_count=1):
|
|
18 |
return None # Not enough syllables for the rhyme
|
19 |
return phones[-syllable_count * 2:]
|
20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
def get_soft_rhymes(phones, syllable_count=1):
|
22 |
-
"""
|
23 |
-
Find words that have a similar ending sound but don't match exactly.
|
24 |
-
"""
|
25 |
rhyming_tail = _get_rhyming_tail(phones, syllable_count)
|
26 |
if not rhyming_tail:
|
27 |
return []
|
@@ -46,7 +51,7 @@ def find_rhymes_for_phrase(phrase, syllable_count=1):
|
|
46 |
perfect_rhymes = get_multisyllabic_rhymes(phones, syllable_count)
|
47 |
soft_rhymes = get_soft_rhymes(phones, syllable_count)
|
48 |
|
49 |
-
# Combine both types of rhymes
|
50 |
all_rhymes = set(perfect_rhymes + soft_rhymes)
|
51 |
if not all_rhymes:
|
52 |
rhyming_options.append([f"{word} (No rhymes found)"])
|
@@ -56,7 +61,7 @@ def find_rhymes_for_phrase(phrase, syllable_count=1):
|
|
56 |
# Generate all possible combinations of rhyming words
|
57 |
combined_results = list(itertools.product(*rhyming_options))
|
58 |
|
59 |
-
# Format combined results as
|
60 |
if combined_results:
|
61 |
result_str = f"Rhyming combinations for '{phrase}':\n"
|
62 |
result_str += "\n".join(" ".join(combination) for combination in combined_results)
|
|
|
18 |
return None # Not enough syllables for the rhyme
|
19 |
return phones[-syllable_count * 2:]
|
20 |
|
21 |
+
def get_multisyllabic_rhymes(phones, syllable_count=1):
|
22 |
+
rhyming_tail = _get_rhyming_tail(phones, syllable_count)
|
23 |
+
if not rhyming_tail:
|
24 |
+
return []
|
25 |
+
|
26 |
+
rhyming_tail_str = " ".join(rhyming_tail)
|
27 |
+
return pronouncing.search(rhyming_tail_str + "$")
|
28 |
+
|
29 |
def get_soft_rhymes(phones, syllable_count=1):
|
|
|
|
|
|
|
30 |
rhyming_tail = _get_rhyming_tail(phones, syllable_count)
|
31 |
if not rhyming_tail:
|
32 |
return []
|
|
|
51 |
perfect_rhymes = get_multisyllabic_rhymes(phones, syllable_count)
|
52 |
soft_rhymes = get_soft_rhymes(phones, syllable_count)
|
53 |
|
54 |
+
# Combine both types of rhymes and add to options
|
55 |
all_rhymes = set(perfect_rhymes + soft_rhymes)
|
56 |
if not all_rhymes:
|
57 |
rhyming_options.append([f"{word} (No rhymes found)"])
|
|
|
61 |
# Generate all possible combinations of rhyming words
|
62 |
combined_results = list(itertools.product(*rhyming_options))
|
63 |
|
64 |
+
# Format combined results as rhyming lines
|
65 |
if combined_results:
|
66 |
result_str = f"Rhyming combinations for '{phrase}':\n"
|
67 |
result_str += "\n".join(" ".join(combination) for combination in combined_results)
|