def build_graph(self, pages): gtm = GraphTaskMapper() for page in pages: page.set_sentences_from_text() page.set_tasks_from_sentences() for task in page.tasks: gtm.add_node_and_edge_with_task(task) remover = TaskGraphNodeRemover(gtm.graph) remover.remove_low_score_generalized_tasks() return gtm.graph
# -*- coding: utf-8 -*- import pdb from graph_task_mapper import GraphTaskMapper from pickle_file_saver_for_ex import PickleFileSaverForEx from pickle_file_loader_for_ex import PickleFileLoaderForExpandedQuery import constants if __name__ == '__main__': original_queries = constants.QUERIES_4 pfs = PickleFileSaverForEx() pfl = PickleFileLoaderForExpandedQuery() for query in original_queries: pages = pfl.load_pages_with_task_with_query(query) gtm = GraphTaskMapper() for i, page in enumerate(pages): try: for task in page.tasks: gtm.add_node_and_edge_with_task(task) print('%i 番目のページ %s のタスクをグラフに追加しました' % (i, page.title)) except AttributeError: break print('added all edges!') pfs.save_graph_with_query(obj=gtm.graph, query=query)
# -*- coding: utf-8 -*- import pdb from graph_task_mapper import GraphTaskMapper from pickle_file_saver_for_original import PickleFileSaverForOriginal from pickle_file_loader_for_original import PickleFileLoaderForOriginal from task_data_selector import TaskDataSelector from task_subtype_data_loader import TaskSubtypeDataLoader import constants from task import Task if __name__ == '__main__': original_queries = constants.QUERIES_4 pfs = PickleFileSaverForOriginal() pfl = PickleFileLoaderForOriginal() gtm = GraphTaskMapper() with TaskDataSelector() as selector: for query in original_queries: task_ids = selector.task_ids_with_query(query) for task_id in task_ids: with TaskSubtypeDataLoader() as task_subtype_loader: distance_subtype_pairs = task_subtype_loader.distance_from_subtype_with_task_id(task_id) distance_between_subtypes = {} for pair in distance_subtype_pairs: distance_between_subtypes[pair[0]] = pair[1] task_data = selector.taskdata_with_task_id(task_id) try: task = Task(distance_between_subtypes=distance_between_subtypes, object_term=task_data[0], cmp=task_data[1],