Skip to content

Instantly share code, notes, and snippets.

@tistre
Created July 10, 2015 06:48
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 tistre/12c9110f54711442e36d to your computer and use it in GitHub Desktop.
Save tistre/12c9110f54711442e36d to your computer and use it in GitHub Desktop.
Minimal example for parsing planetdam.org RDF/XML using EasyRDF
<?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