{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.12.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":121150,"databundleVersionId":15061024,"sourceType":"competition"}],"dockerImageVersionId":31234,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# The Šalim-Aššur Family - Increase the training data\n\nŠalim-Aššur lived thousand of years ago, but he is back from his grave to help us to translate old Akkadian transliterations.\nIf this data helps your model, let me know. Ain't no sure.\n\n**From Gemini:** The Šalim-Aššur family was a prominent merchant dynasty during the Old Assyrian period (c. 1900–1850 BCE). Their history is one of the best-documented examples of ancient international trade, thanks to an archive of over 1,000 cuneiform tablets discovered in their private home at Kültepe (ancient Kaneš), in modern-day Turkey.\n\nUnlike the \"great kings\" of later Assyrian history, the Šalim-Aššur family represents the \"Assyrian Everyman\"—a middle-class business family navigating the complexities of a 1,200-kilometer trade route between the city-state of Aššur (in Iraq) and their commercial colony in Anatolia.","metadata":{}},{"cell_type":"code","source":"import numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport re\nimport os","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2026-01-08T17:31:56.282064Z","iopub.execute_input":"2026-01-08T17:31:56.282577Z","iopub.status.idle":"2026-01-08T17:31:58.014576Z","shell.execute_reply.started":"2026-01-08T17:31:56.282529Z","shell.execute_reply":"2026-01-08T17:31:58.012331Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"INPUT_DIR = \"/kaggle/input/deep-past-initiative-machine-translation\"\n# train_df = pd.read_csv(f\"{INPUT_DIR}/train.csv\")\n# test_df = pd.read_csv(f\"{INPUT_DIR}/test.csv\")\npublications = pd.read_csv(f\"{INPUT_DIR}/publications.csv\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-08T17:31:59.752958Z","iopub.execute_input":"2026-01-08T17:31:59.755577Z","iopub.status.idle":"2026-01-08T17:32:13.707928Z","shell.execute_reply.started":"2026-01-08T17:31:59.755514Z","shell.execute_reply":"2026-01-08T17:32:13.706211Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Remove duplicates based on column, keeping the first occurrence\npub = publications.drop_duplicates(subset=['pdf_name', 'page'], keep='first')\nprint(\"\\nDataFrame after dropping duplicates (keeping first):\")\npub.head(5)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-08T17:32:13.710205Z","iopub.execute_input":"2026-01-08T17:32:13.710646Z","iopub.status.idle":"2026-01-08T17:32:13.836112Z","shell.execute_reply.started":"2026-01-08T17:32:13.710603Z","shell.execute_reply":"2026-01-08T17:32:13.833684Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"PDF_NAME = \"Larsen 2010 - The Archive of the Šalim-Aššur Family, Vol. 1. The First Two Generations. (A)TK 6-a, TTKY 33d-a, 2010 (preprint).pdf\"\nsalim = pub[pub['pdf_name'] == PDF_NAME ]\nsalim = salim[salim['has_akkadian']].reset_index()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-08T17:32:15.097396Z","iopub.execute_input":"2026-01-08T17:32:15.097848Z","iopub.status.idle":"2026-01-08T17:32:15.117412Z","shell.execute_reply.started":"2026-01-08T17:32:15.097768Z","shell.execute_reply":"2026-01-08T17:32:15.115767Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"salim","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-08T17:32:24.393101Z","iopub.execute_input":"2026-01-08T17:32:24.393542Z","iopub.status.idle":"2026-01-08T17:32:24.413959Z","shell.execute_reply.started":"2026-01-08T17:32:24.393509Z","shell.execute_reply":"2026-01-08T17:32:24.411904Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# 1. FILTER: Keep only rows with the specific titles in the first few lines\ntarget_titles = [\"§alim-A$$ur’s death\", \"§alim-A$$ur’s correspondence\", '§alim-A$$ur’s legal texts', '§alim-A$$ur’s contracts', 'Iddin-abum’s death',\n                 'Sadaya’s son', 'Ibaya’s son']\n                \ndef is_target_doc(text):\n    if not isinstance(text, str): return False\n    # Get first 5 lines to check for the title # header = \"\\n\".join(text.split('\\n')[:5])\n    header = text[:100]\n    return any(title in header for title in target_titles)\n\n    # Filtering the dataframe\ndf_filtered = salim[salim['page_text'].apply(is_target_doc)].copy()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-08T17:39:44.975592Z","iopub.execute_input":"2026-01-08T17:39:44.976070Z","iopub.status.idle":"2026-01-08T17:39:44.985701Z","shell.execute_reply.started":"2026-01-08T17:39:44.976039Z","shell.execute_reply":"2026-01-08T17:39:44.984539Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_filtered","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-08T17:39:48.654073Z","iopub.execute_input":"2026-01-08T17:39:48.655079Z","iopub.status.idle":"2026-01-08T17:39:48.668661Z","shell.execute_reply.started":"2026-01-08T17:39:48.655037Z","shell.execute_reply":"2026-01-08T17:39:48.667373Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_filtered = df_filtered[['page', 'page_text']]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-08T17:40:04.101507Z","iopub.execute_input":"2026-01-08T17:40:04.102069Z","iopub.status.idle":"2026-01-08T17:40:04.112427Z","shell.execute_reply.started":"2026-01-08T17:40:04.102036Z","shell.execute_reply":"2026-01-08T17:40:04.110962Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Set option to display the full width of columns\npd.set_option('display.max_colwidth', None)\ndf_filtered['page_text']","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-08T17:40:10.279221Z","iopub.execute_input":"2026-01-08T17:40:10.279698Z","iopub.status.idle":"2026-01-08T17:40:10.291814Z","shell.execute_reply.started":"2026-01-08T17:40:10.279663Z","shell.execute_reply":"2026-01-08T17:40:10.289949Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# 3. Process the text:\n# - We split by the literal '\\n' string\n# - 'explode' turns the list of lines into individual rows\n# - 'strip' removes any leftover whitespace\ndf_final = df_filtered.assign(page_text=df_filtered['page_text'].str.split(r'\\\\n')).explode('page_text')\n\n# 4. Clean up: Remove empty strings and reset index\ndf_final = df_final[df_final['page_text'].str.strip() != \"\"]\ndf_final['page_text'] = df_final['page_text'].str.strip()\ndf_final = df_final.reset_index(drop=True)\n\ndf_final['line_number'] = df_final.groupby('page').cumcount() + 1\nprint(df_final)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-08T17:43:02.021690Z","iopub.execute_input":"2026-01-08T17:43:02.022060Z","iopub.status.idle":"2026-01-08T17:43:02.064216Z","shell.execute_reply.started":"2026-01-08T17:43:02.022033Z","shell.execute_reply":"2026-01-08T17:43:02.063243Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Verify if is akkadian or english\ncond_dashes = df_final['page_text'].str.count('-') > 2\n# Condition B: Contains any of the special Akkadian vowels\ncond_vowels = df_final['page_text'].str.contains(r'[úùíìáàéè]', na=False)\n\n# Combine using OR (|) and assign True/False\ndf_final['is_akkad'] = cond_dashes | cond_vowels","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-08T17:57:43.617003Z","iopub.execute_input":"2026-01-08T17:57:43.617473Z","iopub.status.idle":"2026-01-08T17:57:43.645796Z","shell.execute_reply.started":"2026-01-08T17:57:43.617440Z","shell.execute_reply":"2026-01-08T17:57:43.644102Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# First break the text in lines than aggregate all akkadian or english\ndata_translit = df_final[df_final['is_akkad']]\ndata_translit = data_translit.groupby('page', as_index=False).agg(translit=('page_text', ' '.join))\n\ndata_translat = df_final[~df_final['is_akkad']]\ndata_translat = data_translat.groupby('page', as_index=False).agg(translat=('page_text', ' '.join))\n# Merge the translit with the translat\nmerged_data = pd.merge(data_translit, data_translat, on='page', how='inner')\n# Save the result\nmerged_data.to_csv('salim_assur.csv', index=False, encoding='utf-8-sig')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-08T18:12:46.677939Z","iopub.execute_input":"2026-01-08T18:12:46.678984Z","iopub.status.idle":"2026-01-08T18:12:46.714062Z","shell.execute_reply.started":"2026-01-08T18:12:46.678933Z","shell.execute_reply":"2026-01-08T18:12:46.712850Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(merged_data)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-01-08T18:12:55.227332Z","iopub.execute_input":"2026-01-08T18:12:55.227766Z","iopub.status.idle":"2026-01-08T18:12:55.240627Z","shell.execute_reply.started":"2026-01-08T18:12:55.227726Z","shell.execute_reply":"2026-01-08T18:12:55.238905Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Conclusion\n\nThe translations need to be cleaned manually before using. If used as it is, there is a decrease in the Public Score.","metadata":{}}]}