{ "cells": [ { "metadata": { "ExecuteTime": { "end_time": "2026-05-29T14:06:38.428305400Z", "start_time": "2026-05-29T14:06:38.413301400Z" } }, "cell_type": "code", "source": [ "import warnings\n", "warnings.filterwarnings(\"ignore\", category=UserWarning)" ], "id": "5190bc3bfe99a6e9", "outputs": [], "execution_count": 1 }, { "cell_type": "markdown", "id": "dac6605a", "metadata": {}, "source": [ "# Query Checking with the DECLARE Checker\n", "\n", "This tutorial explains how to perform the query checking of a DECLARE constraint in a log and how to browse the results. We first import the classes `DeclareQueryChecker` and `DeclareResultsBrowser` and the log." ] }, { "cell_type": "code", "id": "91723b33", "metadata": { "ExecuteTime": { "end_time": "2026-05-29T14:06:41.199965600Z", "start_time": "2026-05-29T14:06:38.432303300Z" } }, "source": [ "import os\n", "\n", "from Declare4Py.ProcessMiningTasks.QueryChecking.DeclareQueryChecker import DeclareQueryChecker\n", "from Declare4Py.ProcessMiningTasks.QueryChecking.DeclareResultsBrowser import DeclareResultsBrowser\n", "from Declare4Py.D4PyEventLog import D4PyEventLog\n", "\n", "log_path = os.path.join(\"../../../\", \"tests\", \"test_logs\",\"Sepsis Cases.xes.gz\")\n", "event_log = D4PyEventLog(case_name=\"case:concept:name\")\n", "event_log.parse_xes_log(log_path)" ], "outputs": [ { "data": { "text/plain": [ "parsing log, completed traces :: 0%| | 0/1050 [00:00\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
templateactivationtargetactivation_condition
0Chain ResponseER RegistrationER TriageA.org:group is A
1Chain ResponseER Sepsis TriageLeucocytesA.org:group is A
2Chain ResponseER Sepsis TriageIV LiquidA.org:group is A
3Chain ResponseIV LiquidIV AntibioticsA.org:group is A
4Chain ResponseIV AntibioticsAdmission NCA.org:group is A
\n", "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "execution_count": 4 }, { "cell_type": "markdown", "id": "efffc3c5", "metadata": {}, "source": [ "In the following example we compute the assignments both for the activation and the target by setting `template_str='Response'` and `min_support=0.8`:" ] }, { "cell_type": "code", "id": "7bd7cd74", "metadata": { "ExecuteTime": { "end_time": "2026-05-29T14:06:46.417264900Z", "start_time": "2026-05-29T14:06:44.969415900Z" } }, "source": [ "query_checker = DeclareQueryChecker(log=event_log, consider_vacuity=False, template='Response', min_support=0.8, return_first=False)\n", "query_check_res: DeclareResultsBrowser = query_checker.run()\n", " \n", "query_check_res.filter_query_checking(queries=['template', 'activation', 'target'])" ], "outputs": [ { "data": { "text/plain": [ " template activation target\n", "0 Response ER Registration Leucocytes\n", "1 Response ER Registration CRP\n", "2 Response ER Registration LacticAcid\n", "3 Response ER Registration ER Triage\n", "4 Response ER Registration ER Sepsis Triage\n", "5 Response ER Triage Leucocytes\n", "6 Response ER Triage CRP\n", "7 Response ER Triage ER Sepsis Triage\n", "8 Response ER Sepsis Triage Leucocytes\n", "9 Response ER Sepsis Triage CRP" ], "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
templateactivationtarget
0ResponseER RegistrationLeucocytes
1ResponseER RegistrationCRP
2ResponseER RegistrationLacticAcid
3ResponseER RegistrationER Triage
4ResponseER RegistrationER Sepsis Triage
5ResponseER TriageLeucocytes
6ResponseER TriageCRP
7ResponseER TriageER Sepsis Triage
8ResponseER Sepsis TriageLeucocytes
9ResponseER Sepsis TriageCRP
\n", "
" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "execution_count": 5 }, { "cell_type": "markdown", "id": "1588738c", "metadata": {}, "source": [ "As last example, we set the activation and the target and ask for the template:" ] }, { "cell_type": "code", "id": "cba37244", "metadata": { "ExecuteTime": { "end_time": "2026-05-29T14:06:47.431159700Z", "start_time": "2026-05-29T14:06:47.268141Z" } }, "source": [ "query_checker = DeclareQueryChecker(log=event_log, consider_vacuity=False, activation='ER Registration', target='CRP', min_support=0.2, return_first=False)\n", "query_check_res: DeclareResultsBrowser = query_checker.run()\n", "\n", "query_check_res.filter_query_checking(queries=['template', 'activation', 'target'])" ], "outputs": [ { "data": { "text/plain": [ " template activation target\n", "0 Choice ER Registration CRP\n", "1 Responded Existence ER Registration CRP\n", "2 Response ER Registration CRP\n", "3 Alternate Response ER Registration CRP\n", "4 Precedence ER Registration CRP\n", "5 Alternate Precedence ER Registration CRP\n", "6 Not Chain Response ER Registration CRP\n", "7 Not Chain Precedence ER Registration CRP" ], "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
templateactivationtarget
0ChoiceER RegistrationCRP
1Responded ExistenceER RegistrationCRP
2ResponseER RegistrationCRP
3Alternate ResponseER RegistrationCRP
4PrecedenceER RegistrationCRP
5Alternate PrecedenceER RegistrationCRP
6Not Chain ResponseER RegistrationCRP
7Not Chain PrecedenceER RegistrationCRP
\n", "
" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "execution_count": 6 } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.4" } }, "nbformat": 4, "nbformat_minor": 5 }