JaeSwift commited on
Commit
714813f
·
verified ·
1 Parent(s): 4f51398

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -17
app.py CHANGED
@@ -25,19 +25,10 @@ def get_exact_rhymes(phones):
25
 
26
  rhyming_tail_str = " ".join(rhyming_tail)
27
  matches = pronouncing.search(rhyming_tail_str + "$")
28
- exact_rhymes = [match for match in matches if rhyming_tail == _get_rhyming_tail(get_phones(match))]
 
29
  return exact_rhymes
30
 
31
- def get_filtered_loose_rhymes(phones):
32
- rhyming_tail = _get_rhyming_tail(phones)
33
- if not rhyming_tail:
34
- return []
35
-
36
- search_pattern = " ".join(phone[:-1] + "." for phone in rhyming_tail)
37
- matches = pronouncing.search(search_pattern)
38
- filtered_rhymes = [match for match in matches if get_phones(match)]
39
- return filtered_rhymes
40
-
41
  def find_rhymes_for_phrase(phrase):
42
  words = phrase.split()
43
  rhyming_options = []
@@ -53,18 +44,14 @@ def find_rhymes_for_phrase(phrase):
53
  if exact_rhymes:
54
  rhyming_options.append([[rhyme] for rhyme in exact_rhymes])
55
  else:
56
- loose_rhymes = get_filtered_loose_rhymes(phones)
57
- if loose_rhymes:
58
- rhyming_options.append([[rhyme] for rhyme in loose_rhymes])
59
- else:
60
- rhyming_options.append([[f"{word} (No rhymes found)"]])
61
 
62
  # Flatten each combination into strings
63
  combined_results = list(itertools.product(*rhyming_options))
64
  unique_results = set(" ".join(item[0] for item in combination) for combination in combined_results)
65
 
66
  # Return a list of unique rhyming combinations, each wrapped in a list for DataFrame compatibility
67
- return [[rhyme] for rhyme in unique_results]
68
 
69
  # Function to update the notepad with a selected rhyme
70
  def add_to_notepad(notepad, selected_rhyme):
 
25
 
26
  rhyming_tail_str = " ".join(rhyming_tail)
27
  matches = pronouncing.search(rhyming_tail_str + "$")
28
+ # Only include common, recognized words
29
+ exact_rhymes = [match for match in matches if match.isalpha() and match.islower()]
30
  return exact_rhymes
31
 
 
 
 
 
 
 
 
 
 
 
32
  def find_rhymes_for_phrase(phrase):
33
  words = phrase.split()
34
  rhyming_options = []
 
44
  if exact_rhymes:
45
  rhyming_options.append([[rhyme] for rhyme in exact_rhymes])
46
  else:
47
+ rhyming_options.append([[f"{word} (No rhymes found)"]])
 
 
 
 
48
 
49
  # Flatten each combination into strings
50
  combined_results = list(itertools.product(*rhyming_options))
51
  unique_results = set(" ".join(item[0] for item in combination) for combination in combined_results)
52
 
53
  # Return a list of unique rhyming combinations, each wrapped in a list for DataFrame compatibility
54
+ return [[rhyme] for rhyme in unique_results if rhyme.isalpha() and rhyme.islower()]
55
 
56
  # Function to update the notepad with a selected rhyme
57
  def add_to_notepad(notepad, selected_rhyme):