Used Data and SPARQL Queries - lennartdeknikker/frontend-data GitHub Wiki
Query for extent values
This query gives back all the extent values for ancestor statues from Indonesia. I want to build the app to be able to show this data for different kind of objects, but this is the data I will start with. It has just 40 results which makes it easy to process, but I'll make it work just as well with more.
Query
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX edm: <http://www.europeana.eu/schemas/edm/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?identifier
(SAMPLE(?extent) AS ?extentSample)
WHERE {
<https://hdl.handle.net/20.500.11840/termmaster7745> skos:narrower* ?place .
?place skos:prefLabel ?placeName .
VALUES ?type { "Voorouderbeelden" "Voorouderbeeld" "voorouderbeelden" "voorouderbeeld" }
?cho dct:spatial ?place ;
dc:title ?title ;
dc:type ?type ;
dc:description ?description ;
dct:medium ?medium ;
foaf:depiction ?depiction ;
dct:extent ?extent ;
dc:subject ?subject;
edm:isRelatedTo ?related ;
dc:identifier ?identifier .
FILTER langMatches(lang(?title), "eng")
}
GROUP BY ?identifier
Resulting data
The query gives back objects with just an identifier value and an extent value.
40 results
...
"bindings": [
{
"identifier": {
"type": "literal",
"value": "759463"
},
"extentSample": {
"type": "literal",
"value": "13 cm"
}
},
...
Query for image links, titles and more properties
I will also need image links and titles of these objects. Hence this second query:
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX edm: <http://www.europeana.eu/schemas/edm/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?identifier
(SAMPLE(?depiction) AS ?depictionSample)
(SAMPLE(?title) AS ?titleSample)
WHERE {
<https://hdl.handle.net/20.500.11840/termmaster7745> skos:narrower* ?place .
?place skos:prefLabel ?placeName .
VALUES ?type { "Voorouderbeelden" "Voorouderbeeld" "voorouderbeelden" "voorouderbeeld" }
?cho dct:spatial ?place ;
dc:type ?type ;
dc:title ?title ;
dc:description ?description ;
dct:medium ?medium ;
foaf:depiction ?depiction ;
dct:extent ?extent ;
dc:subject ?subject;
edm:isRelatedTo ?related ;
dc:identifier ?identifier .
FILTER langMatches(lang(?title), "eng")
}
GROUP BY ?identifier
Resulting data
This query gives back values for the identifier, which can be used to match the result to the results of other queries. Furthermore, this query gives back values for the image links and object titles. 40 results
...
"bindings": [
{
"identifier": {
"type": "literal",
"value": "759463"
},
"depictionSample": {
"type": "literal",
"value": "http://collectie.wereldculturen.nl/cc/imageproxy.ashx?server=localhost&port=17581&filename=images/Images/RV//3109-1_02.jpg"
},
"titleSample": {
"type": "literal",
"xml:lang": "eng",
"value": "Christian ancestor"
}
},
...
Enhanced query, combining results
I changed the query to add longitude and latitude, because this data suddenly became available. To make things easier, I rewrote the query to combine the previous two as well, so this query not only obtains all extent data and identifiers, but also obtains the titles, image links, place names and location data for all objects.
When rewriting these queries, I discovered there are way more ancestor statues than I anticipated. That means my extent processor is no longer working since more results come with more edge cases.
Query
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX edm: <http://www.europeana.eu/schemas/edm/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX hdlh: <https://hdl.handle.net/20.500.11840/termmaster>
PREFIX wgs84: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX gn: <http://www.geonames.org/ontology#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT (SAMPLE(?identifier) AS ?identifierSample) ?title ?placeName ?imageLink ?extent ?lat ?long WHERE {
<https://hdl.handle.net/20.500.11840/termmaster7745> skos:narrower* ?place .
?place skos:prefLabel ?placeName .
VALUES ?type { "Voorouderbeelden" "Voorouderbeeld" "voorouderbeelden" "voorouderbeeld" }
?cho dct:spatial ?place ;
dc:title ?title ;
dc:type ?type ;
dc:identifier ?identifier ;
dct:extent ?extent ;
edm:isShownBy ?imageLink .
?place skos:exactMatch/wgs84:lat ?lat .
?place skos:exactMatch/wgs84:long ?long .
}
GROUP BY ?identifier ?title ?place ?placeName ?type ?imageLink ?lat ?long ?extent
Resulting data
This query stores all the necessary data in objects with an identifier. 2372 results
"bindings": [
{
"identifierSample": {
"type": "literal",
"value": "WM-474"
},
"title": {
"type": "literal",
"xml:lang": "ned",
"value": "teteles"
},
"placeName": {
"type": "literal",
"value": "Likupang"
...
Using queries in the application
As you can see below, I eventually put the query in a function. To make it possible to search for all kind of objects, the type is stored in a variable. This way users can fill in their own keywords through a text input.
// generates a query given a certain searchword.
function getQueryFor(searchWord) {
return `
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX edm: <http://www.europeana.eu/schemas/edm/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX hdlh: <https://hdl.handle.net/20.500.11840/termmaster>
PREFIX wgs84: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX gn: <http://www.geonames.org/ontology#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT (SAMPLE(?identifier) AS ?identifierSample) ?title ?placeName ?imageLink ?extent ?lat ?long WHERE {
<https://hdl.handle.net/20.500.11840/termmaster7745> skos:narrower* ?place .
?place skos:prefLabel ?placeName .
VALUES ?type {"${searchWord.toLowerCase()}"}
?cho dct:spatial ?place ;
dc:title ?title ;
dc:type ?type ;
dc:identifier ?identifier ;
dct:extent ?extent ;
edm:isShownBy ?imageLink .
?place skos:exactMatch/wgs84:lat ?lat .
?place skos:exactMatch/wgs84:long ?long .
}
GROUP BY ?identifier ?title ?place ?placeName ?type ?imageLink ?lat ?long ?extent
`;
}