XES Files

Read XES

read_xes() can be used to read XES files and turn the data into an eventlog object in R. The function needs only one xesfile argument. This can be a local path to a file with a .xes extension or an URL. An example XES file can be found at the following link: https://bupar.net/eventdata/exercise1.xes. When opening this file in a browser, you will see that it is an XML file. More information on the notation can be found here.

Importing a XES file is easily done as follows:

library(xesreadR)
data <- read_xes("https://bupar.net/eventdata/exercise1.xes")
## Warning: `data_frame()` was deprecated in tibble 1.1.0.
## ℹ Please use `tibble()` instead.
## ℹ The deprecated feature was likely used in the xesreadR package.
##   Please report the issue to the authors.
## Warning: `as_data_frame()` was deprecated in tibble 2.0.0.
## ℹ Please use `as_tibble()` instead.
## ℹ The signature and semantics have changed, see `?as_tibble`.
## ℹ The deprecated feature was likely used in the xesreadR package.
##   Please report the issue to the authors.
## Warning in read_xes("https://bupar.net/eventdata/exercise1.xes"): No activity
## instance identifier specified in xes-file. By default considered each event as a
## different activity instance. Please check!
data
## # Log of 11 events consisting of:
## 3 traces 
## 3 cases 
## 11 instances of 5 activities 
## 1 resource 
## Events occurred from 2008-12-09 07:20:01 until 2008-12-09 07:23:01 
##  
## # Variables were mapped as follows:
## Case identifier:     CASE_concept_name 
## Activity identifier:     activity_id 
## Resource identifier:     resource_id 
## Activity instance identifier:    activity_instance_id 
## Timestamp:           timestamp 
## Lifecycle transition:        lifecycle_id 
## 
## # A tibble: 11 × 7
##    CASE_concept_name activi…¹ lifec…² resou…³ timestamp           activ…⁴ .order
##    <chr>             <chr>    <chr>   <chr>   <dttm>                <int>  <int>
##  1 Case3.0           A        comple… UNDEFI… 2008-12-09 07:20:01       1      1
##  2 Case3.0           E        comple… UNDEFI… 2008-12-09 07:21:01       2      2
##  3 Case3.0           D        comple… UNDEFI… 2008-12-09 07:22:01       3      3
##  4 Case2.0           A        comple… UNDEFI… 2008-12-09 07:20:01       4      4
##  5 Case2.0           C        comple… UNDEFI… 2008-12-09 07:21:01       5      5
##  6 Case2.0           B        comple… UNDEFI… 2008-12-09 07:22:01       6      6
##  7 Case2.0           D        comple… UNDEFI… 2008-12-09 07:23:01       7      7
##  8 Case1.0           A        comple… UNDEFI… 2008-12-09 07:20:01       8      8
##  9 Case1.0           B        comple… UNDEFI… 2008-12-09 07:21:01       9      9
## 10 Case1.0           C        comple… UNDEFI… 2008-12-09 07:22:01      10     10
## 11 Case1.0           D        comple… UNDEFI… 2008-12-09 07:23:01      11     11
## # … with abbreviated variable names ¹​activity_id, ²​lifecycle_id, ³​resource_id,
## #   ⁴​activity_instance_id

Note that in the example above, read_xes() emits a warnings that no activity instance identifier was found. Recall that an eventlog object in R needs certain data fields to be present. However, it might be so that not all of these field are available, in which case read_xes() will throw a warning or an error. Ideally, the XES file should contain at least the following elements:

<trace>
    <string key="concept:name" value="Case3.0"/>
    <event>
        <string key="concept:name" value="A"/>
        <int key="concept:instance" value = "1"/>
        <string key="org:resource" value="UNDEFINED"/>
        <date key="time:timestamp" value="2008-12-09T08:20:01.527+01:00"/>
        <string key="lifecycle:transition" value="complete"/>
        ...
    </event>
    ...
</trace>

These elements are translated according to the terminology used in bupaR as follows:

XES bupaR
trace concept:name case_id
event concept:name activity_id
concept:instance activity_instance_id
org:resource resource_id
time:timestamp timestamp
lifecycle:transition lifecycle_id

When there is no case identifier, an artificial case identifier CASE_ID will be created based on the hierarchy of the XES file. In case of other missing elements, either an error or a warning will be thrown.

Errors

An error will be thrown if a XES file does not contain an activity identifier or a timestamp. As such these are the minimum requirements to create an eventlog object from a XES file.

Warnings

  • In case the lifecycle transition identifier or the resource identifier is missing, an empty placeholder variable will be created and a warning will be emitted.

  • In case the activity instance identifier is missing, a default activity instance identifier column will be added. This column will regard every event in the log as a distinct activity instance. A warning will be emitted noting that you should check whether this is a justified assumption.

  • If available, missing information can be added manually to the eventlog object by overwriting the variables, e.g. with mutate().

