RDF Icon

Rdfworld.php


Description:
Rdfworld.php is an RDF to PHP object converter, inspired by Aaron Swartz's TRAMP for Python.
It allows PHP developers to convert RDF Resources into PHP objects with appropriate properties. For the gritty details, see the documentation.

Rdfworld.php uses Chris Bizer's RDF API for PHP to do the actual parsing.
It is free to use and redistribute subject to the terms of the Gnu GPL.

Usage Example:
RSS 1.0 newsfeed to PHP object to output:
$feedrdf= file_get_contents("http://www.php.net/news.rss");
include_once("rdfworld.php");
$world= new World($feedrdf);
$channels= $world->getThingsByType("rss:channel");
$channel= $channels[0];
print "<h1>$channel->rss_title</h1>$channel->rss_description<hr />";

Download:

Source tarball, including RDF API and test scripts: rdfworld-2003-02-24.tar.gz

Testing:
The rdfworld.php testbench will fetch RDF from any http URL and turn it into PHP objects: rdfworld-test.php
There is also an RSS test script that displays the PHP newsfeed: rsstest.php

Important Notice:
This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions; please refer to the GNU General Public License for details.

Rdfworld.php is written and maitained by Chris Snyder.


Documentation:

Rdfworld.php consists of two PHP Classes, World and Thing, as well as some runtime variables and a debugging function

It uses classes from the RDF API for PHP, which is documented separately.  For general info on RDF, please consult W3.org or this unofficial reference.

See the sources of rdfworld-test.php and rsstest.php for usage examples.

Please send errors, omissions, bugs, and patches to Chris Snyder (csnyder@chxo.com).


Changelog:
2002-02-24: Support for untyped Resources
Namespace lookup from RDF if necessary
World->addNamespace() - add to World->nsregistry
2002-02-23: Initial release


Class World:

A container object that represents the known-world of the RDF.

Variables:
$rdf
String: RDF describing World
$model
Object: Model object returned by RDF API for PHP
$nsregistry
Array: associative array of names and URLs of common namespaces.
Example: rss=>http://purl.org/rss/1.0/
$_populated
Boolean: indicates that populate() has been called (deprecated)
$_untypedResources
Array: URIs of Resources without rdf:type predicates.


Methods:
World( $rdf="" )

Creator method.
If $rdf is provided, will populate() the World on creation.

populate( $rdf )

Parses $rdf using RDF API for PHP and assigns the resulting Model to $this->model
Note: future versions will allow multiple populate() calls per world in order to aggregate RDF from different sources.

getThingTypes()

Finds all of the valid types of things present in the World.
Returns an array of strings suitable for use as $typenames in getThingsByType($typename).

getThingsByType( $typename )

Finds all Resources in the World with a particular rdf:type.
$typename should be a string in the format ns:typename, like "rss:channel".
For untyped Resources, use "rdfs:Resource" as $typename.
Returns an array of Thing objects.

addNamespace($namespace,$key="")

Adds $namespace to $this->nsregistry with short name $key.
If $key is not specified, a unique name will be created (like ns1, ns2, etc.)
Note that a number of common namespaces are defined in $this->nsregistry on creation and do not need to be added manually. They are: rdf, rdfs, rss, dc, foaf, cc, daml, log, doc, and content.
getNamespace( $ns )
getNs( $namespace )

Methods for looking up values in the $this->nsregistry array.

  top

Class Thing:

An object representing an individual RDF Resource (the Subject of a set of triples).

Variables:
$uri String: URI of Thing
$type String: rdf:type of thing
$model Object: triples Model of self
$world Object Reference: containing World
$_ukindex Integer: Index number used to generate property names in case property name cannot be determined.


Methods:
Thing()

Creator method

fromModel( $model, &$world )

Takes a Model consisting of triples about a single single RDF Resource and uses it to assign property values to the Thing.

Called by World->getThingsByType() in order to build Things.

getPropertiesList()

Generates an HTML listing of all the properties of a Thing.
Returns string.

  top

Runtime Variables:

$rdfworldroot
String: directory containing rdfworld-class.php
$rdfw_error
String: HTML error channel used by rdfwdebug()
  top

Global Functions:

rdfwdebug( $message, $level=0 )
     
Adds $message to $rdfw_error if $level is less-than or equal-to $_REQUEST[debug].

If $level=0, error is considered fatal. $message will be displayed and program exectution will be halted.
  top



  PHP Logo   RDF Resource Description Framework Metadata Icon   Valid XHTML 1.0!

$Id: index.htm,v 1.4 2003/02/25 03:44:27 csnyder Exp $