def __init__(self): super().__init__() self.register(XMxmlSerializer()) self.register(XMxmlGZIPSerializer()) self.register(XesXmlSerializer()) self.set_current_default(XesXmlGZIPSerializer())
def save_event_log_to_file(log, file_path): """This method serialises a created log to a file. Keyword arguments: log -- the log generated by the `cohort_to_event_log` method file_path -- the file path / name """ with open(file_path, "w") as file: XesXmlSerializer().serialize(log, file)
def extract(indexer, manifestPath, xesFilePath): manifest = json.load(open(manifestPath)) log = XFactory.create_log() switches = {} with open("./transactionsFromIndexer.txt", "w") as f: f.write("") for key in manifest: if (key == "xesExtensions"): setExtension(log, manifest[key]) elif (key == "xesClassifiers"): setClassifiers(log, manifest[key]) elif (key == "xesGlobals"): setGlobals(log, manifest[key]) elif (key == "switches"): switches = manifest[key] try: mappings = manifest["mappings"] except: print("Missing mappings in the manifest!") mapLog(log, mappings, indexer, switches) with open(xesFilePath, "w") as file: XesXmlSerializer().serialize(log, file)
dictionary = {} for i in range(len(first_line)): if "yyyy" in first_line[i]: # Convert csv date format in xes date format first_line[i] = first_line[i].replace("dd", "%d").\ replace("MM", "%m").replace("yyyy", "%Y").replace("HH", "%H").\ replace("mm", "%M") dictionary[str(i)] = first_line[i].strip("\n") first_event = file.readline().split(";") actual_trace = first_event[0] log = XFactory.create_log() trace = XFactory.create_trace() trace.append(convert_line_in_event(dictionary, first_event)) for line in file.readlines(): line_list = line.split(";") event = convert_line_in_event(dictionary, line_list) if line_list[0] == actual_trace: # View the Case Id trace.append(event) else: log.append(trace) trace = XFactory.create_trace() trace.append(event) # Save log in xes format with open("xes_file/csv_log_in_xes_format.xes", "w") as file: XesXmlSerializer().serialize(log, file)
def export_log(log, fpath): with open(fpath, 'w') as f: XesXmlSerializer().serialize(log, f)
return merged_log if __name__ == "__main__": normLogs = [] devLogs = [] normPathTemp = "out_xraynorm{}.xes" devPathTemp = "out_xraydev{}.xes" normLogCount = 7 devLogCount = 1 for i in range(1, normLogCount + 1): logPath = normPathTemp.format(i) with open(logPath) as log_file: normLogs.append(XUniversalParser().parse(log_file)[0]) for i in range(1, devLogCount + 1): logPath = devPathTemp.format(i) with open(logPath) as log_file: devLogs.append(XUniversalParser().parse(log_file)[0]) merged_log = merge_and_label(normLogs, devLogs) shuffle(merged_log) with open("merged_xray.xes", "w") as f: XesXmlSerializer().serialize(merged_log, f)
reduce(lambda x, y: x.union(y), map(set, traces)))) positive_log = XFactory.create_log() negative_log = XFactory.create_log() assert len(acceptances) == len(traces) for acc, t in zip(acceptances, traces): trace = XFactory.create_trace() for e in t: event = XFactory.create_event() attribute = XFactory.create_attribute_literal("concept:name", e) event.get_attributes()["string"] = attribute trace.append(event) if acc == "Y": positive_log.append(trace) else: negative_log.append(trace) path_positives = os.path.join(outdir, "T_OK.xes") path_negatives = os.path.join(outdir, "T.xes") with open(path_positives, mode="w") as fout: XesXmlSerializer().serialize(positive_log, fout) with open(path_negatives, mode="w") as fout: XesXmlSerializer().serialize(negative_log, fout) shutil.copy(path_positives, Path(traindir)) shutil.copy(path_negatives, Path(traindir)) shutil.copy(path_positives, Path(testdir)) shutil.copy(path_negatives, Path(testdir))