Skip to content

Commit 956fb8b

Browse files
committed
Add optimization for compacting keywords.
1 parent 81b072b commit 956fb8b

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

jsonld.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4569,16 +4569,22 @@ protected function _compactIri(
45694569
return $iri;
45704570
}
45714571

4572-
// term is a keyword, default vocab to true
4572+
$inverse_ctx = $this->_getInverseContext($active_ctx);
4573+
45734574
if(self::_isKeyword($iri)) {
4574-
$relative_to['vocab'] = true;
4575-
} else if(!isset($relative_to['vocab'])) {
4575+
// a keyword can only be compacted to simple alias
4576+
if(property_exists($inverse_ctx, $iri)) {
4577+
return $inverse_ctx->$iri->{'@none'}->{'@type'}->{'@none'};
4578+
}
4579+
return $iri;
4580+
}
4581+
4582+
if(!isset($relative_to['vocab'])) {
45764583
$relative_to['vocab'] = false;
45774584
}
45784585

45794586
// use inverse context to pick a term if iri is relative to vocab
4580-
if($relative_to['vocab'] &&
4581-
property_exists($this->_getInverseContext($active_ctx), $iri)) {
4587+
if($relative_to['vocab'] && property_exists($inverse_ctx, $iri)) {
45824588
$default_language = '@none';
45834589
if(property_exists($active_ctx, '@language')) {
45844590
$default_language = $active_ctx->{'@language'};

0 commit comments

Comments
 (0)