# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# ## Merges the output of batch_classify
# This notebook contains csv files displaying batch_classify outputs and how it might be used

from crim_intervals import *
import pandas as pd
import ast
import matplotlib
from itertools import tee, combinations
import numpy as np
from fractions import Fraction
import re


# +
# Identify Files to be joined and read them
file1 = "/Users/rfreedma/Documents/Python_Projects/CRIM-notebooks/CRIM/CRIM_Model_0019_generic_close_real.csv"
file2 = "/Users/rfreedma/Documents/Python_Projects/CRIM-notebooks/CRIM/CRIM_Mass_0019_1_generic_close_real.csv"
file3 = "/Users/rfreedma/Documents/Python_Projects/CRIM-notebooks/CRIM/CRIM_Mass_0019_2_generic_close_real.csv"
file4 = "/Users/rfreedma/Documents/Python_Projects/CRIM-notebooks/CRIM/CRIM_Mass_0019_3_generic_close_real.csv"
file5 = "/Users/rfreedma/Documents/Python_Projects/CRIM-notebooks/CRIM/CRIM_Mass_0019_4_generic_close_real.csv"
file6 = "/Users/rfreedma/Documents/Python_Projects/CRIM-notebooks/CRIM/CRIM_Mass_0019_5_generic_close_real.csv"

df1 = pd.read_csv(file1, skiprows=[1]).rename(columns={"Unnamed: 0": "entry_number"})
df2 = pd.read_csv(file2, skiprows=[1]).rename(columns={"Unnamed: 0": "entry_number"})
df3 = pd.read_csv(file3, skiprows=[1]).rename(columns={"Unnamed: 0": "entry_number"})
df4 = pd.read_csv(file4, skiprows=[1]).rename(columns={"Unnamed: 0": "entry_number"})
df5 = pd.read_csv(file5, skiprows=[1]).rename(columns={"Unnamed: 0": "entry_number"})
df6 = pd.read_csv(file6, skiprows=[1]).rename(columns={"Unnamed: 0": "entry_number"})


# +
# Join them together.  Option to Sort by Any Column Needed.  
# Also option to drop Singletons or filter by any Type
# 
df3 = pd.concat([df1, df2, df3, df4, df5, df6], sort=True)[df1.columns].copy()
df3 = df3.fillna("-")
            
df3 = df3.sort_values(['start', "piece_title", 'pattern_generating_match']).copy()

df3.drop(df3[df3['predicted_type'] == "Singleton"].index, inplace = True)
df3.drop(columns=["entry_number"], inplace = True) 
df3 = df3.reset_index()
df3.drop(columns="index", inplace = True)
# df3 = df3[df3["predicted_type"] == "Fuga"]
df3.drop_duplicates().copy()
# df3.to_csv("merged.csv")

# +
df3["pattern_matched"] = df3.pattern_matched.apply(pd.eval).apply(tuple)

df3["unique_titles_for_pattern"] = df3.groupby("pattern_matched").piece_title.transform(lambda group: group.nunique())

df4 = df3[df3.unique_titles_for_pattern > 0]

df5 = df4.sort_values("pattern_matched")

df5.head(50)

# -

df5.to_csv("Palestrina_Veni__combined.csv")





StarcoderdataJupyterScriptsDedupFiltered