Python Forum
Use PM4PY and create working file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Use PM4PY and create working file
#1
Hello
I have a small project to read a text file ( a small book) and make some data mining using nltk library and pm4py. With nltk libray ok but with pm4py i have a few issues. For example my basic issue is how to convert a text file to xes file with activities date and time and be a format like the picture

https://pm4py.fit.fraunhofer.de/static/a...apshot.png

I figured to read a text file (book) and create a xes file with random dates and hours and names but i am not sure if create the correct file

i tried this:

#Program that will create a file from text with random dates and time and save it as xes

import pm4py
from pm4py.objects.log.obj import EventLog, Trace, Event
from datetime import datetime, timedelta
import random

# Specify the path to read file
input_text_file = 'C:\\Users\\User\\Desktop\python\Program_Prof\\room.txt'

# Read the content of the text file
with open(input_text_file, 'r', encoding='utf-8') as file:
    activity_names = [activity.strip() for activity in file.readlines()]

# Create an empty event log
event_log = EventLog()

# Specify the number of traces and events per trace
num_traces = 10
num_events_per_trace = 5

# Generate random traces with activities, hours, and datetime
for _ in range(num_traces):
    trace = Trace()
    for _ in range(num_events_per_trace):
        activity = random.choice(activity_names)
        random_datetime = datetime.now() - timedelta(days=random.randint(0, 30), hours=random.randint(0, 23), minutes=random.randint(0, 59))

        event = Event()
        event['concept:name'] = activity
        event['time:timestamp'] = random_datetime
        event['custom:additional_column'] = 'some_value'  # Add custom columns as needed

        trace.append(event)

    event_log.append(trace)

# Specify the path to your output XES file
output_xes_file = 'C:\\Users\\User\\Desktop\python\Program_Prof\\room5.xes'

# Write the event log to the XES file
pm4py.write_xes(event_log, output_xes_file)

print(f"XES log with random data saved to {output_xes_file}")

#read and print first activities

xes_file_path = 'C:\\Users\\User\\Desktop\python\Program_Prof\\room5.xes'

# Open the XES file and print the first 10 lines
with open(xes_file_path, 'r', encoding='utf-8') as file:
    for i in range(30):
        line = file.readline()
        print(line.strip())
Any better ideas to create my xes file better so i can use algorithms like fuzy miner and alpha miner and obtain Process Model and a map process
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Create Choices from .ods file columns cspower 3 614 Dec-28-2023, 09:59 PM
Last Post: deanhystad
  Recommended way to read/create PDF file? Winfried 3 2,901 Nov-26-2023, 07:51 AM
Last Post: Pedroski55
  Create csv file with 4 columns for process mining thomaskissas33 3 759 Nov-06-2023, 09:36 PM
Last Post: deanhystad
  create exe file for linux? korenron 2 985 Mar-22-2023, 01:42 PM
Last Post: korenron
  my first file won't create itself MehHz2526 2 905 Nov-27-2022, 12:58 AM
Last Post: MehHz2526
  Create multiple/single csv file for each sql records mg24 6 1,406 Sep-29-2022, 08:06 AM
Last Post: buran
Sad pandas writer create "corrupted" file freko75 1 2,828 Jun-14-2022, 09:57 PM
Last Post: snippsat
  create new log file on logging? korenron 6 2,313 Mar-22-2022, 07:14 AM
Last Post: korenron
Question apk file not working on android polya001 0 1,161 Feb-06-2022, 11:58 PM
Last Post: polya001
  Create zip file from the BLOB column in ORACLE DB nnsatpute 2 1,948 Dec-31-2021, 11:00 AM
Last Post: ibreeden

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020