Created
June 24, 2016 11:14
-
-
Save cgueret/255e3ab24b9c76baedcd0f53d704e0ae to your computer and use it in GitHub Desktop.
Searching for assets on the RES platform
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 | |
/** | |
* Find assets associated to a particular topic | |
* | |
* In this example we search for all the assets related to a particular topic. | |
* This topic has to be identified by its URI. In order to find the relevant | |
* URI a first call to a search (see "search.php") can be necessary. | |
* | |
* @copyright Copyright (c) 2016 BBC | |
* @license http://unlicense.org/ | |
*/ | |
# Do some init to include EasyRDF and define useful namespaces | |
require_once realpath(__DIR__)."/vendor/autoload.php"; | |
EasyRdf_Namespace::set('olo', 'http://purl.org/ontology/olo/core#'); | |
# This is the identifier for the play "Romeo and Juliet" | |
$topic = "http://acropolis.org.uk/af28bd78a968460c9bba91839359539e#id"; | |
# Load the description of the topic | |
$graph = EasyRdf_Graph::newAndLoad(str_replace('#id', '.rdf', $topic)); | |
# Convert the ordered list of results into an array | |
$results = array(); | |
foreach($graph->allOfType('olo:Slot') as $entry) { | |
$index = $entry->get('olo:index')->getValue(); | |
$item = array(); | |
$item['uri'] = $entry->get('olo:item')->getUri(); | |
$results[$index] = $item; | |
} | |
ksort($results); | |
# Iterate over all the results to fetch additional information | |
foreach($results as $index => $item) { | |
$graph->load(str_replace('#id', '.rdf', $item['uri'])); | |
foreach($graph->properties($item['uri']) as $property) { | |
$item[$property] = array(); | |
foreach($graph->all($item['uri'], $property) as $value) { | |
if (is_a($value, "EasyRdf_Literal")) | |
array_push($item[$property], $value->getValue()); | |
else if (is_a($value, "EasyRdf_Resource")) | |
array_push($item[$property], $value->getUri()); | |
} | |
} | |
$results[$index] = $item; | |
} | |
# Print all the results | |
print_r ($results); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment