如何使用EasyRDF解析RDF内容(在Turtle序列化中)?例如,像这样:
$rdf = '<subject> <predicate> "object0"@en .' ;
$rdf .= "\n" ;
$rdf .= '<subject> <predicate> "object1"@en .' ;
$array = turtle_decode(rdf) ;
if ($array["subject"]["predicate"][0]["value"]=="object0")
答案 0 :(得分:1)
使用PHP和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);