{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from tf.server.kernel import makeTfConnection\n", "from tf.applib.appmake import findAppConfig\n", "from tf.core.helpers import console" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "config = findAppConfig('bhsa')" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [], "source": [ "TIMEOUT = 5" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [], "source": [ "TF = makeTfConnection(config.host, config.port, TIMEOUT)\n", "kernelApi = TF.connect()" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [], "source": [ "querySlow = '''\n", "p:phrase\n", " =: wFirst:word\n", " wLast:word\n", " :=\n", "\n", "wGap:word\n", "wFirst < wGap\n", "wLast > wGap\n", "\n", "p || wGap\n", "\n", "v:verse\n", "\n", "v [[ wFirst\n", "v [[ wGap\n", "'''\n", "\n", "queryFast = '''\n", "verse\n", " p:phrase\n", " wPreGap:word lex=L\n", " wLast:word\n", " :=\n", "\n", "wGap:word\n", "wPreGap <: wGap\n", "wGap < wLast\n", "p || wGap\n", "'''" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [], "source": [ "def search(query):\n", " try:\n", " (results, messages) = kernelApi.rawSearch(query)\n", " except TimeoutError:\n", " messages = f'Aborted query because it takes longer than {TIMEOUT} seconds.'\n", " results = ()\n", " if messages:\n", " console(messages, error=True)\n", " else:\n", " console(f'{len(results)} results')\n", " return results" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "def search(query):\n", " results = kernelApi.rawSearch(query)\n", " console(f'{len(results)} results')\n", " return results" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "13 results\n" ] }, { "data": { "text/plain": [ "((1414758, 655681, 7431, 7437, 7432),\n", " (1415131, 660328, 14553, 14561, 14554),\n", " (1415243, 661769, 16661, 16665, 16662),\n", " (1416757, 679503, 45899, 45905, 45900),\n", " (1417829, 690836, 67252, 67267, 67253),\n", " (1418680, 698941, 82851, 82855, 82852),\n", " (1419106, 702933, 90507, 90522, 90508),\n", " (1419283, 704590, 93542, 93552, 93543),\n", " (1419932, 712577, 107397, 107402, 107398),\n", " (1422163, 741726, 157214, 157222, 157215),\n", " (1424518, 774011, 211895, 211899, 211896),\n", " (1426819, 802329, 257062, 257070, 257063),\n", " (1435018, 879921, 375932, 375942, 375933))" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "search(queryFast)" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Aborted query because it takes longer than 5 seconds.\n" ] }, { "data": { "text/plain": [ "()" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "search(querySlow)" ] }, { "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.1" } }, "nbformat": 4, "nbformat_minor": 2 }