forked from kuanghuei/Question-Answering-System
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ask.py
41 lines (32 loc) · 1.23 KB
/
ask.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
34
35
36
37
38
39
40
41
#!/usr/bin/python
#
# Usage: ./ask.py article_path num_questions
#
from nltk.tag.stanford import POSTagger
import nltk
from article import Article
from util.nltkHelper import *
import util.questionContentSelector as selector
import util.questionListGenerator as questionListGenerator
import traceback, sys, re
if __name__ == "__main__":
if len(sys.argv) != 3:
sys.exit("""
Usage: ./ask.py article_file.htm N
article_file HTML file containing the article HTML content
N Number of questions to output.
""")
article_filename = sys.argv[1]
num_questions = int(sys.argv[2])
article = Article(article_filename, 'processed')
sentences = article.get_sentence_list(False, False, False)
# Fetch sentence candidates that can be converted into questions.
selected_sentences = selector.process(sentences)
# for sent in selected_sentences:
# print sent
# Use POS Tagging and Transformation rules to generate questions
questions = questionListGenerator.process(selected_sentences, num_questions)
# Select tops and print questions
questions = questions[:num_questions]
for question in questions:
print question