{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%load_ext autoreload\n", "%autoreload 2" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import os\n", "from array import array\n", "from tf.app import use\n", "from tf.fabric import Fabric" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "This is Text-Fabric 7.8.2\n", "Api reference : https://annotation.github.io/text-fabric/Api/Fabric/\n", "\n", "114 features found and 0 ignored\n" ] } ], "source": [ "TF = Fabric(locations='/Users/dirk/text-fabric-data/etcbc/bhsa/tf/c')" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " 0.00s loading features ...\n", " | 0.00s No structure info in otext, the structure part of the T-API cannot be used\n", " 3.62s All features loaded/computed - for details use loadLog()\n", " 0.00s loading features ...\n", " 7.30s All additional features loaded - for details use loadLog()\n" ] } ], "source": [ "api = TF.loadAll()" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "This is Text-Fabric 7.8.1\n", "Api reference : https://annotation.github.io/text-fabric/Api/Fabric/\n", "\n", "7 features found and 0 ignored\n", " 0.00s Warp feature \"otext\" not found. Working without Text-API\n", "\n" ] } ], "source": [ "TF = Fabric(locations='tf') \n", "TF.clearCache()" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " 0.00s loading features ...\n", " | 0.00s No section config in otext, the section part of the T-API cannot be used\n", " | 0.00s No structure info in otext, the structure part of the T-API cannot be used\n", " 0.00s All features loaded/computed - for details use loadLog()\n" ] } ], "source": [ "api = TF.load('name sign')\n", "docs = api.makeAvailableIn(globals())" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "query = '''\n", "sign name=a\n", "== part name=s1\n", "'''" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " 0.00s Checking search template ...\n", " 0.00s Setting up search space for 2 objects ...\n", " 0.00s Constraining search space with 1 relations ...\n", " 0.00s \t0 edges thinned\n", " 0.00s Setting up retrieval plan ...\n", " 0.00s Ready to deliver results from 2 nodes\n", "Iterate over S.fetch() to get the results\n", "See S.showPlan() to interpret the results\n" ] } ], "source": [ "S.study(query)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Search with 2 objects and 1 relations\n", "Results are instantiations of the following objects:\n", "node 0-sign ( 1 choices)\n", "node 1-part ( 1 choices)\n", "Performance parameters:\n", "\tyarnRatio = 1.25\n", "\ttryLimitFrom = 40\n", "\ttryLimitTo = 40\n", "Instantiations are computed along the following relations:\n", "node 0-sign ( 1 choices)\n", "edge 0-sign == 1-part ( 1.0 choices)\n", " 1.20s The results are connected to the original search template as follows:\n", " 0 \n", " 1 R0 sign name=a\n", " 2 R1 == part name=s1\n", " 3 \n" ] } ], "source": [ "S.showPlan(details=True)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[(1, 11)]" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "results = list(S.search(query))\n", "results" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "ClevUp = C.levUp.data\n", "Eoslots = E.oslots.data\n", "maxSlot = F.otype.maxSlot\n", "\n", "def xx(n):\n", " if n <= maxSlot:\n", " slotN = n\n", " else:\n", " slots = Eoslots[n - maxSlot - 1]\n", " slotN = slots[0] if len(slots) == 1 else None\n", " return (\n", " tuple(m for m in ClevUp[n - 1] if n in ClevUp[m - 1])\n", " +\n", " ((slotN, ) if slotN else ())\n", " )\n", "\n", "def xx(n):\n", " if n <= maxSlot:\n", " nA = array('I', (n,))\n", " return tuple(m for m in ClevUp[n - 1] if Eoslots[m - maxSlot - 1] == nA) + (n,)\n", " nSlots = Eoslots[n - maxSlot - 1]\n", " if len(nSlots) == 1:\n", " slot1 = nSlots[0]\n", " nA = array('I', (slot1,))\n", " nT = (slot1,)\n", " return tuple(m for m in ClevUp[n - 1] if Eoslots[m - maxSlot - 1] == nA) + (n,) + nT\n", " return tuple(m for m in ClevUp[n - 1] if n in ClevUp[m - 1]) + (n,)" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(1,)" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "F.name.s('a')" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(11,)" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "F.name.s('s1')" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(21, 11, 1)" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "xx(1)" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(21, 11, 1)" ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "xx(11)" ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(11, 21, 1)" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "xx(21)" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[11, 1]" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "L.d(21)" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array('I', [11, 67, 49, 53, 82, 77, 31, 36, 40, 51, 43, 47, 46, 45, 89])" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "L.u(21)" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[21, 1]" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "L.d(11)" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[11, 1]" ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "L.d(21)" ] }, { "cell_type": "code", "execution_count": 34, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "sign 1 has name a and slots (1,)\n", "part 11 has name s1 and slots (1,)\n", "part 21 has name ss1 and slots (1,)\n" ] } ], "source": [ "for i in (1, 11, 21):\n", " iType = F.otype.v(i)\n", " slots = ((i,) if iType == 'sign' else ()) + L.d(i, otype='sign')\n", " print(f'{iType} {i} has name {F.name.v(i)} and slots {slots}')" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [], "source": [ "query = '''\n", "part name=s1\n", ".namepart~(^[sp]{2}-)|(-[sp]{2}$)~namepart. part name=s3\n", "'''" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "11: nVal=special\n", "11: nValR=special\n", "13: mVal=pp-peculiar-pp\n", "13: mValR=peculiar\n", "result 11 == 13: False\n", "11: nVal=special\n", "11: nValR=special\n", "13: mVal=pp-peculiar-pp\n", "13: mValR=peculiar\n", "result 11 == 13: False\n", "13: nVal=pp-peculiar-pp\n", "13: nValR=peculiar\n", "11: mVal=special\n", "11: mValR=special\n", "result 13 == 11: False\n", "11: nVal=special\n", "11: nValR=special\n", "13: mVal=pp-peculiar-pp\n", "13: mValR=peculiar\n", "result 11 == 13: False\n" ] }, { "data": { "text/plain": [ "[]" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "results = list(S.search(query))\n", "results" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "special\n", "pp-peculiar-pp\n" ] } ], "source": [ "print(F.namepart.v(11))\n", "print(F.namepart.v(13))" ] }, { "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 }