n_jobs=NUM_THREADS) # Create the cluster with the log vector kmeans.fit(log_vector) # Create new log with the attribute for the original log new_logs = {} for i in range(len(kmeans.cluster_centers_)): new_log = XFactory.create_log(log.get_attributes().clone()) for elem in log.get_extensions(): new_log.get_extensions().add(elem) new_log.__classifiers = log.get_classifiers().copy() new_log.__globalTraceAttributes = log.get_global_trace_attributes( ).copy() new_log.__globalEventAttributes = log.get_global_event_attributes( ).copy() new_logs[str(i)] = new_log # Distribute the trace depending the cluster. for point, trace in zip(log_vector, log): cluster = kmeans.predict([point])[0] new_logs[str(cluster)].append(trace) # Write the new logs log_id = 0 for log in new_logs.values(): with open("xes_file/New_cluster_log_{}.xes".format(str(log_id)), "w") as file: XesXmlSerializer().serialize(log, file) log_id += 1
""" from opyenxes.data_in.XUniversalParser import XUniversalParser from opyenxes.data_out.XesXmlSerializer import XesXmlSerializer path = "xes_file/general_example.xes" with open(path) as log_file: log = XUniversalParser().parse(log_file)[0] # Search in global trace attribute for attribute in log.get_global_trace_attributes(): if attribute.get_key() in ["Resource", "org:resource"]: attribute.set_value("UNKNOWN") # Search in global event attribute for attribute in log.get_global_event_attributes(): if attribute.get_key() in ["Resource", "org:resource"]: attribute.set_value("UNKNOWN") # Search in trace for trace in log: # Search in trace attribute for attribute in trace.get_attributes().values(): if attribute.get_key() in ["Resource", "org:resource"]: attribute.set_value("UNKNOWN") # Search in event for event in trace: # Search in event attribute for attribute in event.get_attributes().values(): if attribute.get_key() in ["Resource", "org:resource"]: attribute.set_value("UNKNOWN")