1

How can I parse RDF content (in the Turtle serialization) using EasyRDF? For instance, something like this:

$rdf  = '<subject>  <predicate>  "object0"@en .' ;
$rdf .= "\n" ;
$rdf .= '<subject>  <predicate>  "object1"@en .' ;
$array = turtle_decode(rdf) ;
if ($array["subject"]["predicate"][0]["value"]=="object0")
Stanislav Kralin
  • 11,070
  • 4
  • 35
  • 58
Dani-Br
  • 2,289
  • 5
  • 25
  • 32
  • This function has a wrong description. – Dani-Br Jul 01 '15 at 17:00
  • Citation: `public integer parse(object $graph, string $data, string $format, string $baseUri)` But it doesn't expect object as first parameter, and notify about some strange error. – Dani-Br Jul 01 '15 at 17:02
  • 1
    you're citing a different one than what I linked to. I linked to one with a description: *`public integer parse(string $data, string $format = null, string $uri = null)` Parse some RDF data into the graph object.* ** That looks like it should read RDF content from the string in whatever format you specify, and probably using the uri as the base URI, if needed. – Joshua Taylor Jul 01 '15 at 17:32

1 Answers1

1

Using PHP and EasyRDF:

<?php
require 'vendor/autoload.php';

$data  = '<http://rdf.freebase.com/ns/g.11vjz1ynm> <http://rdf.freebase.com/ns/measurement_unit.dated_percentage.date> "2001-02"^^<http://www.w3.org/2001/XMLSchema#gYearMonth>  .' .PHP_EOL;
$data .= '<http://rdf.freebase.com/ns/g.11vjz1ynm>  <http://rdf.freebase.com/ns/measurement_unit.dated_percentage.source> <http://rdf.freebase.com/ns/g.11x1gf2m6>  .' .PHP_EOL;
$data .= '<http://rdf.freebase.com/ns/g.11vjz1ynm>  <http://rdf.freebase.com/ns/type.object.type> <http://rdf.freebase.com/ns/measurement_unit.dated_percentage>  .' .PHP_EOL;
$data .= '<http://rdf.freebase.com/ns/g.11vjz1ynm>  <http://rdf.freebase.com/ns/measurement_unit.dated_percentage.rate> 4.5 .' .PHP_EOL;
$data .= '<http://rdf.freebase.com/ns/g.11vjz1ynm>  <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://rdf.freebase.com/ns/measurement_unit.dated_percentage>  .' .PHP_EOL;

$graph = new EasyRdf_Graph();
$graph->parse($data,'turtle');
$array = $graph->toRdfPhp();
unset($graph);

print_r($array);
Dani-Br
  • 2,289
  • 5
  • 25
  • 32
  • While I still think that the answer was easy enough to find in the documentation that this question probably doesn't need to be on Stack Overflow, this is a reasonably good answer that contains full working code. Be sure to [accept it](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) after the time limit. – Joshua Taylor Jul 02 '15 at 13:46