#!/usr/local/bin/python # -*- coding: utf-8 -*- import ast import preprocess.sentence as sentence import question_item as question_item import choices.word_item as word_item import choices.wordnet.wn_thai as wordnet_thai import choices.choice_generator as choice_gen _cg = choice_gen.choice_generator() def find_blank_index(word_list, text): for i in range(len(word_list)): word = word_list[i] if word == text[0:len(word)]: text = text[len(word):] else: return i else: return None 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)
# 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: if len(args) >= 3: custom_dict = read_custom_dict(args[2]) ss.set_custom_dict(custom_dict) wnth.set_custom_dict(custom_dict) generated_questions = main_process(args[1]) display.display(generated_questions, percent=100) # f = open("bank-choice2.dict", "w") # for question in generated_questions: # ranked_choices, choice_with_scores = choice_rank.rank_choices(question)