Skip to content

Commit

Permalink
Corrected output
Browse files Browse the repository at this point in the history
  • Loading branch information
ryhan committed Apr 16, 2013
1 parent e1559a5 commit 535a7f5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ask
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import questionFromSentence
if __name__ == '__main__':
path_to_article = sys.argv[1]
num_questions = int(sys.argv[2])
print("Generating " + str(num_questions) + " questions:")
# print("Generating " + str(num_questions) + " questions:")

# Pre-process article content.
article_content = open(path_to_article).read()
Expand Down
11 changes: 11 additions & 0 deletions modules/questionFromSentence.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import re
import nltk
import random

# GIVEN string sentence
# RETURNS (question string, success boolean)
Expand Down Expand Up @@ -34,18 +35,28 @@ def transform(sentence):
tokens = nltk.word_tokenize(sentence)
posTag = nltk.pos_tag([tokens[0]])[0]

add_why = (random.randint(0,1) == 1)

#if (tokens[1].upper() in BEING and posTag == 'PRP'):
if (len(tokens) > 1 and tokens[1].upper() in BEING):
tokens = [tokens[1].capitalize(), tokens[0].lower()] + tokens[2:]

if (add_why):
tokens = ["Why", tokens[0].lower()] + tokens[1:]

question = " ".join(tokens)
if ("," in question):
question = question.split(",")[0] + "?"

return (question, True)

if (len(tokens) > 2 and tokens[2].upper() in BEING):
tokens = [tokens[2].capitalize(), tokens[0].lower(), tokens[1].lower()] + tokens[3:]
#return (" ".join(tokens), True)

if (add_why):
tokens = ["Why", tokens[0].lower()] + tokens[1:]

question = " ".join(tokens)
if ("," in question):
question = question.split(",")[0] + "?"
Expand Down

0 comments on commit 535a7f5

Please sign in to comment.