johnpaulbin commited on
Commit
8ef2116
·
1 Parent(s): 73f20e9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -52,7 +52,7 @@ for pair in json_data:
52
 
53
  def get_distractors(target_word, all_words, num_distractors=3):
54
  """
55
- Get distractor words.
56
  """
57
  distractors = set()
58
  while len(distractors) < num_distractors:
@@ -62,7 +62,7 @@ def get_distractors(target_word, all_words, num_distractors=3):
62
  return list(distractors)
63
 
64
  @app.route('/fillgame')
65
- def random_spanish_pair2():
66
  # Select a random English-Spanish pair
67
  random_pair = random.choice(json_data)
68
 
@@ -76,14 +76,14 @@ def random_spanish_pair2():
76
  language = 'spanish'
77
  word_set = spanish_words
78
 
79
- # Split the sentence into words
80
- words = re.findall(r'\b\w+\b', sentence)
81
 
82
  # Choose a random word to replace with blank
83
- blank_word = random.choice(words)
84
  sentence_with_blank = sentence.replace(blank_word, "_____")
85
 
86
- # Get distractors
87
  distractors = get_distractors(blank_word, word_set)
88
 
89
  # Combine correct word with distractors and shuffle
 
52
 
53
  def get_distractors(target_word, all_words, num_distractors=3):
54
  """
55
+ Get distractor words from the same language.
56
  """
57
  distractors = set()
58
  while len(distractors) < num_distractors:
 
62
  return list(distractors)
63
 
64
  @app.route('/fillgame')
65
+ def random_spanish_pair():
66
  # Select a random English-Spanish pair
67
  random_pair = random.choice(json_data)
68
 
 
76
  language = 'spanish'
77
  word_set = spanish_words
78
 
79
+ # Split the sentence into words and filter out non-words
80
+ words = filter(is_word, re.findall(r'\b\w+\b', sentence))
81
 
82
  # Choose a random word to replace with blank
83
+ blank_word = random.choice(list(words))
84
  sentence_with_blank = sentence.replace(blank_word, "_____")
85
 
86
+ # Get distractors from the same language
87
  distractors = get_distractors(blank_word, word_set)
88
 
89
  # Combine correct word with distractors and shuffle