Created
April 14, 2020 10:37
-
-
Save companje/edcc873fcdae8c0e649b9e10775954d6 to your computer and use it in GitHub Desktop.
SPARQL query get GUIDs by Trefwoord
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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