From 19b08a103305a22ac95b579f7d1c879c5745fe95 Mon Sep 17 00:00:00 2001 From: "Carlos A. Iglesias" Date: Wed, 13 Feb 2019 18:52:29 +0100 Subject: [PATCH] Updated IRIs descriptions and other minor details --- rdf/RDF.ipynb | 210 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 193 insertions(+), 17 deletions(-) diff --git a/rdf/RDF.ipynb b/rdf/RDF.ipynb index df1f03b..c16e57f 100644 --- a/rdf/RDF.ipynb +++ b/rdf/RDF.ipynb @@ -67,7 +67,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": { "deletable": false, "editable": false, @@ -80,7 +80,23 @@ "solution": false } }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Requirement already satisfied: future in /home/cif/anaconda3/lib/python3.5/site-packages (from -r requirements.txt (line 1)) (0.16.0)\n", + "Requirement already satisfied: rdflib in /home/cif/anaconda3/lib/python3.5/site-packages (from -r requirements.txt (line 2)) (4.0.1)\n", + "Requirement already satisfied: rdflib-jsonld in /home/cif/.local/lib/python3.5/site-packages (from -r requirements.txt (line 3)) (0.4.0)\n", + "Requirement already satisfied: lxml in /home/cif/anaconda3/lib/python3.5/site-packages (from -r requirements.txt (line 4)) (4.2.4)\n", + "Requirement already satisfied: html5lib in /home/cif/anaconda3/lib/python3.5/site-packages (from -r requirements.txt (line 5)) (1.0.1)\n", + "Requirement already satisfied: isodate in /home/cif/anaconda3/lib/python3.5/site-packages (from rdflib->-r requirements.txt (line 2)) (0.5.4)\n", + "Requirement already satisfied: pyparsing in /home/cif/anaconda3/lib/python3.5/site-packages (from rdflib->-r requirements.txt (line 2)) (2.2.0)\n", + "Requirement already satisfied: webencodings in /home/cif/anaconda3/lib/python3.5/site-packages (from html5lib->-r requirements.txt (line 5)) (0.5.1)\n", + "Requirement already satisfied: six>=1.9 in /home/cif/anaconda3/lib/python3.5/site-packages (from html5lib->-r requirements.txt (line 5)) (1.11.0)\n" + ] + } + ], "source": [ "!pip install --user -r requirements.txt" ] @@ -155,7 +171,12 @@ "```\n", "\n", "\n", - "The second exercise will show you how to extract this information from any website." + "The second exercise will show you how to extract this information from any website.\n", + "\n", + "As you can observe in these examples, Turtle defines several ways to specify IRIs in a result. Please, consult the specification for further details. As an overview, IRIs can be:\n", + " * *relative IRIs*: IRIs resolved relative to the current base IRI. Thus, you should define a base IRI (@base ) and then relative IRIs (i.e. <#spiderman>). The resulting IRI is .\n", + " * *prefixed names*: a prefixed name (i.e. foaf:Person) is transformed into an IRI by concatenating the IRI of the prefix (@prefix foaf: ." ] }, { @@ -251,7 +272,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": { "deletable": false, "editable": false, @@ -264,7 +285,17 @@ "solution": false } }, - "outputs": [], + "outputs": [ + { + "data": { + "application/javascript": [ + "IPython.CodeCell.options_default.highlight_modes['magic_turtle'] = {'reg':[/^%%ttl/]};" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "from helpers import *\n", "from rdflib import term, RDF, Namespace" @@ -308,12 +339,14 @@ " ] .\n", "```\n", "\n", - "Fill in the answer and run the test code." + "Fill in the answer and run the test code.\n", + "\n", + "This order (%%ttl) is a so-called magic cell command to execute a function. You can read more here https://ipython.readthedocs.io/en/stable/interactive/magics.html#cell-magics" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": { "deletable": false, "nbgrader": { @@ -325,7 +358,25 @@ "solution": true } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/markdown": [ + "Error on line ?\n", + "\n", + "Reason: No plugin registered for (ttl, )\n", + "\n", + "If you don't know what this error means, try an online validator: http://ttl.summerofcode.be/\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "%%ttl example\n", "\n", @@ -413,12 +464,9 @@ "metadata": {}, "source": [ "To make sure we are following Principles 1 and 2, we should use URIs that can be queried.\n", - "For the sake of this exercise, you have two options:\n", - " \n", - "* Use the made-up `http://example/sitc/` as base for our URIs.\n", + "For the sake of this exercise, you can use the made-up `http://example/sitc/` as base for our URIs.\n", "Hence, the URIs of our hotels will look like this: `http://example/sitc/my-fancy-hotel`.\n", "These URIs can not be queried, **and should not be used in real annotations**, but we will see how to fix that in a future exercise.\n", - "* Use (blank nodes)[https://en.wikipedia.org/wiki/Blank_node] (e.g. `_:my-fancy-hotel`), which cannot be used by other people, but can be re-used in your annotations.\n", "\n", "\n", "We will use the vocabularies defined in https://schema.org e.g.:\n", @@ -428,6 +476,11 @@ "\n", "Your definition has to be included in the following cell.\n", "\n", + "So, your task is:\n", + "* Search the relevant properties of the vocabulary schema.org to represent the attributes of both reviews and hotels.\n", + "* Write two resources of type Hotel and three resources of type Review.\n", + "* Check that your syntax is correct, by executing your code in the cell below.\n", + "\n", "**Tip**: Define the schema prefix first, to avoid repeating ``." ] }, @@ -570,18 +623,124 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "Could not get rdfa data\n" + ] + }, + { + "data": { + "text/markdown": [ + "\n", + "Results:\n", + "\n", + "```turtle\n", + "@prefix ns1: .\n", + "@prefix ns2: .\n", + "@prefix ns3: .\n", + "@prefix ns4: .\n", + "@prefix rdf: .\n", + "@prefix rdfs: .\n", + "@prefix xml: .\n", + "@prefix xsd: .\n", + "\n", + " ns4:item () .\n", + "\n", + "[] a ns2:Error ;\n", + " ns1:date \"2019-02-13T17:42:13.310135\"^^xsd:dateTime ;\n", + " ns1:description \"__init__() got an unexpected keyword argument 'encoding'\" ;\n", + " ns2:context [ a ns3:Request ;\n", + " ns3:requestURI \"http://www.hotellasalve.com/\" ],\n", + " [ a ns3:Response ;\n", + " ns3:responseCode ] .\n", + "\n", + "\n", + "```\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "print_data('http://www.hotellasalve.com/')" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "Could not get rdfa data\n", + "https://photos.mandarinoriental.com/is/content/MandarinOriental/RZMAD - Madrid/Logos/hotel-ritz-hotel-logo-SVG.svg does not look like a valid URI, trying to serialize this will break.\n", + "tel:+34 91 701 67 67 does not look like a valid URI, trying to serialize this will break.\n" + ] + }, + { + "data": { + "text/markdown": [ + "\n", + "Results:\n", + "\n", + "```turtle\n", + "@prefix ns1: .\n", + "@prefix ns2: .\n", + "@prefix ns3: .\n", + "@prefix ns4: .\n", + "@prefix ns5: .\n", + "@prefix rdf: .\n", + "@prefix rdfs: .\n", + "@prefix xml: .\n", + "@prefix xsd: .\n", + "\n", + " ns5:item ( [ a ns1:Hotel ;\n", + " ns1:address [ a ns1:PostalAddress ;\n", + " ns1:addressCountry \"Spain\"@en ;\n", + " ns1:addressLocality \"Madrid\"@en ;\n", + " ns1:postalCode \"28014\"@en ;\n", + " ns1:streetAddress \"Plaza de la Lealtad 5\"@en ] ;\n", + " ns1:description \"Experience our 5 Star hotel in central Madrid, Retiro Park offering luxurious rooms and suites, fine dining, private spa, meeting and wedding facilities.\"@en ;\n", + " ns1:email ;\n", + " ns1:image ;\n", + " ns1:name \"Hotel Ritz, Madrid\"@en ;\n", + " ns1:tel ;\n", + " ns1:url ,\n", + " ] ) ;\n", + " ns4:usesVocabulary ns1: .\n", + "\n", + "[] a ns4:Error ;\n", + " ns3:date \"2019-02-13T17:43:52.577508\"^^xsd:dateTime ;\n", + " ns3:description \"__init__() got an unexpected keyword argument 'encoding'\" ;\n", + " ns4:context [ a ns2:Request ;\n", + " ns2:requestURI \"https://www.mandarinoriental.com/madrid/hotel-ritz/luxury-hotel\" ],\n", + " [ a ns2:Response ;\n", + " ns2:responseCode ] .\n", + "\n", + "\n", + "```\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "print_data('https://www.mandarinoriental.com/madrid/hotel-ritz/luxury-hotel')" ] @@ -867,7 +1026,24 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.5.5" + }, + "latex_envs": { + "LaTeX_envs_menu_present": true, + "autocomplete": true, + "bibliofile": "biblio.bib", + "cite_by": "apalike", + "current_citInitial": 1, + "eqLabelWithNumbers": true, + "eqNumInitial": 1, + "hotkeys": { + "equation": "Ctrl-E", + "itemize": "Ctrl-I" + }, + "labels_anchors": false, + "latex_user_defs": false, + "report_style_numbering": false, + "user_envs_cfg": false } }, "nbformat": 4,