"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"query = f\"\"\"\n",
"tablet\n",
" sign grapheme={shinPPPat}\n",
"\"\"\"\n",
"print(query)\n",
"results = A.search(query)\n",
"A.table(results, end=20, showGraphics=True)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's see a few tablets in more detail:"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"ExecuteTime": {
"end_time": "2018-05-24T10:19:36.982430Z",
"start_time": "2018-05-24T10:19:36.884981Z"
}
},
"outputs": [
{
"data": {
"text/html": [
"result 1"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"tablet P448701
Anonymous 448701uruk-iii
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"result 2"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"tablet P448701
Anonymous 448701uruk-iii
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"result 3"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"tablet P448701
Anonymous 448701uruk-iii
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"result 4"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"tablet P006005
ATU 6, pl. 052, W 14731,ag07uruk-iiiW 14731,ag07
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"result 5"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"tablet P002329
ATU 6, pl. 065, W 15774,duruk-iiiW 15774,d
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"A.show(results, end=5, queryFeatures=False)"
]
},
{
"cell_type": "markdown",
"metadata": {
"tags": []
},
"source": [
"# A tablet calculator\n",
"\n",
"Rather than displaying search results, you can also *process* them in your program.\n",
"\n",
"Search results come as tuples of nodes that correspond directly to the elements\n",
"of your search template.\n",
"\n",
"We query for shinPP numerals on the faces of tablets.\n",
"The result of the query is a list of tuples `(t, f, s)` consisting of\n",
"a tablet node, a face node and a node for a sign of a shinPP numeral.\n",
"\n",
"## Rationale\n",
"This task will require a higher level of programming skills and a deeper knowledge of how\n",
"Python works.\n",
"We include it in this tutorial to get the message across that Text-Fabric is not\n",
"a black box that shields you from your data. Everything you handle in Text-Fabric is\n",
"open to further programming and processing of your own design and choosing."
]
},
{
"cell_type": "markdown",
"metadata": {
"tags": []
},
"source": [
"## Data collection"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"ExecuteTime": {
"end_time": "2018-05-24T10:19:42.344356Z",
"start_time": "2018-05-24T10:19:42.097434Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 0.08s 1018 results\n"
]
}
],
"source": [
"query = f\"\"\"\n",
"tablet\n",
" face\n",
" sign type=numeral grapheme={shinPPPat}\n",
"\"\"\"\n",
"results = A.search(query)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We are going to put all these numerals in buckets: for each face on each tablet a separate bucket."
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"ExecuteTime": {
"end_time": "2018-05-24T10:19:44.413172Z",
"start_time": "2018-05-24T10:19:44.404041Z"
},
"lines_to_next_cell": 2
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"235 tablets\n",
"P448701\n",
"P006005\n",
"P002329\n",
"P002342\n",
"P002344\n",
"P002398\n",
"P002622\n",
"P002626\n",
"P003330\n",
"P003357\n",
"...\n"
]
}
],
"source": [
"numerals = {}\n",
"pNums = {}\n",
"for (tablet, face, sign) in results:\n",
" pNums[F.catalogId.v(tablet)] = tablet\n",
" numerals.setdefault(tablet, {}).setdefault(face, []).append(sign)\n",
"print(f\"{len(pNums)} tablets\")\n",
"print(\"\\n\".join(list(pNums)[0:10]))\n",
"print(\"...\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## The calculator\n",
"We define a function that given a tablet, adds the shinPP numerals by its faces.\n",
"We also show the line art and a pretty transcription.\n",
"\n",
"The function is a bit involved."
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"ExecuteTime": {
"end_time": "2018-05-24T10:19:46.415859Z",
"start_time": "2018-05-24T10:19:46.406051Z"
}
},
"outputs": [],
"source": [
"# we generate Markdown strings and send them to the notebook formatter\n",
"\n",
"\n",
"def dm(x):\n",
" display(Markdown(x))\n",
"\n",
"\n",
"def calcTablet(pNum): # pNum identifies the tablet in question\n",
" # show a horizontal line in Markdown\n",
" dm(\"---\\n\")\n",
" tablet = pNums.get(pNum, None) # look up the node for this p-number\n",
" if tablet is None:\n",
" dm(f\"**no results for {pNum}**\")\n",
" return # if not found the tablet has no ShinPP numerals: quit\n",
"\n",
" A.lineart(tablet, withCaption=\"top\", width=\"200\") # show lineart\n",
" faces = numerals[tablet] # get the buckets for the faces\n",
" mySigns = []\n",
" for (face, signs) in faces.items(): # work per face\n",
" mySigns.extend(signs)\n",
" dm(f\"### {F.type.v(face)}\") # show the name of the face\n",
" distinctSigns = {} # collect the distinct numerals\n",
" for s in signs:\n",
" distinctSigns.setdefault(A.atfFromSign(s), []).append(s)\n",
" A.lineart(distinctSigns) # display the list of signs\n",
" total = 0 # start adding up\n",
" for (signAtf, signs) in distinctSigns.items():\n",
" value = 0\n",
" for s in signs:\n",
" value += F.repeat.v(s) * shinPP[F.grapheme.v(s)]\n",
" total += value\n",
" amount = len(signs) # we report our calculation\n",
" shinPPval = shinPP[F.grapheme.v(signs[0])]\n",
" repeat = F.repeat.v(signs[0])\n",
" print(f\"{amount} x {signAtf} = {amount} x {repeat} x {shinPPval} = {value}\")\n",
" dm(f\"**total** = **{total}**\")\n",
" A.prettyTuple(\n",
" [tablet] + mySigns, 1, queryFeatures=False\n",
" ) # show pretty transcription"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Calculate once"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"ExecuteTime": {
"end_time": "2018-05-24T10:19:48.478383Z",
"start_time": "2018-05-24T10:19:48.377669Z"
}
},
"outputs": [
{
"data": {
"text/markdown": [
"---\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/markdown": [
"### obverse"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"1 x 1(N46) = 1 x 1 x 60 = 60\n",
"1 x 5(N19) = 1 x 5 x 6 = 30\n",
"4 x 3(N04) = 4 x 3 x 1 = 12\n",
"2 x 1(N41) = 2 x 1 x 0.2 = 0.4\n",
"8 x 1(N19) = 8 x 1 x 6 = 48\n",
"2 x 3(N19) = 2 x 3 x 6 = 36\n",
"5 x 1(N04) = 5 x 1 x 1 = 5\n",
"3 x 2(N04) = 3 x 2 x 1 = 6\n",
"3 x 2(N19) = 3 x 2 x 6 = 36\n",
"1 x 2(N41) = 1 x 2 x 0.2 = 0.4\n",
"2 x 4(N04) = 2 x 4 x 1 = 8\n",
"1 x 3(N41) = 1 x 3 x 0.2 = 0.6000000000000001\n",
"1 x 4(N19) = 1 x 4 x 6 = 24\n"
]
},
{
"data": {
"text/markdown": [
"**total** = **266.4**"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/markdown": [
"### reverse"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"1 x 1(N36) = 1 x 1 x 180 = 180\n",
"1 x 1(N46) = 1 x 1 x 60 = 60\n",
"1 x 8(N19) = 1 x 8 x 6 = 48\n",
"1 x 5(N04) = 1 x 5 x 1 = 5\n",
"1 x 3(N41) = 1 x 3 x 0.2 = 0.6000000000000001\n"
]
},
{
"data": {
"text/markdown": [
"**total** = **293.6**"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"result 1"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"tablet P006377
CUSAS 01, 105uruk-iii
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"calcTablet(\"P006377\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Calculate ad lib\n",
"Now the first 5 tablets."
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"ExecuteTime": {
"end_time": "2018-05-24T10:19:52.590763Z",
"start_time": "2018-05-24T10:19:52.327850Z"
}
},
"outputs": [
{
"data": {
"text/markdown": [
"---\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/markdown": [
"### obverse"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"1 x 1(N04) = 1 x 1 x 1 = 1\n"
]
},
{
"data": {
"text/markdown": [
"**total** = **1**"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"result 1"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"tablet P000266
CDLI Lexical 000019, ex. 003uruk-iiiW 20266,020
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/markdown": [
"---\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/markdown": [
"### obverse"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"2 x 1(N36) = 2 x 1 x 180 = 360\n"
]
},
{
"data": {
"text/markdown": [
"**total** = **360**"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/markdown": [
"### reverse"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"1 x 3(N36) = 1 x 3 x 180 = 540\n"
]
},
{
"data": {
"text/markdown": [
"**total** = **540**"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"result 1"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"tablet P001043
ATU 5, pl. 037, W 9123,vuruk-ivW 09123,v
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/markdown": [
"---\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/markdown": [
"### obverse"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"1 x 5(N36) = 1 x 5 x 180 = 900\n",
"4 x 1(N46) = 4 x 1 x 60 = 240\n",
"2 x 1(N36) = 2 x 1 x 180 = 360\n",
"1 x 2(N46) = 1 x 2 x 60 = 120\n",
"1 x 1(N04) = 1 x 1 x 1 = 1\n",
"1 x 1(N19) = 1 x 1 x 6 = 6\n",
"2 x 2(N36) = 2 x 2 x 180 = 720\n",
"1 x 2(N19) = 1 x 2 x 6 = 12\n"
]
},
{
"data": {
"text/markdown": [
"**total** = **2359**"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"result 1"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"tablet P001270
ATU 5, pl. 065, W 9579,wuruk-ivW 09579,w
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/markdown": [
"---\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/markdown": [
"### obverse"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"1 x 1(N04) = 1 x 1 x 1 = 1\n"
]
},
{
"data": {
"text/markdown": [
"**total** = **1**"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"result 1"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"tablet P002260
IM 023435,14uruk-iiiW 15771,d
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/markdown": [
"---\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/markdown": [
"### obverse"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"1 x 1(N36) = 1 x 1 x 180 = 180\n"
]
},
{
"data": {
"text/markdown": [
"**total** = **180**"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"result 1"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"tablet P002275
IM 023435,06uruk-iiiW 15771,t
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"for tablet in sorted(pNums)[0:5]:\n",
" calcTablet(tablet)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## More ...\n",
"\n",
"The capabilities of search are endless.\n",
"Often it is the quickest way to focus on a phenomenon, quicker than hand coding all the logic\n",
"to retrieve your patterns.\n",
"\n",
"That said, it is not a matter of either-or. You can use coding to craft your templates,\n",
"and you can use coding to process your results.\n",
"\n",
"It's an explosive mix. A later chapter in this tutorial shows\n",
"even more [cases](cases.ipynb).\n",
"\n",
"Have another look at\n",
"[the manual](https://annotation.github.io/text-fabric/tf/about/searchusage.html)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Next\n",
"\n",
"[signs](signs.ipynb)\n",
"\n",
"*Back to the basics ...*\n",
"\n",
"All chapters:\n",
"[start](start.ipynb)\n",
"[imagery](imagery.ipynb)\n",
"[steps](steps.ipynb)\n",
"[search](search.ipynb)\n",
"**calc**\n",
"[signs](signs.ipynb)\n",
"[quads](quads.ipynb)\n",
"[jumps](jumps.ipynb)\n",
"[cases](cases.ipynb)\n",
"\n",
"---\n",
"\n",
"CC-BY Dirk Roorda"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.12.0"
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": true,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": true,
"toc_position": {
"height": "607px",
"left": "0px",
"right": "983px",
"top": "110px",
"width": "297px"
},
"toc_section_display": "block",
"toc_window_display": false
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"state": {},
"version_major": 2,
"version_minor": 0
}
}
},
"nbformat": 4,
"nbformat_minor": 4
}