This page lists SPARQL Queries that you can test on a Dutch Ships and Sailors SPARQL Endpoint. There are two ClioPatria triple stores: one hosted at Huygens ING (http://dutchshipsandsailors.nl/data/) and one hosted at VU (http://semanticweb.cs.vu.nl/dss/). It is best to use the second one for this hands on session. On the web interface you can browse the data (through the menu item “Places”->”Graphs” or through the search box in the top right). For live SPARQL Queries you find a number of options under the “Query” menu This includes the great Yasgui interface with all kinds of query assistance or the simple form. I suggest using that one.
If you want to use an external tool for these queries (such as CURL or SPARQL for R), you should use the endpoint for machines which is at “/sparql/” (Don’t forget the slash at the end ie. http://semanticweb.cs.vu.nl/dss/sparql/?query=PREFIX…).
The data
These following example queries work on the Dutch Asiatic Shipping subset of the DSS data. The dataset lists voyages of VOC ships in the 17th Century, including the ship, its name, the captain, date and place of departure and arrival. To get an overview over what is in this data, you can look at its main named graph in the ClioPatria interface or, more specifically at the list of predicates used in that graph. Another way is to look at an instance of a specific voyage, for example this one: http://purl.org/collections/nl/dss/das/voyage-5580_1.
Example queries and exercises
Below you will find the queries, which you can copy-paste into the interactive query fields. “#” denotes a comment. In between the examples there are a few open exercises to expand on the queries. For inspiration and checking syntax, you can look at a SPARQL tutorial or this page with
SPARQL examples for statistical queries.
- The prefix for Das is “http://purl.org/collections/nl/dss/das/”
- It is a good idea to set the entailment to ‘rdfslite’ (this reduces calculation time
Our first query: List the first 10 Triples
SELECT * WHERE { ?x ?y ?z . } LIMIT 10
Now, list the first 100 “X is of type Class Z” triples (“a” is shorthand for rdf:type)
SELECT * WHERE { ?x a ?z . } LIMIT 100
Find all distinct predicates that DAS Ships have (Set Entailment to “rdfslite” otherwise the query takes a very long time).
PREFIX das: <http://purl.org/collections/nl/dss/das/> SELECT DISTINCT ?pred WHERE { ?x a das:Ship . ?x ?pred ?obj. } LIMIT 100
# EXERCISE 1A: Find all distinct classes. What are these?
# EXERCISE 1B: Find all distinct classes in the DAS named graph (hint, you can use GRAPH <http://purl.org/collections/nl/dss/das/das_data.ttl> { *graph pattern here* }
Find all DAS places with preferred label “Middelburg”
PREFIX das: <http://purl.org/collections/nl/dss/das/> PREFIX skos: <http://www.w3.org/2004/02/skos/core#> SELECT * WHERE { ?x a das:Place . ?x skos:prefLabel "Middelburg". } LIMIT 100
Find all ships with name “WITTE”:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT * WHERE { ?x a das:Ship . ?x rdfs:label ?label. FILTER(regex(?label, "WITTE")) } LIMIT 100
Find all ships with name “WITTE” and their shiptypes &gt; Why are there suddenly only 20 hits?:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT * WHERE { ?x a das:Ship . ?x rdfs:label ?label. ?x das:typeOfShip ?type. FILTER(regex(?label, "WITTE")) } LIMIT 100
Find all ships with name “WITTE” and optionaly their shiptypes
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT * WHERE { ?x a das:Ship . ?x rdfs:label ?label. OPTIONAL {?x das:typeOfShip ?type.} FILTER(regex(?label, "WITTE")) } LIMIT 100
Count the total number of ships in DAS
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT (COUNT(?type) as ?ntype) WHERE { ?x a das:Ship . ?x das:typeOfShip ?type. }
# EXERCISE 2: FIND all shiptypes in DAS. How many are there? What are there preferred labels (skos:prefLabel)?
# EXERCISE 3: Find all ship names of shiptypes with the word “hoeker” in the ship type name
Count the number of ships per ship type in DAS
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?type (COUNT(?type) as ?ntype) WHERE { ?x a das:Ship . ?x das:typeOfShip ?type. } GROUP BY ?type
Count the types of ships in DAS that sailed from Texel
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?type (COUNT(?type) as ?ntype) WHERE { ?x a das:Ship . ?x das:typeOfShip ?type. ?voy das:has_ship ?x. ?voy das:placeOfDeparture das:place-Texel. } GROUP BY ?type
Explore links from DAS to Geonames
SELECT * WHERE { ?x das:placeOfArrival ?dasplace. ?dasplace a das:Place . ?dasplace skos:exactMatch ?gnplace. } LIMIT 100
What do we know about Geonames places that are linked to from DAS places? (list all predicates that a Geonames place has).
SELECT DISTINCT ?pred WHERE { ?dasplace a das:Place . ?dasplace skos:exactMatch ?gnplace. ?gnplace ?pred ?y. } LIMIT 50
Alternatively, you can also see this in the ClioPatria interface: http://semanticweb.cs.vu.nl/dss/browse/list_resource?r=http://sws.geonames.org/2745738/
For which DAS places can we find spanish placenames through the link to Geonames
PREFIX skos: <http://www.w3.org/2004/02/skos/core#> SELECT ?esname WHERE { ?dasplace a das:Place. ?dasplace skos:exactMatch ?gnplace. ?gnplace <http://www.geonames.org/ontology#alternateName> ?esname. FILTER(langMatches(lang(?esname), "ES")) }
#EXERCISE 4: What are the latitude/longitudes for the place of arrival of das:voyage-5087_1
#EXERCISE 5: How many “pinas” ships (type) sailed to an island (geonames featureCode http://www.geonames.org/ontology#T.ISL)
GZMVOC
These queries are about another dataset in DSS: the Generale Zeemonsterrollen VOC or GZMVOC. It is related to the DAS set but this contains data about counting and payment of ships and sailors rather than the voyages. It also is in the Dutch language data. First have a look at one such counting through the CLioPatria interface: http://purl.org/collections/nl/dss/gzmvoc/telling-2240-De_Brugh. This will show you the type of triples that GZMVOC contains.
List all countings where asiatic sailors were found, for those list the number of sailors and optionally the number of supervisors
SELECT * WHERE { ?count gzmvoc:aziatischeBemanning ?asCrew. ?asCrew gzmvoc:azAantalMatrozen ?sailor. OPTIONAL {?asCrew gzmvoc:azAantalVoorman ?supervisor.} } LIMIT 50
# Count the birthplaces of GZMVOC captains towards the province of where they were born (through link with GeoNames)
PREFIX skos: <http://www.w3.org/2004/02/skos/core#> SELECT ?provname (COUNT (?count) AS ?nrcount )WHERE { ?count gzmvoc:schipper ?capt. ?capt gzmvoc:has_geboorteplaats ?place. ?place skos:exactMatch ?gnplace. ?gnplace <http://www.geonames.org/ontology#parentADM1> ?province. ?province <http://www.geonames.org/ontology#name> ?provname. } GROUP by ?provname
# Do the same but only for captains that were on at least one ship for which asiatic sailors were registered
PREFIX skos: <http://www.w3.org/2004/02/skos/core#> SELECT ?provname (COUNT (?count) AS ?nrcount )WHERE { ?count gzmvoc:aziatischeBemanning ?asCrew. ?asCrew gzmvoc:azAantalMatrozen ?sailor. ?count gzmvoc:schipper ?capt. ?capt gzmvoc:has_geboorteplaats ?place. ?place skos:exactMatch ?gnplace. ?gnplace <http://www.geonames.org/ontology#parentADM1> ?province. ?province <http://www.geonames.org/ontology#name> ?provname. } GROUP by ?provname
# EXERCISE 6: For a GZMVOC record, get the number of people counted on board. Do this only for records of ships that sailed from “China” (Through the link with DAS)
Compare ship names for GZMVOC and DAS
PREFIX skos: <http://www.w3.org/2004/02/skos/core#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?shiplabel1 ?shiplabel2 WHERE { ?tcount a gzmvoc:Telling. ?tcount gzmvoc:schip ?ship1. ?ship1 gzmvoc:scheepsnaam ?shiplabel1. ?tcount gzmvoc:has_das_link_heen ?dasrecord. ?dasrecord das:has_ship ?dasship. ?dasship rdfs:label ?shiplabel2. } LIMIT 100
# EXERCISE 7: For a GZMVOC record, get the number of people counted on board. Do this only for records of ships that sailed from “China” (Through the link with DAS)
Some links and further exercises
Other interesting SPARQL endpoints
-
- http://hackalod.com/: experimental KB endpoint
- https://dbpedia.org/sparql: DBPedia SPARQL endpoint
- Yasgui.org lists many endpoints and also allows you to query these remotely from the yasgui interactive endpoint
RDFLib
RDFLib is a SPARQL Python library. It provides data structures and functions to deal with RDF graphs and also has built-in support for SPARQL queries.
SPARQL for R
When you are finished or bored with these exercises, you can try to do SPARQL queries from an external tool. For example, the statistical package R has a nice library SPARQL which allows you to do queries and process the results for further analysis and visualisation. If you are familiar with R, as an exercise, get SPARQL for R running and do an interesting query on the DSS data. Then, process the results to derive statistical results or visualise in a graph (for example, visualise the wages of asiatic sailors vs non-asiatic in a bar chart). The links below should help you get started.