Skip to content

Commit ee9a13b

Browse files
committed
Update container prioritization in compactIri.
1 parent 9308adf commit ee9a13b

File tree

1 file changed

+29
-13
lines changed

1 file changed

+29
-13
lines changed

lib/compact.js

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -471,23 +471,32 @@ api.compactIri = ({
471471

472472
// prefer @index if available in value
473473
const containers = [];
474-
if(_isObject(value) && '@index' in value) {
475-
containers.push('@index');
474+
if(_isObject(value) && '@index' in value && !('@graph' in value)) {
475+
containers.push('@index', '@index@set');
476476
}
477477

478478
// prefer most specific container including @graph, prefering @set variations
479479
if(_isGraph(value)) {
480-
containers.push('@graph@index@set');
481-
containers.push('@graph@index');
482-
containers.push('@graph@id@set');
483-
containers.push('@graph@id');
484-
containers.push('@graph@set');
485-
containers.push('@graph');
480+
// favor indexmap if the graph is indexed
481+
if('@index' in value) {
482+
containers.push('@graph@index', '@graph@index@set', '@index', '@index@set');
483+
}
484+
// favor idmap if the graph is has an @id
485+
if('@id' in value) {
486+
containers.push(
487+
'@graph@id', '@graph@id@set');
488+
}
489+
containers.push('@graph', '@graph@set');
490+
// allow indexmap if the graph is not indexed
491+
if(!('@index' in value)) {
492+
containers.push('@graph@index', '@graph@index@set', '@index', '@index@set');
493+
}
494+
// allow idmap if the graph does not have an @id
495+
if(!('@id' in value)) {
496+
containers.push('@graph@id', '@graph@id@set');
497+
}
486498
} else if(_isObject(value) && !_isValue(value)) {
487-
containers.push('@id@set');
488-
containers.push('@id');
489-
containers.push('@type@set');
490-
containers.push('@type');
499+
containers.push('@id', '@id@set', '@type','@set@type');
491500
}
492501

493502
// defaults for term selection based on type/language
@@ -557,16 +566,23 @@ api.compactIri = ({
557566
} else {
558567
if(_isValue(value)) {
559568
if('@language' in value && !('@index' in value)) {
560-
containers.push('@language');
569+
containers.push('@language', '@language@set');
561570
typeOrLanguageValue = value['@language'];
562571
} else if('@type' in value) {
563572
typeOrLanguage = '@type';
564573
typeOrLanguageValue = value['@type'];
574+
} else if(!('@index' in value)) {
575+
// allw indexing by language even if no language present
576+
containers.push('@language', '@language@set');
565577
}
566578
} else {
567579
typeOrLanguage = '@type';
568580
typeOrLanguageValue = '@id';
569581
}
582+
if(_isObject(value) && !('@index' in value)) {
583+
// allow indexing even if no @index present
584+
containers.push('@index', '@index@set');
585+
}
570586
containers.push('@set');
571587
}
572588

0 commit comments

Comments
 (0)