-
Notifications
You must be signed in to change notification settings - Fork 1
/
ask
executable file
·30 lines (24 loc) · 878 Bytes
/
ask
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
#!/usr/bin/python
from TextParser import TextParser
from SentencesPreprocessor import SentencesPreprocessor
from QuestionGenerator import QuestionGenerator
from QuestionRanker import QuestionRanker
import sys
import random
article_path = sys.argv[1]
num_questions = int(sys.argv[2])
sentences = TextParser(article_path).to_sentences()
simple_sentences = SentencesPreprocessor(sentences).generate_simple_sentences()
question_bank = []
for s in simple_sentences:
questions = QuestionGenerator(s).create()
for question in questions:
if question not in question_bank:
question_bank.append(question)
qgs = map(lambda x: QuestionRanker(x), question_bank)
sentence_scores = map(lambda x: (x.question, x.score()), qgs)
ranked = sorted(sentence_scores, key=lambda x: x[1], reverse=True)
i = 0
while i < len(ranked) and i < num_questions:
print ranked[i][0]
i += 1