-
Notifications
You must be signed in to change notification settings - Fork 90
Turtle Templates
megaplanet edited this page Feb 29, 2012
·
2 revisions
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',$config); /* any component will do */
$index = $obj->getFilledTemplate($template, $vals);
$turtle = $obj->toTurtle($index);
Note that the configuration must contains the prefixes used in the template (in the example above 'rss' and 'dcc' should be defined in $config).
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" */