def test_trees(): root_path = "/Users/minjoon/Desktop/questions2" if not os.path.exists(root_path): os.mkdir(root_path) k = 300 numbers = [26, 28] questions = geoserver_interface.download_questions(numbers) for pk, question in questions.iteritems(): folder_name = get_number_string(pk, 4) question_path = os.path.join(root_path, folder_name) if not os.path.exists(question_path): os.mkdir(question_path) lexical_parses = get_lexical_parses(question.text) for idx, lexical_parse in enumerate(lexical_parses): sentence_folder_name = get_number_string(idx, 2) sentence_path = os.path.join(question_path, sentence_folder_name) if not os.path.exists(sentence_path): os.mkdir(sentence_path) syntax = create_syntax(lexical_parse.tokens, k) syntax.save_graphs(sentence_path) print(pk, idx)
def zip_diagrams(questions, dest): """ zip just the diagrams in the questions and save the file in the destination :param dict questions: :param str dest: :return: """ with ZipFile(dest, 'w') as myzip: for key, question in questions.iteritems(): assert isinstance(question, Question) number_string = get_number_string(int(question.key), 4) myzip.write(question.diagram_path, "%s.png" % number_string) return True
def save_questions(query): questions = geoserver_interface.download_questions(query) base_path = os.path.join("../../temp/data/", query) if not os.path.exists(base_path): os.mkdir(base_path) for index, (key, question) in enumerate(questions.iteritems()): print key folder_name = get_number_string(index, 3) json_path = os.path.join(base_path, folder_name + ".json") diagram_path = os.path.join(base_path, folder_name + ".png") d = {} d['key'] = question.key d['text'] = question.text d['choices'] = question.choices d['answer'] = str(int(question.answer)) json.dump(d, open(json_path, 'wb')) shutil.copyfile(question.diagram_path, diagram_path)
def syntax_save_graphs(syntax, root_path): for idx, syntax_tree in syntax.syntax_trees.iteritems(): file_name = "%s.png" % get_number_string(idx, 2) full_path = os.path.join(root_path, file_name) save_graph_image(syntax_tree.graph, full_path)