From 599e507bcc4cb8e0375ad0c2f04d6bc7bc12eac9 Mon Sep 17 00:00:00 2001 From: Dave Longley Date: Mon, 25 Jun 2012 00:00:56 -0400 Subject: [PATCH] Use available aliases for @value, @language when compacting. --- jsonld.php | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/jsonld.php b/jsonld.php index 4391789..290d6e2 100644 --- a/jsonld.php +++ b/jsonld.php @@ -1160,8 +1160,10 @@ class JsonLdProcessor { if(!property_exists($ctx, '@language')) { return $element->{'@value'}; } - // return full element - return $element; + // return full element, alias @value + $rval = new stdClass(); + $rval->{$this->_compactIri($ctx, '@value')} = $element->{'@value'}; + return $rval; } // get type and language context rules @@ -1171,19 +1173,29 @@ class JsonLdProcessor { // matching @type specified in context, compact element if($type !== null && property_exists($element, '@type') && $element->{'@type'} === $type) { - $element = $element->{'@value'}; + return $element->{'@value'}; } // matching @language specified in context, compact element else if($language !== null && property_exists($element, '@language') && $element->{'@language'} === $language) { - $element = $element->{'@value'}; + return $element->{'@value'}; } - // compact @type IRI - else if(property_exists($element, '@type')) { - $element->{'@type'} = $this->_compactIri($ctx, $element->{'@type'}); + else { + $rval = new stdClass(); + // compact @type IRI + if(property_exists($element, '@type')) { + $rval->{$this->_compactIri($ctx, '@type')} = + $this->_compactIri($ctx, $element->{'@type'}); + } + // alias @language + else if(property_exists($element, '@language')) { + $rval->{$this->_compactIri($ctx, '@language')} = + $element->{'@language'}; + } + $rval->{$this->_compactIri($ctx, '@value')} = $element->{'@value'}; + return $rval; } - return $element; } // compact subject references