From fbfb6c9fcbd15cbb249a4ae1a9c45dd637615443 Mon Sep 17 00:00:00 2001 From: Dave Longley Date: Fri, 15 Feb 2013 12:44:00 -0500 Subject: [PATCH] Do not compact to relative IRIs if vocab relative flag is true. --- jsonld.php | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/jsonld.php b/jsonld.php index b29dc14..bd067d7 100644 --- a/jsonld.php +++ b/jsonld.php @@ -3944,21 +3944,26 @@ class JsonLdProcessor { } // no matching terms or curies, use @vocab if available - if(isset($relative_to['vocab']) && $relative_to['vocab'] && - property_exists($active_ctx, '@vocab')) { - // determine if vocab is a prefix of the iri - $vocab = $active_ctx->{'@vocab'}; - if(strpos($iri, $vocab) === 0 && $iri !== $vocab) { - // use suffix as relative iri if it is not a term in the active context - $suffix = substr($iri, strlen($vocab)); - if(!property_exists($active_ctx->mappings, $suffix)) { - return $suffix; + if(isset($relative_to['vocab']) && $relative_to['vocab']) { + if(property_exists($active_ctx, '@vocab')) { + // determine if vocab is a prefix of the iri + $vocab = $active_ctx->{'@vocab'}; + if(strpos($iri, $vocab) === 0 && $iri !== $vocab) { + // use suffix as relative iri if it is not a term in the active context + $suffix = substr($iri, strlen($vocab)); + if(!property_exists($active_ctx->mappings, $suffix)) { + return $suffix; + } } } } - // compact IRI relative to base - return jsonld_remove_base($active_ctx->{'@base'}, $iri); + else { + return jsonld_remove_base($active_ctx->{'@base'}, $iri); + } + + // return IRI as is + return $iri; } /**