-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmcq_questions.py
33 lines (27 loc) · 883 Bytes
/
mcq_questions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import nltk
import random
nltk.download('wordnet')
from nltk.corpus import wordnet
from gap_questions import create_gap_questions
def concatenateStrings(list):
result = ''
for string in list:
result += string
return result
def create_mcq_questions(sentence):
gap_question_answer = create_gap_questions(sentence)
answer = ''
if gap_question_answer:
answer = gap_question_answer['answer']
antonyms = []
if answer:
answer_elements = answer.split()
remaining = concatenateStrings(answer_elements[1:])
for syn in wordnet.synsets(answer_elements[0]):
for lm in syn.lemmas():
if lm.antonyms():
antonyms.append(lm.antonyms()[0].name() + " " + remaining)
if len(antonyms) != 0:
return [gap_question_answer, antonyms]
else:
return None