Additional elements

Note that both traces and events can have additional elements in the XES files. These will be added as extra variables in the resulting log. Attributes at a the level of traces will get the prefix CASE_ in their name. 1

Create list of cases

In certain circumstances, it might be useful to have a separate list of cases with case attributes. This can be obtained using read_xes_cases(). The argument for this function remains the same xesfile. The result is a data.frame with one row for each case and one column for each attribute. Non-existing attributes for a specific case are filled in with NA`s. Below, this function is illustrated using the repairExample event log, which has one case attribute called description. For the sake of illustration the entire event log is also imported.

read_xes_cases("https://bupar.net/eventdata/repairExample.xes")
## # A tibble: 1,104 × 2
##    CASE_concept_name CASE_description          
##    <chr>             <chr>                     
##  1 1                 Simulated process instance
##  2 10                Simulated process instance
##  3 100               Simulated process instance
##  4 1000              Simulated process instance
##  5 1001              Simulated process instance
##  6 1002              Simulated process instance
##  7 1003              Simulated process instance
##  8 1004              Simulated process instance
##  9 1005              Simulated process instance
## 10 1006              Simulated process instance
## # … with 1,094 more rows
read_xes("https://bupar.net/eventdata/repairExample.xes")
## Warning in read_xes("https://bupar.net/eventdata/repairExample.xes"): No
## activity instance identifier specified in xes-file. By default considered each
## event as a different activity instance. Please check!
## # Log of 11855 events consisting of:
## 77 traces 
## 1104 cases 
## 11855 instances of 8 activities 
## 13 resources 
## Events occurred from 1970-01-01 05:36:00 until 1970-01-24 08:16:00 
##  
## # Variables were mapped as follows:
## Case identifier:     CASE_concept_name 
## Activity identifier:     activity_id 
## Resource identifier:     resource_id 
## Activity instance identifier:    activity_instance_id 
## Timestamp:           timestamp 
## Lifecycle transition:        lifecycle_id 
## 
## # A tibble: 11,855 × 12
##    CASE_concep…¹ CASE_…² activ…³ defec…⁴ defec…⁵ lifec…⁶ numbe…⁷ resou…⁸ phone…⁹
##    <chr>         <chr>   <chr>   <chr>   <chr>   <chr>   <chr>   <chr>   <chr>  
##  1 1             Simula… Regist… <NA>    <NA>    comple… <NA>    System  <NA>   
##  2 1             Simula… Analyz… <NA>    <NA>    start   <NA>    Tester3 <NA>   
##  3 1             Simula… Analyz… <NA>    6       comple… <NA>    Tester3 T2     
##  4 1             Simula… Repair… <NA>    <NA>    start   <NA>    Solver… <NA>   
##  5 1             Simula… Repair… <NA>    <NA>    comple… <NA>    Solver… <NA>   
##  6 1             Simula… Test R… <NA>    <NA>    start   <NA>    Tester3 <NA>   
##  7 1             Simula… Test R… true    <NA>    comple… 0       Tester3 <NA>   
##  8 1             Simula… Inform… <NA>    <NA>    comple… <NA>    System  <NA>   
##  9 1             Simula… Archiv… true    <NA>    comple… 0       System  <NA>   
## 10 10            Simula… Regist… <NA>    <NA>    comple… <NA>    System  <NA>   
## # … with 11,845 more rows, 3 more variables: timestamp <dttm>,
## #   activity_instance_id <int>, .order <int>, and abbreviated variable names
## #   ¹​CASE_concept_name, ²​CASE_description, ³​activity_id, ⁴​defectFixed,
## #   ⁵​defectType, ⁶​lifecycle_id, ⁷​numberRepairs, ⁸​resource_id, ⁹​phoneType

Write XES

Use write_xes() to write a XES file.

args(write_xes)
## function (eventlog, xesfile = file.choose(), case_attributes = NULL) 
## NULL

It minimally requires 2 arguments:

  • an eventlog object
  • a file name/path where to store the file (if not specified, as file system window will open to save the file)

Additionally, one can specify which of the variables in the event log should be regarded as case attributes by supplying a character vector of variable names to the case_attributes argument. If this argument is not specified, all the variables starting with the prefix CASE_ will be considered as case attributes.

eventdataR::patients

write_xes(patients, "patients.xes")

Read more:


  1. On terminology: what in XES is called a trace (i.e. between tags) is called a case or process instance in bupaR. In bupaR the concept trace is reserved for an activity sequence, and is not related to a specific process instance. Many process instances can share the same trace of activities. The terminology used in bupaR is in correspondence with current literature. See creating logs for more information about the data model used.↩︎


Copyright © 2023 bupaR - Hasselt University