-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetchData.js
More file actions
45 lines (34 loc) · 1.66 KB
/
fetchData.js
File metadata and controls
45 lines (34 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//resource used: https://dev.to/shoupn/javascript-fetch-api-and-using-asyncawait-47mp
//MDN await: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await
export default async function fetchData(){
//puts the endpoint in a variable
const url ="https://api.data.netwerkdigitaalerfgoed.nl/datasets/ivo/NMVW/services/NMVW-36/sparql"
const 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/>
SELECT ?herkomstSuper ?herkomstSuperLabel ?typeLabel (COUNT(?cho) AS ?amount)
WHERE {
# geef ruilmiddelen
<https://hdl.handle.net/20.500.11840/termmaster14607> skos:narrower* ?type .
?type skos:prefLabel ?typeLabel .
# geef de continenten
<https://hdl.handle.net/20.500.11840/termmaster2> skos:narrower ?herkomstSuper .
?herkomstSuper skos:prefLabel ?herkomstSuperLabel .
# geef per continent de onderliggende geografische termen
?herkomstSuper skos:narrower* ?herkomstSub .
?herkomstSub skos:prefLabel ?herkomstSubLabel .
# geef objecten bij de onderliggende geografische termen
?cho dct:spatial ?herkomstSub .
?cho edm:object ?type .
} #GROUP BY ?herkomstSuper ?herkomstSuperLabel
`
//await pauses async function to pause untill promis is settled => when function resumes value of await becomes that of fulfilled promise
let response = await fetch(url + "?query=" + encodeURIComponent(query) + "&format=json");
let json = await response.json();
const data = json.results.bindings;
return data
}