Skip to content

Commit 07e9c06

Browse files
committed
Add optimization for compacting keywords.
1 parent 3423f20 commit 07e9c06

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

js/jsonld.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5446,13 +5446,18 @@ function _compactIri(activeCtx, iri, value, relativeTo, reverse) {
54465446
}
54475447
relativeTo = relativeTo || {};
54485448

5449-
// if term is a keyword, default vocab to true
5449+
var inverseCtx = activeCtx.getInverse();
5450+
5451+
// if term is a keyword, it can only be compacted to a simple alias
54505452
if(_isKeyword(iri)) {
5451-
relativeTo.vocab = true;
5453+
if(iri in inverseCtx) {
5454+
return inverseCtx[iri]['@none']['@type']['@none'];
5455+
}
5456+
return iri;
54525457
}
54535458

54545459
// use inverse context to pick a term if iri is relative to vocab
5455-
if(relativeTo.vocab && iri in activeCtx.getInverse()) {
5460+
if(relativeTo.vocab && iri in inverseCtx) {
54565461
var defaultLanguage = activeCtx['@language'] || '@none';
54575462

54585463
// prefer @index if available in value

0 commit comments

Comments
 (0)