6
6
import requests
7
7
from tutorial .conf import system_instance , workspace_id , user_name , pw
8
8
9
+
9
10
class ExplainerSignal :
10
11
def __init__ (self ):
11
12
self .constraints = [] # List to store constraints (constraint patterns)
@@ -80,7 +81,7 @@ def conformant(self, trace, constraints=None):
80
81
:return: Boolean indicating if the trace is conformant with all constraints.
81
82
"""
82
83
if constraints == None :
83
- return self .post_query_trace_in_dataset (trace , self .constraints )
84
+ return self .post_query_trace_in_dataset (trace , self .constraints )
84
85
return self .post_query_trace_in_dataset (trace , constraints )
85
86
86
87
def minimal_expl (self , trace ):
@@ -224,13 +225,14 @@ def get_nodes_from_constraint(self, constraint=None):
224
225
return list (set (self .filter_keywords (constraint )))
225
226
226
227
def filter_keywords (self , text ):
227
- """ Extracts the events from a SIGNAL constraint
228
+ """
229
+ Extracts the events from a SIGNAL constraint
228
230
229
231
Args:
230
232
text (String): The SIGNAL constraint
231
233
232
234
Returns:
233
- [String]: A list of the filtered events from the SIGNAL constraint
235
+ [String]: A list of the filtered events from the SIGNAL constraint
234
236
"""
235
237
text = re .sub (r"\s+" , "_" , text .strip ())
236
238
words = re .findall (r"\b[A-Z_a-z]+\b" , text )
@@ -392,7 +394,7 @@ def constraint_ctrb_to_fitness(self, log=None, constraints=None, index=-1):
392
394
len_log = self .get_total_cases ()
393
395
return ctrb_count / (len_log * len (constraints ))
394
396
395
- def check_conformance (self , constraint , negative = True ):
397
+ def check_conformance (self , constraint , negative = True ):
396
398
"""
397
399
Checks the conformance of the event log against a specific constraint.
398
400
@@ -419,7 +421,9 @@ def check_violations(self, constraints):
419
421
combined_constraints = " OR " .join (
420
422
[f"NOT event_name MATCHES { constraint } " for constraint in constraints ]
421
423
)
422
- query = f'SELECT COUNT(CASE_ID) FROM "defaultview-4" WHERE { combined_constraints } '
424
+ query = (
425
+ f'SELECT COUNT(CASE_ID) FROM "defaultview-4" WHERE { combined_constraints } '
426
+ )
423
427
return self .post_query (query ) # Execute the query and return the result
424
428
425
429
def get_total_cases (self ):
@@ -442,7 +446,7 @@ def post_query(self, query):
442
446
cache_key = hash (query ) # Generate a cache key for the query
443
447
if cache_key in self .cache : # Check if the result is already in the cache
444
448
return self .cache [cache_key ] # Return cached result if available
445
-
449
+
446
450
# Send the query to the server
447
451
request = requests .post (
448
452
self .signal_endpoint ,
@@ -464,15 +468,15 @@ def post_query_trace_in_dataset(self, trace, constraints):
464
468
"""
465
469
if not constraints :
466
470
constraints = self .constraints # Use self.constraints if none are provided
467
-
471
+
468
472
# Combine constraints with AND if there are multiple, otherwise use the single constraint
469
473
if len (constraints ) > 1 :
470
474
constraints = " AND " .join (
471
475
[f"event_name MATCHES { constraint } " for constraint in constraints ]
472
476
)
473
477
else :
474
478
constraints = "" .join (f"event_name MATCHES { constraints [0 ]} " )
475
-
479
+
476
480
# Formulate the query
477
481
query = f'SELECT ACTIVITY, COUNT(CASE_ID) FROM "defaultview-4" WHERE { constraints } '
478
482
cache_key = hash (query ) # Generate a cache key for the query
@@ -503,8 +507,12 @@ def get_all_conformant_traces(self):
503
507
constraints = "" .join (f"event_name MATCHES { constraints [0 ]} " )
504
508
505
509
# Formulate the query
506
- query = f'SELECT ACTIVITY, COUNT(CASE_ID) FROM "defaultview-4" WHERE { constraints } '
507
- return self .post_query_return_all (query ) # Execute the query and return the list of conformant traces
510
+ query = (
511
+ f'SELECT ACTIVITY, COUNT(CASE_ID) FROM "defaultview-4" WHERE { constraints } '
512
+ )
513
+ return self .post_query_return_all (
514
+ query
515
+ ) # Execute the query and return the list of conformant traces
508
516
509
517
def post_query_return_all (self , query ):
510
518
"""
@@ -516,7 +524,7 @@ def post_query_return_all(self, query):
516
524
cache_key = hash (query ) # Generate a cache key for the query
517
525
if cache_key in self .cache : # Check if the result is already in the cache
518
526
return self .cache [cache_key ] # Return cached result if available
519
-
527
+
520
528
# Send the query to the server
521
529
request = requests .post (
522
530
self .signal_endpoint ,
0 commit comments