Ensure named graph blank node IDs are relabeled.

This commit is contained in:
Dave Longley 2013-02-15 14:04:29 -05:00
parent fbfb6c9fcb
commit bea64fee03
1 changed files with 13 additions and 10 deletions

View File

@ -1346,7 +1346,7 @@ class JsonLdProcessor {
* Converts an RDF statement to an N-Quad string (a single quad). * Converts an RDF statement to an N-Quad string (a single quad).
* *
* @param stdClass $statement the RDF statement to convert. * @param stdClass $statement the RDF statement to convert.
* @param string $bnode the bnode the staetment is mapped to (optional, for * @param string $bnode the bnode the statement is mapped to (optional, for
* use during normalization only). * use during normalization only).
* *
* @return the N-Quad string. * @return the N-Quad string.
@ -1409,11 +1409,11 @@ class JsonLdProcessor {
if($g->interfaceName === 'IRI') { if($g->interfaceName === 'IRI') {
$quad .= " <{$g->nominalValue}>"; $quad .= " <{$g->nominalValue}>";
} }
else if(bnode) { else if($bnode) {
$quad += ' _:g'; $quad .= ' _:g';
} }
else { else {
$quad += " {$g->nominalValue}"; $quad .= " {$g->nominalValue}";
} }
} }
@ -2013,7 +2013,7 @@ class JsonLdProcessor {
else { else {
// drop subjects that generate no triples // drop subjects that generate no triples
$has_triples = false; $has_triples = false;
$ignore = array('@graph', '@type', '@list'); $ignore = array('@graph', '@type');
foreach($keys as $key) { foreach($keys as $key) {
if(!self::_isKeyword($key) || in_array($key, $ignore)) { if(!self::_isKeyword($key) || in_array($key, $ignore)) {
$has_triples = true; $has_triples = true;
@ -2132,9 +2132,10 @@ class JsonLdProcessor {
$namer = new UniqueNamer('_:t'); $namer = new UniqueNamer('_:t');
$this->_toRDF($input, $namer, null, null, null, $statements); $this->_toRDF($input, $namer, null, null, null, $statements);
foreach($statements as $statement) { foreach($statements as $statement) {
foreach(array('subject', 'object') as $node) { foreach(array('subject', 'object', 'name') as $node) {
$id = $statement->{$node}->nominalValue; if(property_exists($statement, $node) &&
if($statement->{$node}->interfaceName === 'BlankNode') { $statement->{$node}->interfaceName === 'BlankNode') {
$id = $statement->{$node}->nominalValue;
if(property_exists($bnodes, $id)) { if(property_exists($bnodes, $id)) {
$bnodes->{$id}->statements[] = $statement; $bnodes->{$id}->statements[] = $statement;
} }
@ -2224,8 +2225,10 @@ class JsonLdProcessor {
// update bnode names in each statement and serialize // update bnode names in each statement and serialize
foreach($statements as $statement) { foreach($statements as $statement) {
foreach(array('subject', 'object') as $node) { foreach(array('subject', 'object', 'name') as $node) {
if($statement->{$node}->interfaceName === 'BlankNode') { if(property_exists($statement, $node) &&
$statement->{$node}->interfaceName === 'BlankNode' &&
strpos($statement->{$node}->nominalValue, '_:c14n') !== 0) {
$statement->{$node}->nominalValue = $namer->getName( $statement->{$node}->nominalValue = $namer->getName(
$statement->{$node}->nominalValue); $statement->{$node}->nominalValue);
} }