Spaces:
Sleeping
Sleeping
neuralworm
commited on
Commit
•
95fdffd
1
Parent(s):
82d4320
fix most frequent phrase
Browse files
app.py
CHANGED
@@ -200,7 +200,7 @@ with gr.Blocks() as app:
|
|
200 |
els_results = perform_els_search(step, rounds_combination, tlang, strip_spaces, strip_in_braces, strip_diacritics_chk, merge_results, include_torah, include_bible, include_quran)
|
201 |
|
202 |
# --- Network Search Integration ---
|
203 |
-
updated_els_results = []
|
204 |
for result in els_results:
|
205 |
print("DEBUG: Result from perform_els_search:", result)
|
206 |
try:
|
@@ -212,21 +212,32 @@ with gr.Blocks() as app:
|
|
212 |
max_words = len(result['result_text'].split())
|
213 |
matching_phrases = search_gematria_in_db(gematria_sum, max_words)
|
214 |
|
215 |
-
#
|
216 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
217 |
|
218 |
# Add most frequent phrase to the result dictionary
|
219 |
result['Most Frequent Phrase'] = most_frequent_phrase
|
220 |
|
221 |
-
updated_els_results.append(result)
|
222 |
|
223 |
# --- Prepare Dataframe ---
|
224 |
-
df = pd.DataFrame(updated_els_results)
|
225 |
df.index = range(1, len(df) + 1)
|
226 |
df.reset_index(inplace=True)
|
227 |
df.rename(columns={'index': 'Result Number'}, inplace=True)
|
228 |
|
229 |
-
return df, most_frequent_phrase
|
230 |
|
231 |
|
232 |
|
|
|
200 |
els_results = perform_els_search(step, rounds_combination, tlang, strip_spaces, strip_in_braces, strip_diacritics_chk, merge_results, include_torah, include_bible, include_quran)
|
201 |
|
202 |
# --- Network Search Integration ---
|
203 |
+
updated_els_results = []
|
204 |
for result in els_results:
|
205 |
print("DEBUG: Result from perform_els_search:", result)
|
206 |
try:
|
|
|
212 |
max_words = len(result['result_text'].split())
|
213 |
matching_phrases = search_gematria_in_db(gematria_sum, max_words)
|
214 |
|
215 |
+
# Iteratively increase max_words if no results are found
|
216 |
+
max_words_limit = 20 # Set a limit for max_words
|
217 |
+
while not matching_phrases and max_words < max_words_limit:
|
218 |
+
max_words += 1
|
219 |
+
matching_phrases = search_gematria_in_db(gematria_sum, max_words)
|
220 |
+
|
221 |
+
# Find most frequent phrase or first phrase with lowest word count
|
222 |
+
if matching_phrases:
|
223 |
+
most_frequent_phrase = get_most_frequent_phrase(matching_phrases)
|
224 |
+
else:
|
225 |
+
# Sort initial results by word count and take the first phrase
|
226 |
+
sorted_results = sorted(search_gematria_in_db(gematria_sum, max_words_limit), key=lambda x: len(x[0].split()))
|
227 |
+
most_frequent_phrase = sorted_results[0][0] if sorted_results else ""
|
228 |
|
229 |
# Add most frequent phrase to the result dictionary
|
230 |
result['Most Frequent Phrase'] = most_frequent_phrase
|
231 |
|
232 |
+
updated_els_results.append(result)
|
233 |
|
234 |
# --- Prepare Dataframe ---
|
235 |
+
df = pd.DataFrame(updated_els_results)
|
236 |
df.index = range(1, len(df) + 1)
|
237 |
df.reset_index(inplace=True)
|
238 |
df.rename(columns={'index': 'Result Number'}, inplace=True)
|
239 |
|
240 |
+
return df, most_frequent_phrase
|
241 |
|
242 |
|
243 |
|