Published
Edited
Aug 30, 2021
Importers
1 star
Insert cell
Insert cell
Insert cell
Insert cell
async function querySPARQLendpoint (endpoint, SPARQL_query, prefixes = true) {
// initialize tabular results array
let results = [];

// append endpoint URL with query as URL-encoded variable
let URLencodedQuery = endpoint + `?query=${encodeURIComponent(SPARQL_query)}` + `&output=json`;

// await JSON response from URL-encoded query
let JSON_query_results = await fetch(URLencodedQuery, {
headers: { accept: "application/sparql-results+json" }
}).then(response => response.json());
if(prefixes) {
// parse PREFIX instances from SPARQL query (to make output results more readable)
let Prefixes = parseSPARQLPrefixes(SPARQL_query);
// parse JSON response into tabular format and replace namespace prefixes where available
results = parseSPARQL(JSON_query_results, Prefixes);
} else {
let Prefixes = new Map([[]]);
results = parseSPARQL(JSON_query_results, Prefixes)
}
return results;
}
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more