{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "4e901d96-860c-41a4-93fa-1b312200126e", "metadata": {}, "outputs": [], "source": [ "!pip install pengines prologterms\n", "from pengines.Builder import PengineBuilder\n", "from pengines.Pengine import Pengine\n", "\n", "q = '((member(X,[1,2,3])))'\n", "factory = PengineBuilder(urlserver=\"http://logicmoo.org:3020\", destroy=False, ask=q)\n", "pengine = Pengine(builder=factory)\n", "# Start query.\n", "print()\n", "print(pengine.currentQuery.availProofs, \"Has More? \", pengine.currentQuery.hasMore)\n", "print()\n", "# Get next query.\n", "print(pengine.state.current_state)\n", "while pengine.currentQuery.hasMore:\n", " pengine.doNext(pengine.currentQuery)\n", "print(pengine.currentQuery.availProofs)\n", "\n" ] }, { "cell_type": "code", "execution_count": 13, "id": "3cab67b7-cd1d-4614-8488-32ab378344a6", "metadata": {}, "outputs": [ { "ename": "SyntaxError", "evalue": "Bad event in answer ()", "output_type": "error", "traceback": [ "Traceback \u001b[0;36m(most recent call last)\u001b[0m:\n", " File \u001b[1;32m/usr/local/lib/python3.10/dist-packages/IPython/core/interactiveshell.py:3251\u001b[0m in \u001b[1;35mrun_code\u001b[0m\n exec(code_obj, self.user_global_ns, self.user_ns)\n", " Input \u001b[1;32mIn [13]\u001b[0m in \u001b[1;35m\u001b[0m\n pengine = Pengine(builder=factory)\n", " File \u001b[1;32m/usr/local/lib/python3.10/dist-packages/pengines/Pengine.py:40\u001b[0m in \u001b[1;35m__init__\u001b[0m\n self.pengineID = self.create()\n", " File \u001b[1;32m/usr/local/lib/python3.10/dist-packages/pengines/Pengine.py:126\u001b[0m in \u001b[1;35mcreate\u001b[0m\n self.handleAnswer(response[\"answer\"])\n", "\u001b[0;36m File \u001b[0;32m/usr/local/lib/python3.10/dist-packages/pengines/Pengine.py:309\u001b[0;36m in \u001b[0;35mhandleAnswer\u001b[0;36m\u001b[0m\n\u001b[0;31m raise SyntaxError(\"Bad event in answer\")\u001b[0m\n", "\u001b[0;36m File \u001b[0;32m\u001b[0;36m\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m Bad event in answer\n" ] } ], "source": [ "#!pip install pengines\n", "from pengines.Builder import PengineBuilder\n", "from pengines.Pengine import Pengine\n", "\n", "#q = 'X=((wots(S,((current_output(CO),set_stream(CO,alias(user_error)),set_stream(CO,alias(current_output)),ls))),fail))'\n", "q = '((e2ec(\"A man waits\")))'\n", "\n", "factory = PengineBuilder(urlserver=\"http://logicmoo.org:3020\", destroy=False, ask=q)\n", "pengine = Pengine(builder=factory)\n", "# Start query.\n", "print()\n", "print(pengine.currentQuery.availProofs, \"Has More? \", pengine.currentQuery.hasMore)\n", "print()\n", "# Get next query.\n", "print(pengine.state.current_state)\n", "while pengine.currentQuery.hasMore:\n", " pengine.doNext(pengine.currentQuery)\n", "print(pengine.currentQuery.availProofs)\n", "\n", "q = 'e2eco(X)'\n", "\n", "factory2 = PengineBuilder(urlserver=\"http://logicmoo.org:3020\", destroy=False, ask=q)\n", "pengine = Pengine(builder=factory2)\n", "# Start query.\n", "print()\n", "print(pengine.currentQuery.availProofs, \"Has More? \", pengine.currentQuery.hasMore)\n", "print()\n", "# Get next query.\n", "print(pengine.state.current_state)\n", "while pengine.currentQuery.hasMore:\n", " pengine.doNext(pengine.currentQuery)\n", "print(pengine.currentQuery.availProofs)\n" ] }, { "cell_type": "code", "execution_count": null, "id": "9488e5ca-983a-497f-9545-b593095ee119", "metadata": {}, "outputs": [], "source": [ "from pengines.Builder import PengineBuilder\n", "from pengines.Pengine import Pengine\n", "from prologterms import TermGenerator, PrologRenderer, Program, Var\n", "\n", "P = TermGenerator()\n", "X = Var('X')\n", "Y = Var('Y')\n", "Z = Var('Z')\n", "R = PrologRenderer()\n", "\n", "p = Program(\n", " P.ancestor(X,Y) <= (P.parent(X,Z), P.ancestor(Z,Y)),\n", " P.ancestor(X,Y) <= P.parent(X,Y),\n", " P.parent('a','b'),\n", " P.parent('b','c'),\n", " P.parent('c','d')\n", ")\n", "\n", "q = P.ancestor(X,Y)\n", "\n", "factory = PengineBuilder(urlserver=\"http://logicmoo.org:3020\",\n", " srctext=R.render(p),\n", " ask=R.render(q))\n", "pengine = Pengine(builder=factory)\n", "while pengine.currentQuery.hasMore:\n", " pengine.doNext(pengine.currentQuery)\n", "for p in pengine.currentQuery.availProofs:\n", " print('{} <- {}'.format(p[X.name], p[Y.name]))" ] }, { "cell_type": "code", "execution_count": null, "id": "0828c87c-532c-4895-852d-53d56a07a510", "metadata": {}, "outputs": [], "source": [ "from IPython.display import display, HTML\n", "display(HTML('

Hello, world!

'))" ] }, { "cell_type": "code", "execution_count": null, "id": "ae1e2a3f-04b2-4061-ae9c-611d6801418f", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "6412931c-e124-47c0-a4cc-1751f10145d3", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "1e86afcb-8812-454d-b740-ea20a5cbf086", "metadata": {}, "outputs": [], "source": [] } ], "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.10.1" } }, "nbformat": 4, "nbformat_minor": 5 }