pm4py load in of sqlite-file is throwing the same naming error of my table even though I changed it

19 Views Asked by At

I am trying to read in an ocel from an Eventlog sqlite file, which I build from multiple csv-files in python. Here's the code for the creation of the sqlite file:

# Define the path to the folder in Google Drive
drive_path = '/content/drive/MyDrive/Test2/'

# Update the file search patterns
eventTypeTableFilenames = [fn for fn in glob.glob(drive_path + 'event_*.csv')
                           if not fn.endswith("event_map_type.csv") and not fn.endswith("event_object.csv")]

objectTypeTableFilenames = [fn for fn in glob.glob(drive_path + 'object_*.csv')
                             if not fn.endswith("object_map_type.csv") and not fn.endswith("object_object.csv")]

# Define the TABLES dictionary
TABLES = dict()

# Read CSV files into the TABLES dictionary
for table_name in ["event", "event_map_type", "event_object", "object", "object_object", "object_map_type"]:
    TABLES[table_name] = pd.read_csv(drive_path + table_name + ".csv", sep=",")

# Read additional event type tables
for fn in eventTypeTableFilenames:
    table_name = fn.split(".")[0].split("/")[-1]
    table = pd.read_csv(fn, sep=",")
    TABLES[table_name] = table

# Read additional object type tables
for fn in objectTypeTableFilenames:
    table_name = fn.split(".")[0].split("/")[-1]
    table = pd.read_csv(fn, sep=",")
    TABLES[table_name] = table

sql_path = "Eventlog.sqlite"
if os.path.exists(sql_path):
    os.remove(sql_path)

conn = sqlite3.connect(sql_path)
for tn, df in TABLES.items():
    df.to_sql(tn, conn, index=False)
conn.close()


# Connect to your SQLite database
conn = sqlite3.connect("Eventlog.sqlite")
cursor = conn.cursor()

# Create a new table without duplicates
cursor.execute('''CREATE TABLE IF NOT EXISTS object_object_no_duplicates AS
                  SELECT DISTINCT * FROM object_object''')

# Drop the original table
cursor.execute('DROP TABLE IF EXISTS object_object')

# Rename the new table to the original table name
cursor.execute('ALTER TABLE object_object_no_duplicates RENAME TO object_object')

# Commit changes and close the connection
conn.commit()
conn.close()


# Connect to your SQLite database
conn = sqlite3.connect("Eventlog.sqlite")
cursor = conn.cursor()

# Create a new table without duplicates
cursor.execute('''CREATE TABLE IF NOT EXISTS event_object_no_duplicates AS
                  SELECT DISTINCT * FROM event_object''')

# Drop the original table
cursor.execute('DROP TABLE IF EXISTS event_object')

# Rename the new table to the original table name
cursor.execute('ALTER TABLE event_object_no_duplicates RENAME TO event_object')

# Commit changes and close the connection
conn.commit()
conn.close()

Im am using this line of code to read in the file afterwards:

sql_path = "Eventlog.sqlite"
ocel = pm4py.read_ocel2_sqlite(sql_path)

After executing the code, I received an Error with the name of my table as it included an "-".

After removing the "-" from the csv-file table, I build the sqlite-file once more, but I still receive the same error. I also checked the table name in the database after building it from the csv-file, which is fine but it still throws the same error. I am using colab and tried refreshing the notebook, but nothing helped. The command to read in the sqlite file is stuck with the table name, which contains the "-".

0

There are 0 best solutions below