Fix bug when renaming @type blank nodes when flattening.

This commit is contained in:
Dave Longley 2013-03-28 12:12:13 -04:00
parent b3d8b564d0
commit 63a59e63a8

View file

@ -1,7 +1,7 @@
<?php <?php
/** /**
* PHP implementation of the JSON-LD API. * PHP implementation of the JSON-LD API.
* Version: 0.0.18 * Version: 0.0.19
* *
* @author Dave Longley * @author Dave Longley
* *
@ -3182,20 +3182,18 @@ class JsonLdProcessor {
return; return;
} }
// add entries for @type // add values to list
if(property_exists($input, '@type')) { if(self::_isValue($input)) {
$types = $input->{'@type'}; if(property_exists($input, '@type')) {
$types = self::arrayify($types); $type = $input->{'@type'};
foreach($types as $type) { // rename @type blank node
$id = (strpos($type, '_:') === 0) ? $namer->getName($type) : $type; if(strpos($type, '_:') === 0) {
if(!property_exists($graphs->{$graph}, $id)) { $type = $input->{'@type'} = $namer->getName($type);
$graphs->{$graph}->{$id} = (object)array('@id' => $id); }
if(!property_exists($graphs->{$graph}, $type)) {
$graphs->{$graph}->{$type} = (object)array('@id' => $type);
} }
} }
}
// add add values to list
if(self::_isValue($input)) {
if($list !== null) { if($list !== null) {
$list[] = $input; $list[] = $input;
} }
@ -3283,6 +3281,14 @@ class JsonLdProcessor {
continue; continue;
} }
foreach($objects as $o) { foreach($objects as $o) {
if($property === '@type') {
// rename @type blank nodes
$o = (strpos($o, '_:') === 0) ? $namer->getName($o) : $o;
if(!property_exists($graphs->{$graph}, $o)) {
$graphs->{$graph}->{$o} = (object)array('@id' => $o);
}
}
// handle embedded subject or subject reference // handle embedded subject or subject reference
if(self::_isSubject($o) || self::_isSubjectReference($o)) { if(self::_isSubject($o) || self::_isSubjectReference($o)) {
// rename blank node @id // rename blank node @id