-
Notifications
You must be signed in to change notification settings - Fork 89
Parsing RDF Formats
semsol edited this page Mar 11, 2011
·
2 revisions
ARC2 comes with a built-in RDF format detector for convenient parsing. You can instantiate the generic RDF parser and let ARC detect RDF/XML, Turtle, N-Triples, RSS 2.0, SPOG (constrained SPARQL XML results), Google's Social Graph API JSON, or HTML:
$parser = ARC2::getRDFParser();
You can also access a specific parser directly:
$parser = ARC2::getRDFXMLParser();
or
$parser = ARC2::getTurtleParser();
$parser->parse('http://example.com/foaf.rdf');
$parser->parse('data/foaf.ttl');
$base = 'http://example.com/';
$data = '<rdf:RDF ...>...</rdf:RDF>';
$parser->parse($base, $data);
$triples = $parser->getTriples();
$index = $parser->getSimpleIndex();
This method will by default flatten the object values. To keep object type / datatype / language information, you can use
$index = $parser->getSimpleIndex(0);
See also: Internal Structures