Created
July 10, 2015 06:48
-
-
Save tistre/12c9110f54711442e36d to your computer and use it in GitHub Desktop.
Minimal example for parsing planetdam.org RDF/XML using EasyRDF
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 | |
/* | |
Minimal example for parsing http://planetdam.org article list RDF/XML | |
using http://www.easyrdf.org | |
1) Install Composer, see http://www.easyrdf.org/docs/getting-started : | |
curl -s https://getcomposer.org/installer | php | |
2) Create composer.json: | |
{ | |
"require": { | |
"easyrdf/easyrdf": "*" | |
} | |
} | |
3) Install EasyRDF: | |
php composer.phar install | |
4) Run this file from the command line: | |
php planetdam_easyrdf_demo.php | |
*/ | |
if (PHP_SAPI === 'cli') | |
{ | |
error_reporting(E_ALL); | |
ini_set('error_log', false); | |
ini_set('display_errors', 'stderr'); | |
} | |
require 'vendor/autoload.php'; | |
$graph = EasyRdf_Graph::newAndLoad('http://planetdam.org/api/article'); | |
$items = $graph->allOfType('schema:CreativeWork'); | |
foreach ($items as $item) | |
{ | |
echo "Item URL: " . $item->getUri() . "\n"; | |
$name = $item->getLiteral('schema:name'); | |
if ($name) | |
{ | |
echo "Name: " . $name->getValue() . "\n"; | |
} | |
$thumbnail = $item->getResource('schema:thumbnail'); | |
if ($thumbnail) | |
{ | |
$thumbnail_url = $thumbnail->get('schema:contentUrl'); | |
if ($thumbnail_url) | |
echo "Thumbnail URL: " . $thumbnail_url->getValue() . "\n"; | |
} | |
echo "\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment