Add optimization for compacting keywords.

This commit is contained in:
Dave Longley 2016-04-24 17:01:42 -04:00
parent 81b072b438
commit 956fb8b790

View file

@ -4569,16 +4569,22 @@ class JsonLdProcessor {
return $iri; return $iri;
} }
// term is a keyword, default vocab to true $inverse_ctx = $this->_getInverseContext($active_ctx);
if(self::_isKeyword($iri)) { if(self::_isKeyword($iri)) {
$relative_to['vocab'] = true; // a keyword can only be compacted to simple alias
} else if(!isset($relative_to['vocab'])) { if(property_exists($inverse_ctx, $iri)) {
return $inverse_ctx->$iri->{'@none'}->{'@type'}->{'@none'};
}
return $iri;
}
if(!isset($relative_to['vocab'])) {
$relative_to['vocab'] = false; $relative_to['vocab'] = false;
} }
// use inverse context to pick a term if iri is relative to vocab // use inverse context to pick a term if iri is relative to vocab
if($relative_to['vocab'] && if($relative_to['vocab'] && property_exists($inverse_ctx, $iri)) {
property_exists($this->_getInverseContext($active_ctx), $iri)) {
$default_language = '@none'; $default_language = '@none';
if(property_exists($active_ctx, '@language')) { if(property_exists($active_ctx, '@language')) {
$default_language = $active_ctx->{'@language'}; $default_language = $active_ctx->{'@language'};