Spaces:
Running
Running
Commit
·
73f20e9
1
Parent(s):
2abb4ba
Update app.py
Browse files
app.py
CHANGED
@@ -31,6 +31,12 @@ def random_spanish_pair():
|
|
31 |
random_pair = random.choice(json_data)
|
32 |
return jsonify(random_pair)
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
# Lists to store English and Spanish words separately
|
35 |
english_words = set()
|
36 |
spanish_words = set()
|
@@ -38,11 +44,11 @@ spanish_words = set()
|
|
38 |
# Populate the word lists
|
39 |
for pair in json_data:
|
40 |
if "english" in pair:
|
41 |
-
# Extract words from the English sentence
|
42 |
-
english_words.update(re.findall(r'\b\w+\b', pair["english"]))
|
43 |
if "spanish" in pair:
|
44 |
-
# Extract words from the Spanish sentence
|
45 |
-
spanish_words.update(re.findall(r'\b\w+\b', pair["spanish"]))
|
46 |
|
47 |
def get_distractors(target_word, all_words, num_distractors=3):
|
48 |
"""
|
|
|
31 |
random_pair = random.choice(json_data)
|
32 |
return jsonify(random_pair)
|
33 |
|
34 |
+
def is_word(s):
|
35 |
+
"""
|
36 |
+
Check if the string 's' is a word (contains only alphabetic characters).
|
37 |
+
"""
|
38 |
+
return s.isalpha()
|
39 |
+
|
40 |
# Lists to store English and Spanish words separately
|
41 |
english_words = set()
|
42 |
spanish_words = set()
|
|
|
44 |
# Populate the word lists
|
45 |
for pair in json_data:
|
46 |
if "english" in pair:
|
47 |
+
# Extract words from the English sentence and filter out numbers
|
48 |
+
english_words.update(filter(is_word, re.findall(r'\b\w+\b', pair["english"])))
|
49 |
if "spanish" in pair:
|
50 |
+
# Extract words from the Spanish sentence and filter out numbers
|
51 |
+
spanish_words.update(filter(is_word, re.findall(r'\b\w+\b', pair["spanish"])))
|
52 |
|
53 |
def get_distractors(target_word, all_words, num_distractors=3):
|
54 |
"""
|