Skip to content

Instantly share code, notes, and snippets.

@companje
Created April 14, 2020 10:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save companje/edcc873fcdae8c0e649b9e10775954d6 to your computer and use it in GitHub Desktop.
Save companje/edcc873fcdae8c0e649b9e10775954d6 to your computer and use it in GitHub Desktop.
SPARQL query get GUIDs by Trefwoord
<?php
header("Content-type: text/json");
$trefwoord = $_GET["trefwoord"];
$sparqlquery = '
PREFIX veld: <http://archief.io/veld#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT distinct * WHERE {
?sub veld:THWTW "'.$trefwoord.'" .
?sub rdfs:label ?label
BIND(REPLACE(str(?sub), "http://archief.io/id/", "") AS ?img)
} LIMIT 100';
$url = "https://api.data.netwerkdigitaalerfgoed.nl/datasets/mi2rdf/mi2rdf/services/mi2rdf/sparql?query=" . urlencode($sparqlquery) . "";
// does not like url parameters, send accept header instead
$opts = [
"http" => [
"method" => "GET",
"header" => "Accept: application/sparql-results+json\r\n"
// "header" => "Accept: text/csv\r\n"
]
];
$context = stream_context_create($opts);
// Open the file using the HTTP headers set above
$response = file_get_contents($url, false, $context);
// echo $response;
// die();
$json = json_decode($response, true);
$items = [];
foreach ($json['results']['bindings'] as $row) {
$items[] = $row['img']['value'];
}
echo json_encode($items);
die();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment