1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Santakku fonts and sign list\n",
    "\n",
    "## Provenance\n",
    "\n",
    "On the advice of Martin Worthington I visited the\n",
    "[Cambridge Cuneify+ page](http://www.hethport.uni-wuerzburg.de/cuneifont/).\n",
    "\n",
    "On that page there is a link to a \n",
    "[Würzburg page on Cuneiform fonts](http://www.hethport.uni-wuerzburg.de/cuneifont/)\n",
    "with a download link to\n",
    "[Old Babylonian Fonts](http://www.hethport.uni-wuerzburg.de/cuneifont/download/Santakku.zip),\n",
    "containing the Santakku(M) fonts and a sign list in PDF.\n",
    "\n",
    "I extracted the text from that PDF, sanitized it to one table cell per line by means of the text editor Vim,\n",
    "and that file is the source of this notebook, that tries to restore the orginal table in a tab separated format.\n",
    "\n",
    "The PDF is in the *docs* directory of this repo.\n",
    "\n",
    "The sanitized text file is the file *sources/writing/Santakku.txt* in this repository."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Problems\n",
    "\n",
    "While the text extraction and sanitizing went reasonably well, there are problems with empty cells.\n",
    "\n",
    "The table is seven columns wide, but there are not seven lines per row in the text file due to missing cells.\n",
    "\n",
    "Yet we can align by means of the typical values in the cells (unicode code points, characters, small numbers).\n",
    "\n",
    "Sometimes the values are also missing.\n",
    "\n",
    "We ignore the values in the Santakku columns and also the value, so we will not suffer much by this problem.\n",
    "\n",
    "## Results\n",
    "\n",
    "We just extract these columns:\n",
    "\n",
    "* `Unicode` i.e. unicode code point,\n",
    "* `signe` i.e. grapheme,\n",
    "* `Autotext` i.e. reading"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import re"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [],
   "source": [
    "BASE = os.path.expanduser('~/github')\n",
    "ORG = 'Nino-cunei'\n",
    "REPO = 'oldbabylonian'\n",
    "\n",
    "REPO_DIR = f'{BASE}/{ORG}/{REPO}'\n",
    "\n",
    "SRC = f'{REPO_DIR}/sources/writing/Santakku.txt'\n",
    "\n",
    "CUNEI_START = int('12000', 16)\n",
    "CUNEI_END = int('13000', 16)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 106,
   "metadata": {},
   "outputs": [],
   "source": [
    "uniCandRe = re.compile(r'''^\\s*([0-9A-Fa-f]{5}[ +]*)+$''')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 108,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ERROR at line 366: out of sync \"141 12100 GI\"\n",
      "['141 12100 GI', '140 12363', 'ZI', 'mud', 'JM', 'UY', 'MUD (ḪU-ḪI)']\n",
      "ERROR at line 367: missing Borger number \"141 12100 GI\"\n",
      "['141 12100 GI', '140 12363', 'ZI', 'mud', 'JM', 'UY', 'MUD (ḪU-ḪI)']\n",
      "Seen 365 lines\n",
      "ERROR detected\n"
     ]
    }
   ],
   "source": [
    "# code below not working because I do not yet correctly all unicode code point strings\n",
    "# correctly, eg \"140 12363\"\n",
    "\n",
    "def makeMapping():\n",
    "  mapping = {}\n",
    "  \n",
    "  def finishUni():\n",
    "    if curGrapheme is None:\n",
    "      print(f'ERROR at line {i + 1}: missing grapheme for uni \"{curUni}\"')\n",
    "      print(list(reversed(prevLines)))\n",
    "      return False\n",
    "    \n",
    "    curReading = None\n",
    "    for (p, pLine) in enumerate(reversed(prevLines)):\n",
    "      curBorger = None\n",
    "      if p == 0:\n",
    "        if not (pLine.isdigit() and not 0 < int(p) < 1000):\n",
    "          print(f'ERROR at line {i + 1}: missing Borger number \"{pLine}\"')\n",
    "          print(list(reversed(prevLines)))\n",
    "          return False\n",
    "          \n",
    "        curBorger = line\n",
    "      else:\n",
    "        curReading = line\n",
    "        return True\n",
    "      \n",
    "    if curReading is None:\n",
    "      print(f'ERROR at line {i + 1}: missing reading for uni \"{curUni}\"')\n",
    "      print(list(reversed(prevLines)))\n",
    "      return False\n",
    "    \n",
    "    uniStrs = curUni.strip().split()\n",
    "    for uniStr in uniStrs:\n",
    "      uniGood = True\n",
    "      try:\n",
    "        uni = int(uniStr, 16)\n",
    "      except Exception:\n",
    "        uniGood = False\n",
    "        break\n",
    "    if not uniGood:\n",
    "      print(f'ERROR at line {i + 1}: malformed unicode number \"{curUni}\"')\n",
    "      print(list(reversed(prevLines)))\n",
    "      return False\n",
    "    unis = {int(uniStr) for uniStr in uniStrs}\n",
    "    if len(unis) != len(uniStrs):\n",
    "      print(f'ERROR at line {i + 1}: identical unis in \"{curUni}\"')\n",
    "      print(list(reversed(prevLines)))\n",
    "      return False\n",
    "        \n",
    "    for uniStr in uniStrs:\n",
    "      uniStr = uniStr.upper()\n",
    "      if uniStr in mapping:\n",
    "        print(f'ERROR at line {i + 1}: duplicate uni {uniStr} in \"{curUni}\"')\n",
    "        print(list(reversed(prevLines)))\n",
    "        return False\n",
    "\n",
    "      mapping[uniStr] = (curGrapheme, curReading)\n",
    "    return True\n",
    "            \n",
    "  with open(SRC) as fh:\n",
    "    curUni = None\n",
    "    curGrapheme = None\n",
    "    prevLines = []\n",
    "\n",
    "    i = 0\n",
    "    for line in fh:\n",
    "      i += 1\n",
    "      line = line.strip()\n",
    "      if uniCandRe.match(line):\n",
    "        if curUni:\n",
    "          if not finishUni():\n",
    "            break\n",
    "        curUni = line\n",
    "        curGrapheme = None\n",
    "        prevLines = []\n",
    "        continue\n",
    "\n",
    "      if len(prevLines) == 0:\n",
    "        curGrapheme = line\n",
    "        prevLines.append(line)\n",
    "        continue\n",
    "\n",
    "      prevLines.append(line)\n",
    "      if len(prevLines) > 6:\n",
    "        print(f'ERROR at line {i + 1}: out of sync \"{line}\"')\n",
    "        print(list(reversed(prevLines)))\n",
    "        break\n",
    "        \n",
    "    i += 1\n",
    "    good = finishUni()\n",
    "    print(f'Seen {i - 1} lines')\n",
    "\n",
    "  if good:\n",
    "    print(f'{len(mapping)} unicode characters mapped')\n",
    "  else:\n",
    "    print(f'ERROR detected')\n",
    "  return mapping\n",
    "    \n",
    "mapping = makeMapping()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [],
   "source": [
    "for (uni, (grapheme, reading)) in sorted(mapping.items()):\n",
    "  print(f'\"{chr(uni)}\" = {uni} = \"{grapheme}\" = \"{reading}\"')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}