forked from semsol/arc2
-
Notifications
You must be signed in to change notification settings - Fork 0
Turtle Templates
semsol edited this page Mar 14, 2011
·
1 revision
ARC's Turtle Parser was derived from the SPARQL grammar parser. As a handy side-effect, it now supports variables in triple patterns. This functionality can be used to dynamically generate RDF graphs via template-like Turtle documents and value arrays that can be created separately, e.g. via submitted forms:
$template = '
?res a rss:item ;
dc:title ?title ;
rss:link ?link ;
dc:creator ?creator ;
rss:description ?description ;
dc:date ?now .
';
$vals = $_POST;
$vals['link'] = $vals['res'];
$vals['now'] = date('Y-m-d', time());
$obj = ARC2::getComponent('Class'); /* any component will do */
$index = $obj->getFilledTemplate($template, $vals);
$turtle = $obj->toTurtle($index);
ARC auto-detects the different value types and creates triples accordingly. If the type is not obvious (e.g. the rss:link URL values are usually serialized as literals), a typing hint can be passed with the value array:
$vals['link type'] = 'literal'; /* space + "type" */