Generate pm4py log using ASP GeneratorΒΆ

ASP log generator uses the decl model which converts the model into abudction logic programming and pass to the clingo. Clingo generates the output which is turned into the pm4py log or can be created a .xes file.

[ ]:
!python --version
[9]:
import os
import pathlib

from Declare4Py.ProcessMiningTasks.ASPLogGeneration.asp_generator import AspGenerator
from Declare4Py.ProcessModels.DeclareModel import DeclareModel
[10]:
decl_model_1 = "decl_files/Response.decl"
decl_model_2 = "decl_files/MikeModel.decl"
decl_model_3 = "decl_files/reference10.decl"
decl_model_4 = "diagonisis.decl"
decl_folder = "decl_files"

decl_filename = decl_model_4.split(".")[0]
output_file = pathlib.Path(".", f"{decl_filename}.xes")
decl_file = pathlib.Path(".", decl_folder, decl_model_4)
[11]:
# Create Declare model by reading declare model from a file.

model: DeclareModel = DeclareModel().parse_from_file(decl_file)
[12]:
#general Setting

# Number of traces that should be generated
num_of_traces = 50

# Minimum and maximum number of events a trace can contain
(num_min_events, num_max_events) = (2, 5)

[13]:
# Initializing ASP generator with default distributor which is uniform.

#logging.basicConfig(level=logging.DEBUG)
asp = AspGenerator(
    model,
    num_of_traces,
    num_min_events,
    num_max_events,
    encode_decl_model=True  #
)
# NON CAPISCO QUESTO ULTIMO TRUE
[14]:
# Violates some constraints for declare model

# NOTE: this examples or cell is only configured according to the `decl_model_4` file

# You can add constraint templates as a string array to be violated from the declared model lines.
# You can use the flag `violate_all_constraints_in_subset` in order to tell clingo, to violate all
# templates or some of them( will be decided by clingo). The second param = True means
# all the contstraint should be violate which are available in the subset (which you add in the array string/int).



asp.set_constraints_to_violate(1, True, [
    # "Existence[act2] | |",
    # "Existence[act4] | |"
    "Response[Driving_Test, Resit] |A.Grade<=2 | |"
    # "Chain Response[Admission IC, Admission NC] |A.org:group is J |T.org:group is J |61534,61534,s",
    # "Chain Response[LacticAcid, Leucocytes] |A.LacticAcid <= 0.8 |T.Leucocytes >= 13.8 |0,2778,m",
])


# the deference between these two methods is that you can decide if you want to pass the constraint
# template list of strings or the indexes of constraint templates generated by model itself in order

# asp.set_constraints_to_violate_by_template_index(1, True, [2])

[15]:
# Generate the traces and parse the result produced by clingo
asp.run()  # Run accets 1 optional value whether to create file for the ASP generated from given declare model

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/var/folders/5w/6k152p214xbc6ghcldxtvf2r0000gq/T/ipykernel_31137/4122125268.py in <module>
      1 # Generate the traces and parse the result produced by clingo
----> 2 asp.run()  # Run accets 1 optional value whether to create file for the ASP generated from given declare model

~/PycharmProjects/declare4py-v2.0/src/Declare4Py/ProcessMiningTasks/ASPLogGeneration/asp_generator.py in run(self, generated_asp_file_path)
    218                                                        dupl_decl_model, violation)
    219             else:
--> 220                 lp = self.generate_asp_from_decl_model(self.encode_decl_model, None, dupl_decl_model, violation)
    221                 self.__generate_traces(lp, neg_traces_dist, "negative")
    222

~/PycharmProjects/declare4py-v2.0/src/Declare4Py/ProcessMiningTasks/ASPLogGeneration/asp_generator.py in generate_asp_from_decl_model(self, encode, save_file, process_model, violation)
    122             process_model = self.process_model
    123         self.py_logger.debug("Translate declare model to ASP")
--> 124         self.lp_model = ASPModel(encode).from_decl_model(process_model, violation)
    125         self.__handle_activations_condition_asp_generation()
    126         lp = self.lp_model.to_str()

~/PycharmProjects/declare4py-v2.0/src/Declare4Py/ProcessMiningTasks/ASPLogGeneration/ASPTranslator/asp_translator.py in from_decl_model(self, decl_model, constraint_violation)
    164         for template_idx in model.templates:
    165             ct = model.templates[template_idx]
--> 166             self.add_template(ct, model.attributes_list)
    167             constraints_violate[template_idx] = ct.violate
    168

~/PycharmProjects/declare4py-v2.0/src/Declare4Py/ProcessMiningTasks/ASPLogGeneration/ASPTranslator/asp_translator.py in add_template(self, ct, props)
    107         self.templates_s.append(f"template({ct.template_index},\"{ct.get_template_name()}\").")
    108
--> 109         ls = self.condition_resolver.resolve_to_asp(ct, props)
    110         if ls and len(ls) > 0:
    111             self.templates_s = self.templates_s + ls + ["\n"]

~/PycharmProjects/declare4py-v2.0/src/Declare4Py/ProcessMiningTasks/ASPLogGeneration/ASPTranslator/declare_constraint_resolver.py in resolve_to_asp(self, ct, attrs)
     38         if ct.template.is_binary:
     39             tar_ev: DeclareModelEvent = ct.events_activities[1]
---> 40             tar_ev_name = tar_ev.event_name.get_encoded_name() if self.is_encoded else tar_ev.event_name.get_name()
     41             ls.append('target({},{}).'.format(idx, tar_ev_name))
     42         if activation:

AttributeError: 'NoneType' object has no attribute 'event_name'
[ ]:
# Save file to xes
asp.to_xes(output_file.as_posix())
[ ]: