{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Basic SPARQLProg example\n", "\n", "Walkthrough of basic commands" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from prologterms import TermGenerator, PrologRenderer, Program, Var\n", "from sparqlprog import SPARQLProg\n", "P = TermGenerator()" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "server = 'http://localhost:9083'\n", "# server = 'https://evening-falls-87315.herokuapp.com'\n" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "S = SPARQLProg(server=server,\n", " endpoint='wd')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### setting up a query" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "C = Var('C')\n", "N = Var('N')\n", "query = (P.continent(C), P.enlabel(C, N))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### running the querry\n" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "res = S.query(query)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "http://www.wikidata.org/entity/Q15 Africa\n", "http://www.wikidata.org/entity/Q18 South America\n", "http://www.wikidata.org/entity/Q46 Europe\n", "http://www.wikidata.org/entity/Q48 Asia\n", "http://www.wikidata.org/entity/Q49 North America\n", "http://www.wikidata.org/entity/Q51 Antarctica\n", "http://www.wikidata.org/entity/Q538 Oceania\n", "http://www.wikidata.org/entity/Q3960 Australia\n" ] } ], "source": [ "for r in res:\n", " print(f\"{r['C']} {r['N']}\")" ] } ], "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 }