alexgreene / WikiQuiz

Generates a quiz for a Wikipedia page using parts of speech and text chunking.
MIT License
803 stars 58 forks source link

Raises 500 error for some but not all articles #7

Closed svisser closed 7 years ago

svisser commented 7 years ago

There are articles where it raises a 500 error in case it's unable to generate any questions.

For example, for "beer" (I added some lines to print the relevant exception traceback):

Traceback (most recent call last):
  File "python/server.py", line 17, in get_quiz
    for question in a.quiz.get_ten_random():
  File "/Users/svisser/projects/WikiQuiz/python/Quiz.py", line 19, in get_ten_random
    selected.append(random.choice(self.questions))
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/random.py", line 275, in choice
    return seq[int(self.random() * len(seq))]  # raises IndexError if seq is empty
IndexError: list index out of range

This is different from https://github.com/alexgreene/WikiQuiz/issues/1 as I'm able to run the project successfully for other articles (like "baseball").

c-w commented 7 years ago

This may be fixed for free by the change to the sampling logic suggested by #11, specifically by this explicit check for empty sequences before sampling.