def process_document(config, corpus, key, output_dir): """ Read the document and write an equivalent .seg file in the output path """ doc = corpus[key] if config.emit_resources: rstuff = ResourceAnnos(resources=[x for x in doc.units if is_resource(x)], anaphora=[x for x in doc.relations if x.type == "Anaphora"], several=[x for x in doc.schemas if x.type == "Several_resources"]) else: rstuff = ResourceAnnos(resources=[], anaphora=[], several=[]) # print(rstuff.anaphora) output_filename = output_path_stub(output_dir, key) + ".seg" mk_parent_dirs(output_filename) context = Context.for_edus(doc) infos_ = [get_eduinfo(config, doc, context, rstuff, edu) for edu in sorted_first_widest(context)] if config.fake_turn_ids: infos = [eduinfo_set_turn_id(x, i + 1) for i, x in enumerate(infos_)] else: infos = [x for x in infos_ if x.turn_id is not None] with codecs.open(output_filename, 'w', 'utf-8') as fout: print(eduinfo_list_to_string(config, infos), file=fout)
def process_document(config, corpus, key, output_dir): """ Read the document and write an equivalent .seg file in the output path """ doc = corpus[key] if config.emit_resources: rstuff = ResourceAnnos( resources=[x for x in doc.units if is_resource(x)], anaphora=[x for x in doc.relations if x.type == "Anaphora"], several=[x for x in doc.schemas if x.type == "Several_resources"]) else: rstuff = ResourceAnnos(resources=[], anaphora=[], several=[]) # print(rstuff.anaphora) output_filename = output_path_stub(output_dir, key) + ".seg" mk_parent_dirs(output_filename) context = Context.for_edus(doc) infos_ = [ get_eduinfo(config, doc, context, rstuff, edu) for edu in sorted_first_widest(context) ] if config.fake_turn_ids: infos = [eduinfo_set_turn_id(x, i + 1) for i, x in enumerate(infos_)] else: infos = [x for x in infos_ if x.turn_id is not None] with codecs.open(output_filename, 'w', 'utf-8') as fout: print(eduinfo_list_to_string(config, infos), file=fout)
def dump_graph(dump_filename, graph): """ Write a dot graph and possibly run graphviz on it """ dot_graph = stac_gr.DotGraph(graph) dot_file = dump_filename + '.dot' svg_file = dump_filename + '.svg' mk_parent_dirs(dot_file) with codecs.open(dot_file, 'w', encoding='utf-8') as dotf: print(dot_graph.to_string(), file=dotf) print("Creating %s" % svg_file, file=sys.stderr) subprocess.call('dot -T svg -o %s %s' % (svg_file, dot_file), shell=True)