{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
},
"source": [
"# SPARQL about van Gogh -- on CoCalc!\n",
"\n",
"We are going to use some the [DBPedia SPARQL endpoint](http://wiki.dbpedia.org/OnlineAccess#1.1%20Public%20SPARQL%20Endpoint) to do some queries related to _Vincent van Gogh_.\n",
"\n",
"First we define the endpoint and the preferred language for labels"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"
Endpoint set to: http://dbpedia.org/sparql
Label preferred languages: ['en']
Logging set to DEBUG
"
]
},
"execution_count": 1,
"metadata": {
},
"output_type": "execute_result"
}
],
"source": [
"%endpoint http://dbpedia.org/sparql\n",
"%lang en\n",
"\n",
"# This is optional, it would increase the log level.\n",
"# The default logfile (unless changed upon kernel installation) is [TMPDIR]/sparqlkernel.log, \n",
"# where [TMPDIR] is the platform default temporal directory\n",
"%log debug"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
},
"source": [
"Now let's find out the entity URI for _van Gogh_ in DBPedia. We search entities that are persons and whose label contains `van Gogh` (case insensitive).\n",
"\n",
"Note that the DBPedia endpoint has a set of [predefined namespace prefixes](http://dbpedia.org/sparql?nsdecl) that we can use without the need to define them in the query, such as `rdfs:` or `foaf:` so we could remove them from the query without problem."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"Return format: JSON
Display: table
"
]
},
"execution_count": 2,
"metadata": {
},
"output_type": "execute_result"
},
{
"data": {
"text/html": [
""
]
},
"execution_count": 2,
"metadata": {
},
"output_type": "execute_result"
}
],
"source": [
"%format json\n",
"%display table \n",
"\n",
"PREFIX rdfs: \n",
"PREFIX foaf: \n",
"SELECT ?person ?name\n",
"WHERE {\n",
" ?person a foaf:Person .\n",
" ?person rdfs:label ?name\n",
" FILTER regex(?name,\"van gogh\",\"i\")\n",
" FILTER langMatches(lang(?name),\"en\")\n",
"} LIMIT 20"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
},
"source": [
"It is clear from the result that we want the DBPedia entity (we can click on the link for confirmation, and it will lead us to a DBPedia web page describing the resource).\n",
"\n",
"## Fact finding\n",
"\n",
"Now that we found his URI, let's search for places, dates and people related with van Gogh.\n",
"\n",
"In this query we also set the table to show the data type for each result"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"Return format: JSON
Display: table Show Types: on
"
]
},
"execution_count": 4,
"metadata": {
},
"output_type": "execute_result"
},
{
"data": {
"text/html": [
"prop type \n",
"value type http://dbpedia.org/ontology/birthDate uri \n",
"1853-03-30 typed-literal http://dbpedia.org/ontology/birthDate uri \n",
"1853-3-30 typed-literal http://dbpedia.org/ontology/birthPlace uri \n",
"http://dbpedia.org/resource/Zundert uri http://dbpedia.org/ontology/deathDate uri \n",
"1890-07-29 typed-literal http://dbpedia.org/ontology/deathDate uri \n",
"1890-7-29 typed-literal http://dbpedia.org/ontology/deathPlace uri \n",
"http://dbpedia.org/resource/Auvers-sur-Oise uri http://dbpedia.org/ontology/deathPlace uri \n",
"http://dbpedia.org/resource/Auberge_Ravoux uri http://dbpedia.org/ontology/wikiPageWikiLink uri \n",
"http://dbpedia.org/resource/Rob_Liefeld uri http://dbpedia.org/ontology/wikiPageWikiLink uri \n",
"http://dbpedia.org/resource/Harold_Hecht uri http://dbpedia.org/ontology/wikiPageWikiLink uri \n",
"http://dbpedia.org/resource/Stephen_Emmer uri http://dbpedia.org/ontology/wikiPageWikiLink uri \n",
"http://dbpedia.org/resource/Luke_Fildes uri http://dbpedia.org/ontology/wikiPageWikiLink uri \n",
"http://dbpedia.org/resource/Peter_Lindbergh uri http://dbpedia.org/ontology/wikiPageWikiLink uri \n",
"http://dbpedia.org/resource/Einojuhani_Rautavaara uri http://dbpedia.org/ontology/wikiPageWikiLink uri \n",
"http://dbpedia.org/resource/Claude_Monet uri http://dbpedia.org/ontology/wikiPageWikiLink uri \n",
"http://dbpedia.org/resource/Lazarus_of_Bethany uri http://dbpedia.org/ontology/wikiPageWikiLink uri \n",
"http://dbpedia.org/resource/Chen_Ke_(artist) uri http://dbpedia.org/ontology/wikiPageWikiLink uri \n",
"http://dbpedia.org/resource/William_Hood_Dunwoody uri http://dbpedia.org/ontology/wikiPageWikiLink uri \n",
"http://dbpedia.org/resource/Casimir_Lefaucheux uri http://dbpedia.org/ontology/wikiPageWikiLink uri \n",
"http://dbpedia.org/resource/Abraham_Diepraam uri http://dbpedia.org/ontology/wikiPageWikiLink uri \n",
"http://dbpedia.org/resource/Trento_Longaretti uri
Total: 295, Shown: 20
"
]
},
"execution_count": 4,
"metadata": {
},
"output_type": "execute_result"
}
],
"source": [
"%format json\n",
"%display table withtypes\n",
"\n",
"# We might have more than one triple pointing to the same object, so we group by object\n",
"# and take one arbitrary predicate\n",
"\n",
"SELECT (SAMPLE(?pred) AS ?prop) ?value\n",
"WHERE {\n",
"\n",
" # Places and dates\n",
" {\n",
" dbr:Vincent_van_Gogh ?pred ?value .\n",
" { ?pred rdfs:range xsd:date }\n",
" UNION\n",
" { ?pred rdfs:range dbo:Place }\n",
" }\n",
" # People van Gogh relates to\n",
" UNION \n",
" { \n",
" dbr:Vincent_van_Gogh ?pred ?value .\n",
" ?value a foaf:Person \n",
" }\n",
" # People related to van Gogh\n",
" UNION \n",
" { \n",
" ?value ?pred dbr:Vincent_van_Gogh .\n",
" ?value a foaf:Person \n",
" }\n",
"\n",
"} GROUP BY ?value ORDER BY ?prop\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
},
"source": [
"\n",
"\n",
"## Find a painting\n",
"Now we search for a van Gogh painting whose title contains _\"night\"_"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"Return format: JSON
Display: table
"
]
},
"execution_count": 4,
"metadata": {
},
"output_type": "execute_result"
},
{
"data": {
"text/html": [
""
]
},
"execution_count": 4,
"metadata": {
},
"output_type": "execute_result"
}
],
"source": [
"%format json\n",
"%display table \n",
"\n",
"\n",
"PREFIX rdfs: \n",
"PREFIX foaf: \n",
"SELECT DISTINCT (?picture) ?name\n",
"WHERE {\n",
" ?picture ?p1 dbr:Vincent_van_Gogh .\n",
" ?picture rdfs:label ?name .\n",
" FILTER regex(?name,\"night\", \"i\")\n",
" FILTER langMatches(lang(?name),\"en\") \n",
"}"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
},
"source": [
"Just to show another possibility, we repeat the same query but indicating `raw` display format"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
""
]
},
"execution_count": 5,
"metadata": {
},
"output_type": "execute_result"
},
{
"data": {
"text/plain": [
"{\n",
" \"head\": {\n",
" \"link\": [],\n",
" \"vars\": [\n",
" \"picture\",\n",
" \"name\"\n",
" ]\n",
" },\n",
" \"results\": {\n",
" \"bindings\": [\n",
" {\n",
" \"name\": {\n",
" \"type\": \"literal\",\n",
" \"value\": \"Café Terrace at Night\",\n",
" \"xml:lang\": \"en\"\n",
" },\n",
" \"picture\": {\n",
" \"type\": \"uri\",\n",
" \"value\": \"http://dbpedia.org/resource/Café_Terrace_at_Night\"\n",
" }\n",
" },\n",
" {\n",
" \"name\": {\n",
" \"type\": \"literal\",\n",
" \"value\": \"Dodge MacKnight\",\n",
" \"xml:lang\": \"en\"\n",
" },\n",
" \"picture\": {\n",
" \"type\": \"uri\",\n",
" \"value\": \"http://dbpedia.org/resource/Dodge_MacKnight\"\n",
" }\n",
" },\n",
" {\n",
" \"name\": {\n",
" \"type\": \"literal\",\n",
" \"value\": \"Midnight in Paris\",\n",
" \"xml:lang\": \"en\"\n",
" },\n",
" \"picture\": {\n",
" \"type\": \"uri\",\n",
" \"value\": \"http://dbpedia.org/resource/Midnight_in_Paris\"\n",
" }\n",
" },\n",
" {\n",
" \"name\": {\n",
" \"type\": \"literal\",\n",
" \"value\": \"Night in paintings (Western art)\",\n",
" \"xml:lang\": \"en\"\n",
" },\n",
" \"picture\": {\n",
" \"type\": \"uri\",\n",
" \"value\": \"http://dbpedia.org/resource/Night_in_paintings_(Western_art)\"\n",
" }\n",
" },\n",
" {\n",
" \"name\": {\n",
" \"type\": \"literal\",\n",
" \"value\": \"White House at Night\",\n",
" \"xml:lang\": \"en\"\n",
" },\n",
" \"picture\": {\n",
" \"type\": \"uri\",\n",
" \"value\": \"http://dbpedia.org/resource/White_House_at_Night\"\n",
" }\n",
" },\n",
" {\n",
" \"name\": {\n",
" \"type\": \"literal\",\n",
" \"value\": \"The Night Café\",\n",
" \"xml:lang\": \"en\"\n",
" },\n",
" \"picture\": {\n",
" \"type\": \"uri\",\n",
" \"value\": \"http://dbpedia.org/resource/The_Night_Café\"\n",
" }\n",
" },\n",
" {\n",
" \"name\": {\n",
" \"type\": \"literal\",\n",
" \"value\": \"Starry Night Over the Rhone\",\n",
" \"xml:lang\": \"en\"\n",
" },\n",
" \"picture\": {\n",
" \"type\": \"uri\",\n",
" \"value\": \"http://dbpedia.org/resource/Starry_Night_Over_the_Rhone\"\n",
" }\n",
" },\n",
" {\n",
" \"name\": {\n",
" \"type\": \"literal\",\n",
" \"value\": \"The Starry Night\",\n",
" \"xml:lang\": \"en\"\n",
" },\n",
" \"picture\": {\n",
" \"type\": \"uri\",\n",
" \"value\": \"http://dbpedia.org/resource/The_Starry_Night\"\n",
" }\n",
" }\n",
" ],\n",
" \"distinct\": false,\n",
" \"ordered\": true\n",
" }\n",
"}"
]
},
"execution_count": 5,
"metadata": {
},
"output_type": "execute_result"
}
],
"source": [
"%display raw \n",
"\n",
"PREFIX rdfs: \n",
"PREFIX foaf: \n",
"SELECT DISTINCT (?picture) ?name\n",
"WHERE {\n",
" ?picture ?p1 dbr:Vincent_van_Gogh .\n",
" ?picture rdfs:label ?name .\n",
" FILTER regex(?name,\"night\", \"i\")\n",
" FILTER langMatches(lang(?name),\"en\") \n",
"}"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
},
"source": [
"## Describe a painting\n",
"\n",
"Now we find out all that DBPedia knows about one of those paintings, _Starry Night Over the Rhone_"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false,
"scrolled": true
},
"outputs": [
{
"data": {
"text/html": [
"Return format: N3
Display: table
Label preferred languages: ['en']
Result maximum size: unlimited
"
]
},
"execution_count": 6,
"metadata": {
},
"output_type": "execute_result"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"WARNING: Some output was deleted.\n"
]
}
],
"source": [
"%format n3\n",
"%display table\n",
"%lang en\n",
"%show all\n",
"\n",
"PREFIX rdfs: \n",
"PREFIX foaf: \n",
"CONSTRUCT { ?s1 ?p1 dbr:Starry_Night_Over_the_Rhone .\n",
" dbr:Starry_Night_Over_the_Rhone ?p2 ?o1 .\n",
" }\n",
"WHERE {\n",
" { ?s1 ?p1 dbr:Starry_Night_Over_the_Rhone }\n",
" UNION\n",
" { dbr:Starry_Night_Over_the_Rhone ?p2 ?o1 }\n",
" \n",
" FILTER ( ?p1 != owl:sameAs && ?p2 != owl:sameAs)\n",
"}\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
},
"source": [
"Similar data could be obtained by asking the endpoint to `DESCRIBE` the resource. Let's do this, but for a twist let's ask the kernel to draw a graph with the results (for this to work, [Graphviz](http://www.graphviz.org/) should be installed in the system).\n",
"\n",
"We generate a PNG here. Note that `svg` is a much better format than `png`, if the browser supports it (better quality, and hyperlinked nodes)."
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"Return format: N3
Display: svg
Label preferred languages: ['en']
"
]
},
"execution_count": 11,
"metadata": {
},
"output_type": "execute_result"
},
{
"data": {
"image/svg+xml": "\n\n\n\n\n\n%3 \n \n\n\nnode0 \n\nStarry Night Over \nthe Rhône \n \n \n \n\n\nnode1 \n\nStarry Night over \nthe Rhone \n \n \n \n\n\nnode0->node1 \n\n \n \n \n \n\ndbo:wikiPageWikiLink \n \n \n \n\n\nnode0->node1 \n\n \n \n \n \n\ndbo:wikiPageRedirects \n \n \n \n\n\nnode2 \n\nΈναστρη Νύχτα \nπάνω από τον Ροδανό \n \n \n \n\n\nnode1->node2 \n\n \n \n \n \n\nowl:sameAs \n \n \n \n\n\nnode3 \n\nVincent van Gogh paintings \nof Arles \n \n \n \n\n\nnode1->node3 \n\n \n \n \n \n\ndbo:wikiPageWikiLink \n \n \n \n\n\nnode1->node3 \n\n \n \n \n \n\ndct:subject \n \n \n \n\n\nnode4 \n\nParis \n \n \n \n\n\nnode1->node4 \n\n \n \n \n \n\ndbo:wikiPageWikiLink \n \n \n \n\n\nnode1->node4 \n\n \n \n \n \n\ndbp:city \n \n \n \n\n\nnode5 \n\nVincent van \nGogh \n \n \n \n\n\nnode1->node5 \n\n \n \n \n \n\ndbo:wikiPageWikiLink \n \n \n \n\n\nnode1->node5 \n\n \n \n \n \n\ndbo:author \n \n \n \n\n\nnode6 \n\nThing \n \n \n \n\n\nnode1->node6 \n\n \n \n \n \n\nrdf:type \n \n \n \n\n\nnode7 \n\nOil \npainting \n \n \n \n\n\nnode1->node7 \n\n \n \n \n \n\ndbo:wikiPageWikiLink \n \n \n \n\n\nnode1->node7 \n\n \n \n \n \n\ndbp:type \n \n \n \n\n\nnode8 \n\nObject100002684 \n \n \n \n\n\nnode1->node8 \n\n \n \n \n \n\nrdf:type \n \n \n \n\n\nnode10 \n\nQ1464531 \n \n \n \n\n\nnode1->node10 \n\n \n \n \n \n\nowl:sameAs \n \n \n \n\n\nnode11 \n\nWikicatPaintingsByVincentVanGogh \n \n \n \n\n\nnode1->node11 \n\n \n \n \n \n\nrdf:type \n \n \n \n\n\nnode12 \n\nTrinquetaille \n \n \n \n\n\nnode1->node12 \n\n \n \n \n \n\ndbo:wikiPageWikiLink \n \n \n \n\n\nnode13 \n\nPainting103876519 \n \n \n \n\n\nnode1->node13 \n\n \n \n \n \n\nrdf:type \n \n \n \n\n\nnode14 \n\nSociété des \nArtistes Indépendants \n \n \n \n\n\nnode1->node14 \n\n \n \n \n \n\ndbo:wikiPageWikiLink \n \n \n \n\n\nnode15 \n\nNotte \nstellata sul Rodano \n \n \n \n\n\nnode1->node15 \n\n \n \n \n \n\nowl:sameAs \n \n \n \n\n\nnode16 \n\nGenre103434943 \n \n \n \n\n\nnode1->node16 \n\n \n \n \n \n\nrdf:type \n \n \n \n\n\nnode17 \n\n paintings \n \n \n \n\n\nnode1->node17 \n\n \n \n \n \n\ndct:subject \n \n \n \n\n\nnode1->node17 \n\n \n \n \n \n\ndbo:wikiPageWikiLink \n \n \n \n\n\nnode18 \n\nUrsa \nMajor \n \n \n \n\n\nnode1->node18 \n\n \n \n \n \n\ndbo:wikiPageWikiLink \n \n \n \n\n\nnode19 \n\nEugène \nBoch \n \n \n \n\n\nnode1->node19 \n\n \n \n \n \n\ndbo:wikiPageWikiLink \n \n \n \n\n\nnode20 \n\nWork \n \n \n \n\n\nnode1->node20 \n\n \n \n \n \n\nrdf:type \n \n \n \n\n\nnode21 \n\nWikicatLandscapePaintings \n \n \n \n\n\nnode1->node21 \n\n \n \n \n \n\nrdf:type \n \n \n \n\n\nnode22 \n\nSternennacht über \nder Rhone \n \n \n \n\n\nnode1->node22 \n\n \n \n \n \n\nowl:sameAs \n \n \n \n\n\nnode23 \n\nPaintings by Vincent \nvan Gogh \n \n \n \n\n\nnode1->node23 \n\n \n \n \n \n\ndct:subject \n \n \n \n\n\nnode1->node23 \n\n \n \n \n \n\ndbo:wikiPageWikiLink \n \n \n \n\n\nnode24 \n\nYellow \nHouse (Arles) \n \n \n \n\n\nnode1->node24 \n\n \n \n \n \n\ndbo:wikiPageWikiLink \n \n \n \n\n\nnode27 \n\nNight sky \n \n \n \n\n\nnode1->node27 \n\n \n \n \n \n\ndbo:wikiPageWikiLink \n \n \n \n\n\nnode28 \n\nWrong Way \nUp \n \n \n \n\n\nnode1->node28 \n\n \n \n \n \n\ndbo:wikiPageWikiLink \n \n \n \n\n\nnode29 \n\nArtifact100021939 \n \n \n \n\n\nnode1->node29 \n\n \n \n \n \n\nrdf:type \n \n \n \n\n\nnode30 \n\nCreativeWork \n \n \n \n\n\nnode1->node30 \n\n \n \n \n \n\nrdf:type \n \n \n \n\n\nnode31 \n\nWikicat19th-centuryPaintings \n \n \n \n\n\nnode1->node31 \n\n \n \n \n \n\nrdf:type \n \n \n \n\n\nnode33 \n\nWhole100003553 \n \n \n \n\n\nnode1->node33 \n\n \n \n \n \n\nrdf:type \n \n \n \n\n\nnode34 \n\nIrises \n(painting) \n \n \n \n\n\nnode1->node34 \n\n \n \n \n \n\ndbo:wikiPageWikiLink \n \n \n \n\n\nnode36 \n\nOrsay \n \n \n \n\n\nnode1->node36 \n\n \n \n \n \n\ndbo:wikiPageWikiLink \n \n \n \n\n\nnode1->node36 \n\n \n \n \n \n\ndct:subject \n \n \n \n\n\nnode37 \n\nRhône \nRiver \n \n \n \n\n\nnode1->node37 \n\n \n \n \n \n\ndbo:wikiPageWikiLink \n \n \n \n\n\nnode38 \n\nArles \n \n \n \n\n\nnode1->node38 \n\n \n \n \n \n\ndbo:wikiPageWikiLink \n \n \n \n\n\nnode39 \n\nm.063598 \n \n \n \n\n\nnode1->node39 \n\n \n \n \n \n\nowl:sameAs \n \n \n \n\n\nnode40 \n\nBrian Eno \n \n \n \n\n\nnode1->node40 \n\n \n \n \n \n\ndbo:wikiPageWikiLink \n \n \n \n\n\nnode42 \n\nOrsay \n \n \n \n\n\nnode1->node42 \n\n \n \n \n \n\ndbo:wikiPageWikiLink \n \n \n \n\n\nnode1->node42 \n\n \n \n \n \n\ndbo:museum \n \n \n \n\n\nnode43 \n\nWikicat1888Paintings \n \n \n \n\n\nnode1->node43 \n\n \n \n \n \n\nrdf:type \n \n \n \n\n\nnode45 \n\nCafe \nTerrace at Night \n \n \n \n\n\nnode1->node45 \n\n \n \n \n \n\ndbo:wikiPageWikiLink \n \n \n \n\n\nnode46 \n\nWikicatVincentVanGoghPaintingsOfArles \n \n \n \n\n\nnode1->node46 \n\n \n \n \n \n\nrdf:type \n \n \n \n\n\nnode47 \n\nStarry Night Over \nthe Rhone?oldid=744816584 \n \n \n \n\n\nnode1->node47 \n\n \n \n \n \n\nprov:wasDerivedFrom \n \n \n \n\n\nnode48 \n\nZeru izartsua Rodano \ngainean \n \n \n \n\n\nnode1->node48 \n\n \n \n \n \n\nowl:sameAs \n \n \n \n\n\nnode50 \n\nPhillips \nCollection \n \n \n \n\n\nnode1->node50 \n\n \n \n \n \n\ndbo:wikiPageWikiLink \n \n \n \n\n\nnode51 \n\nGas \nlighting \n \n \n \n\n\nnode1->node51 \n\n \n \n \n \n\ndbo:wikiPageWikiLink \n \n \n \n\n\nnode52 \n\nTheo van \nGogh (art dealer) \n \n \n \n\n\nnode1->node52 \n\n \n \n \n \n\ndbo:wikiPageWikiLink \n \n \n \n\n\nnode53 \n\nLandscape103640011 \n \n \n \n\n\nnode1->node53 \n\n \n \n \n \n\nrdf:type \n \n \n \n\n\nnode54 \n\nStarry Night Over \nthe Rhone \n \n \n \n\n\nnode1->node54 \n\n \n \n \n \n\nowl:sameAs \n \n \n \n\n\nnode55 \n\nThe \nStarry Night \n \n \n \n\n\nnode1->node55 \n\n \n \n \n \n\ndbo:wikiPageWikiLink \n \n \n \n\n\nnode56 \n\nSterrennacht boven \nde Rhône \n \n \n \n\n\nnode1->node56 \n\n \n \n \n \n\nowl:sameAs \n \n \n \n\n\nnode57 \n\nQ1464531 \n \n \n \n\n\nnode1->node57 \n\n \n \n \n \n\nowl:sameAs \n \n \n \n\n\nnode58 \n\nStarry Night Over \nthe Rhone \n \n \n \n\n\nnode1->node58 \n\n \n \n \n \n\nfoaf:isPrimaryTopicOf \n \n \n \n\n\nnode59 \n\nArtwork \n \n \n \n\n\nnode1->node59 \n\n \n \n \n \n\nrdf:type \n \n \n \n\n\nnode60 \n\nQuay \n \n \n \n\n\nnode1->node60 \n\n \n \n \n \n\ndbo:wikiPageWikiLink \n \n \n \n\n\nnode61 \n\nFrance Arles \nReattu LaCroix 2008.jpg \n \n \n \n\n\nnode1->node61 \n\n \n \n \n \n\ndbo:wikiPageWikiLink \n \n \n \n\n\nnode62 \n\nGraphicArt103453809 \n \n \n \n\n\nnode1->node62 \n\n \n \n \n \n\nrdf:type \n \n \n \n\n\nnode63 \n\nStarry Night Over \nthe Rhone.jpg?width=300 \n \n \n \n\n\nnode1->node63 \n\n \n \n \n \n\ndbo:thumbnail \n \n \n \n\n\nnode64 \n\nNoite \nEstrelada Sobre o Ródano \n \n \n \n\n\nnode1->node64 \n\n \n \n \n \n\nowl:sameAs \n \n \n \n\n\nnode65 \n\nStarry Night \nOver the Rhone.jpg \n \n \n \n\n\nnode1->node65 \n\n \n \n \n \n\nfoaf:depiction \n \n \n \n\n\nnode68 \n\nGwiaździsta noc \nnad Rodanem \n \n \n \n\n\nnode1->node68 \n\n \n \n \n \n\nowl:sameAs \n \n \n \n\n\nnode69 \n\nCreation103129123 \n \n \n \n\n\nnode1->node69 \n\n \n \n \n \n\nrdf:type \n \n \n \n\n\nnode71 \n\nColor \n \n \n \n\n\nnode1->node71 \n\n \n \n \n \n\ndbo:wikiPageWikiLink \n \n \n \n\n\nnode72 \n\nQ386724 \n \n \n \n\n\nnode1->node72 \n\n \n \n \n \n\nrdf:type \n \n \n \n\n\nnode73 \n\nPaintings \n \n \n \n\n\nnode1->node73 \n\n \n \n \n \n\nns19:hypernym \n \n \n \n\n\nnode74 \n\nNuit \nétoilée sur le Rhône \n \n \n \n\n\nnode1->node74 \n\n \n \n \n \n\nowl:sameAs \n \n \n \n\n\nnode75 \n\nArt102743547 \n \n \n \n\n\nnode1->node75 \n\n \n \n \n \n\nrdf:type \n \n \n \n\n\nnode76 \n\nRhone \n \n \n \n\n\nnode1->node76 \n\n \n \n \n \n\ndbo:wikiPageWikiLink \n \n \n \n\n\nnode77 \n\nPhysicalEntity100001930 \n \n \n \n\n\nnode1->node77 \n\n \n \n \n \n\nrdf:type \n \n \n \n\n\nnode5->node1 \n\n \n \n \n \n\ndbo:wikiPageWikiLink \n \n \n \n\n\nnode9 \n\nList of works \nby Vincent van Gogh \n \n \n \n\n\nnode9->node1 \n\n \n \n \n \n\ndbo:wikiPageWikiLink \n \n \n \n\n\nnode18->node1 \n\n \n \n \n \n\ndbo:wikiPageWikiLink \n \n \n \n\n\nnode25 \n\nIndex of World \nWar II articles (S) \n \n \n \n\n\nnode25->node1 \n\n \n \n \n \n\ndbo:wikiPageWikiLink \n \n \n \n\n\nnode26 \n\nGianluca \nMasi \n \n \n \n\n\nnode26->node1 \n\n \n \n \n \n\ndbo:wikiPageWikiLink \n \n \n \n\n\nnode32 \n\ns Chair \n \n \n \n\n\nnode32->node1 \n\n \n \n \n \n\ndbo:wikiPageWikiLink \n \n \n \n\n\nnode34->node1 \n\n \n \n \n \n\ndbo:wikiPageWikiLink \n \n \n \n\n\nnode35 \n\nNocturne \n(painting) \n \n \n \n\n\nnode35->node1 \n\n \n \n \n \n\ndbo:wikiPageWikiLink \n \n \n \n\n\nnode38->node1 \n\n \n \n \n \n\ndbo:wikiPageWikiLink \n \n \n \n\n\nnode41 \n\nStarry Night \n(disambiguation) \n \n \n \n\n\nnode41->node1 \n\n \n \n \n \n\ndbo:wikiPageDisambiguates \n \n \n \n\n\nnode41->node1 \n\n \n \n \n \n\ndbo:wikiPageWikiLink \n \n \n \n\n\nnode42->node1 \n\n \n \n \n \n\ndbo:wikiPageWikiLink \n \n \n \n\n\nnode44 \n\nStarry Night over \nthe Rhone \n \n \n \n\n\nnode44->node1 \n\n \n \n \n \n\ndbo:wikiPageRedirects \n \n \n \n\n\nnode44->node1 \n\n \n \n \n \n\ndbo:wikiPageWikiLink \n \n \n \n\n\nnode49 \n\nNight in \npaintings (Western art) \n \n \n \n\n\nnode49->node1 \n\n \n \n \n \n\ndbo:wikiPageWikiLink \n \n \n \n\n\nnode55->node1 \n\n \n \n \n \n\ndbo:wikiPageWikiLink \n \n \n \n\n\nnode58->node1 \n\n \n \n \n \n\nfoaf:primaryTopic \n \n \n \n\n\nnode66 \n\nCafé \nTerrace at Night \n \n \n \n\n\nnode66->node1 \n\n \n \n \n \n\ndbo:wikiPageWikiLink \n \n \n \n\n\nnode67 \n\nEffets de \nsoir \n \n \n \n\n\nnode67->node1 \n\n \n \n \n \n\ndbo:wikiPageWikiLink \n \n \n \n\n\nnode70 \n\nDécoration for the \nYellow House \n \n \n \n\n\nnode70->node1 \n\n \n \n \n \n\ndbo:wikiPageWikiLink \n \n \n \n \n \n"
},
"execution_count": 11,
"metadata": {
"unconfined": true
},
"output_type": "execute_result"
}
],
"source": [
"%format n3\n",
"%display diagram svg\n",
"%lang en\n",
"\n",
"PREFIX rdfs: \n",
"PREFIX foaf: \n",
"DESCRIBE dbr:Starry_Night_Over_the_Rhone"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
},
"source": [
"## Locate paintings\n",
"\n",
"Finally, to print out a slightly more complex graph, we will construct one with all of van Gogh's paintings, together with their location and the country they are in.\n",
"\n",
"This one we render as SVG; this has the said advantage of better quality (being a vector format). Plus nodes and edges can contain hyperlinks, so when they are URIs they point to the full URL (note that, unless the `withliterals` option is used, **all** represented nodes will be URIs)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"Return format: N3
Display: svg
"
]
},
"execution_count": 12,
"metadata": {
},
"output_type": "execute_result"
},
{
"data": {
"image/svg+xml": "\n\n\n\n\n\n%3 \n \n \n \n"
},
"execution_count": 12,
"metadata": {
"unconfined": true
},
"output_type": "execute_result"
}
],
"source": [
"%format n3\n",
"%display diagram svg\n",
"\n",
"PREFIX wd: \n",
"CONSTRUCT { ?painting dbp:museum ?museum .\n",
" ?painting dct:subject ?subject .\n",
" ?museum dbo:location ?location .\n",
" ?location dbo:country ?country .\n",
" }\n",
"WHERE {\n",
" ?painting dbp:artist dbr:Vincent_van_Gogh .\n",
" ?painting a wd:Q386724 .\n",
" ?painting a dbo:Artwork .\n",
" ?painting dbp:museum ?museum .\n",
" ?museum dbo:location ?location .\n",
" ?location dbo:country ?country .\n",
"}"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
},
"source": [
"Version: 1.1 (2016-08-10) \n",
"Author: Paulo Villegas
"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
]
}
],
"metadata": {
"kernelspec": {
"display_name": "SPARQL",
"language": "sparql",
"name": "sparql"
},
"language_info": {
"codemirror_mode": {
"name": "sparql"
},
"mimetype": "application/sparql-query",
"name": "sparql",
"pygments_lexer": "sparql-nb"
}
},
"nbformat": 4,
"nbformat_minor": 0
}