{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "774b70a7", "metadata": {}, "outputs": [], "source": [ "from pyswip import Prolog\n", "prolog = Prolog()\n", "prolog.assertz(\"father(michael,john)\")\n", "\n", "\n", "\n" ] }, { "cell_type": "code", "execution_count": 2, "id": "a266c106", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "michael is the father of john\n", "michael is the father of john\n", "michael is the father of gina\n" ] } ], "source": [ "from pyswip import Prolog\n", "prolog = Prolog()\n", "prolog.assertz(\"father(michael,john)\")\n", "prolog.assertz(\"father(michael,gina)\")\n", "list(prolog.query(\"father(michael,X)\")) == [{'X': 'john'}, {'X': 'gina'}]\n", "for soln in prolog.query(\"father(X,Y)\"):\n", " print(soln[\"X\"], \"is the father of\", soln[\"Y\"])\n", " " ] }, { "cell_type": "code", "execution_count": null, "id": "74bfe496", "metadata": {}, "outputs": [], "source": [ "for soln in prolog.query(\"ls,Y)\"):" ] } ], "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.5" } }, "nbformat": 4, "nbformat_minor": 5 }