Saturday, March 19, 2011

XML_GRDDL, BestBuy & Good Relations

Digg used to publish rdfa, but it appears to have given it the boot.

So who is out there publishing useful rdfa? Best Buy of course.

While they appear to have sold out of their example rdfa product you can still get a heck of a lot of data out about the store itself.

The code:

$url = 'http://stores.bestbuy.com/577/fairless-hills-pa/products/open-box/frigidaire-30-freestanding-range/0012505540066/?uid=118';

$options = XML_GRDDL::getDefaultOptions();
$options['log'] = Log::singleton('console');
$grddl = XML_GRDDL::factory('xsl', $options);

$data = $grddl->fetch($url);

$data = $grddl->appendProfiles($data, array('http://ns.inria.fr/grddl/rdfa/'));

$stylesheets = $grddl->inspect($data, $url);

$rdfXml = array();
foreach ($stylesheets as $stylesheet) {
$rdfXml[] = $grddl->transform($stylesheet, $data);
}

$result = array_reduce($rdfXml, array($grddl, 'merge'));

print $result;



The result? 80 or so triples come out describing everything from the facebook account of the store; the geolocation; the address; the telephone; their email; their opening hours and more.

Give it a go yourself:

$ pear install -f XML_GRDDL
$ cd /usr/share/php/doc/XML_GRDDL/docs
$ php bestbuy-rdfa.php | less

No comments: