コード例 #1
0
def main_process(input_file):
	sentence_count = 0
	gen_questions = []
	final_questions = []

	with open(input_file, "r") as f:
		for line in f:
			sentences = ss.sentence_segment(line, tri_gram=False)
			sentence_count += 1

			for i in range(len(sentences)):
				questions = qg.generate(sentences[i].pos)
				for tp in questions:
					(question, answer, answer_index) = tp
					ans_eng, ans_index = wnth.get_general_info(answer)
					answer_item = _wi.word_item(answer, ans_eng, ans_index, None)
					question_item = _qui.question_item(sentences[i], sentence_count, question, answer_item, answer_index)
					gen_questions.append(question_item)
			
	ranked_questions, qrank_scores = qr.rank_question(gen_questions)
	for question in ranked_questions:
		choices = chg.generate_choices(question)
		if choices != []:
			question.add_choices(choices)
			final_questions.append(question)

	return final_questions
    def addQuestion(self, question_body, lang, sortorder, REQUEST=None):
        """ """
        id = 'q%s' % self.utGenRandomId(4)

        try: sortorder = int(sortorder)
        except: sortorder = 100

        if not self.questions.has_key(id): id = id
        else: id = id + self.utGenRandomId()

        self.questions[id] = question_item(question_body, lang, sortorder)
        self._p_changed = 1
        return REQUEST.RESPONSE.redirect('%s/manage_questions_html' % (self.absolute_url(), ))
コード例 #3
0
    def addQuestion(self, question_body, lang, sortorder, REQUEST=None):
        """ """
        id = 'q%s' % self.utGenRandomId(4)

        try:
            sortorder = int(sortorder)
        except:
            sortorder = 100

        if not self.questions.has_key(id): id = id
        else: id = id + self.utGenRandomId()

        self.questions[id] = question_item(question_body, lang, sortorder)
        self._p_changed = 1
        return REQUEST.RESPONSE.redirect('%s/manage_questions_html' %
                                         (self.absolute_url(), ))
コード例 #4
0
def get_question_item(question_file, pos_file):
	sentences = []
	sentence_with_pos = []
	with open(pos_file) as f:
		for line in f:
			read_list = ast.literal_eval(line.strip())
			for a_sentence in read_list:
				sentences.append("".join([word for (word, _) in a_sentence]))
				sentence_with_pos.append(a_sentence)

	sentence_count = 0
	all_question_items = []
	with open(question_file) as f:
		for line in f:
			read_list = ast.literal_eval(line.strip())
			for a_sentence in read_list:
				sentence_item = sentence.sentence(sentences[sentence_count], sentence_with_pos[sentence_count])
				for a_question in a_sentence:
					(question_sentence, answer, choices) = a_question
					answer_item = word_item.word_item(answer)
					answer_index = find_blank_index([tp[0] for tp in sentence_with_pos[sentence_count]], question_sentence)
					all_generated_choices = _cg.choice_generate(answer_item)
					choice_items = []
					for a_choice in choices:
						if str(a_choice) == answer:
							choice_items.append(answer_item)
						else:
							for gen_choice in all_generated_choices:
								if str(gen_choice) == a_choice:
									choice_items.append(gen_choice)
									break

					# print([str(choice) for choice in choice_items])
					question = question_item.question_item(sentence_item, sentence_count, question_sentence, answer_item, answer_index)
					question.add_choices(choice_items)
					all_question_items.append(question)

				sentence_count += 1

	return all_question_items
コード例 #5
0
	for sentence in sentences:
		print(str(sentence))
	print("======================")

	for sentence in sentences:
		for word, pos in sentence.pos:
			print(word, pos)
		print("--------", end="\n\n")

if __name__ == "__main__":
    
    # initialize - train model
    all_questions = []
    with open("ranking/test-globalwarming.out", "r") as f:
    	for line in f:
    		a_question_item = _qui.question_item(from_str=line.strip())
    		all_questions.append(a_question_item)
    
    # print_sentence_cut_results(all_questions)
    _ev.read_eval_file("ranking/evaluation/sheet1.csv", all_questions)
    _ev.read_eval_file("ranking/evaluation/sheet2.csv", all_questions)
    _ev.read_eval_file("ranking/evaluation/sheet3.csv", all_questions)
    qr = qrank.question_ranker(question_set=all_questions)
    # qr.test_kfolds(all_questions)
    choice_rank = chrank.choice_ranker(training_set=all_questions, wordnet=wnth)
    chg = _chg.choice_generator(wnth, choice_rank)
    # ranked_question, ranked_scores = qr.rank_question(generated_questions)

    args = sys.argv
    custom_dict = dict()
    if len(args) >= 2: