{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from SPARQLWrapper import SPARQLWrapper, JSON, DIGEST, BASIC, CSV" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "sparql = SPARQLWrapper(\n", " \"https://lov.linkeddata.es/dataset/lov/sparql\"\n", ")\n", "#sparql.setReturnFormat(JSON)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "# sparql.setHTTPAuth(DIGEST)\n", "# sparql.setCredentials(\"dba\", \"mysecret\")\n", "sparql.setReturnFormat(JSON)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "sparql.setQuery(\"\"\"\n", "PREFIX rdf: \n", "PREFIX rdfs: \n", "PREFIX td: \n", "PREFIX facility: \n", "PREFIX process: \n", "PREFIX props: \n", "SELECT ?project ?elem ?elemId ?td ?type WHERE {\n", " SERVICE {\n", " ?project rdf:type facility:Project .\n", " \t?project facility:projectID ?id .\n", " \t?project facility:isRelatedToProcess ?process .\n", " ?process process:hasTask ?task .\n", " ?task facility:isRelatedTo ?elem .\n", " \t?elem props:hasCompressedGuid ?elemId .\n", " }\n", " SERVICE {\n", " \tBIND(URI(concat('https://data.cogito.iot.linkeddata.es/tdd/api/things/',?elemId)) AS ?td) .\n", " ?td a td:Thing .\n", " ?td td:type 'facility:Element' .\n", " ?td td:hasPropertyAffordance ?fileProperty .\n", " ?fileProperty td:name 'platform:hasFile' .\n", " ?fileProperty td:hasForm ?formFile .\n", " ?formFile td:type ?type .\n", " } \n", "} LIMIT 10\n", "\n", " \"\"\"\n", ")" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "HTTP Error 406: \n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "/Users/salva/.pyenv/versions/3.11.1/lib/python3.11/site-packages/SPARQLWrapper/Wrapper.py:794: RuntimeWarning: Sending Accept header '*/*' because unexpected returned format 'json' in a 'CONSTRUCT' SPARQL query form\n", " warnings.warn(\n" ] } ], "source": [ "try:\n", " ret = sparql.queryAndConvert()\n", "\n", " for r in ret[\"results\"][\"bindings\"]:\n", " print(r)\n", "except Exception as e:\n", " print(e)" ] }, { "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.11.1 (main, Dec 22 2022, 22:10:00) [Clang 14.0.0 (clang-1400.0.29.202)]" }, "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "4e68eea911fef027cedb18eacef846ed575567368a2e04b5661fa2b5d0e49da1" } } }, "nbformat": 4, "nbformat_minor": 2 }