EasyRdf Examples

artistinfo.php

Example of mapping an RDF class type to a PHP Class

This example fetches and displays artist information from the BBC Music website. The artist object is an instance of the Model_MusicArtist class, so it is possible to call custom PHP methods on the object.

It also demonstrates setting new namespaces.

basic.php

Basic "Hello World" type example

A new EasyRdf_Graph object is created and then the contents of my FOAF profile is loaded from the web. An EasyRdf_Resource for the primary topic of the document (me, Nicholas Humfrey) is returned and then used to display my name.

sparql_queryform.php

Form to submit SPARQL queries and display the result

This example presents a form that you can enter the URI of a a SPARQL endpoint and a SPARQL query into. The results are displayed using a call to dump() on what will be either a EasyRdf_Sparql_Result or EasyRdf_Graph object.

A list of registered namespaces is displayed above the query box - any of these namespaces can be used in the query and PREFIX statements will automatically be added to the start of the query string.

basic_sparql.php

Example of making a SPARQL SELECT query

The example creates a new SPARQL client, pointing at the Talis hosted BBC Backstage store. It then makes a SELECT query that returns all of the episodes, along with their episode number and title.

Note how the PO prefix declaration is automatically added to the query.

httpget.php

No RDF, just test EasyRdf_Http_Client

This example does nothing but test EasyRdf's build in HTTP client. It demonstrates setting Accept headers and displays the response headers and body.

review_extract.php

Extract a review from a page containing Google Review RDFa

This example uses ARC2's RDFa parser to extract the Google rich snippets review vocabulary from an HTML page.

dbpedia_village.php

Fetch and information about villages in Fife from dbpedia.org

graphstore.php

Store and retrieve data from a SPARQL 1.1 Graph Store

This example adds a triple containing the current time into a local graph store. It then fetches the whole graph out and displays the contents.

Note that you will a graph store, for example RedStore, running on your local machine in order to test this example.

graph_direct.php

Example of using EasyRdf_Graph directly without EasyRdf_Resource

Triple data is inserted and retrieved directly from a graph object, where it is stored internally as an associative array.

converter.php

Convert RDF from one format to another

The source RDF data can either be fetched from the web or typed into the Input box.

The first thing that this script does is make a list the names of the supported input and output formats. These options are then displayed on the HTML form.

The input data is loaded or parsed into an EasyRdf_Graph. That graph is than outputted again in the desired output format.

dump.php

Display the contents of a graph

Data from the chosen URI is loaded into an EasyRdf_Graph object. Then the graph is dumped and printed to the page using the $graph->dump() method.

The call to preg_replace() replaces links in the page with links back to this dump script.

uk_postcode.php

Example of resolving UK postcodes using uk-postcodes.com

Another basic example that demonstrates registering namespaces, loading RDF data from the web and then directly displaying literals from the graph on the page.

foafinfo.php

Display the basic information in a FOAF document

The example starts by loading the requested FOAF document from the web. It then tries to work out if the URI given was for the person or the document about the person.

If a person is found, then the person's name, homepage and description are shown, along with a list of the person's friends.

zend_framework.php

Example of using Zend_Http_Client and Zend_Loader_Autoloader with EasyRdf

This example creates a simple graph in memory, saves it to a local graphstore and then fetches the data back using a SPARQL SELECT query. Zend's curl HTTP client adaptor is used to perform the HTTP requests.

foafmaker.php

Construct a FOAF document with a choice of serialisations

This example is similar in concept to Leigh Dodds' FOAF-a-Matic. The fields in the HTML form are inserted into an empty EasyRdf_Graph and then serialised to the chosen format.

html_tag_helpers.php

Rails Style html tag helpers to make the EasyRdf examples simplier

serialise.php

Basic serialisation example

This example create a simple FOAF graph in memory and then serialises it to the page in the format of choice.