Skip to content

Commit 5bb6924

Browse files
committed
Update container prioritization in compactIri.
1 parent 3d550c8 commit 5bb6924

File tree

2 files changed

+31
-15
lines changed

2 files changed

+31
-15
lines changed

lib/compact.js

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

487487
// prefer @index if available in value
488488
const containers = [];
489-
if(_isObject(value) && '@index' in value) {
490-
containers.push('@index');
489+
if(_isObject(value) && '@index' in value && !('@graph' in value)) {
490+
containers.push('@index', '@index@set');
491491
}
492492

493493
// prefer most specific container including @graph, prefering @set variations
494494
if(_isGraph(value)) {
495-
containers.push('@graph@index@set');
496-
containers.push('@graph@index');
497-
containers.push('@graph@id@set');
498-
containers.push('@graph@id');
499-
containers.push('@graph@set');
500-
containers.push('@graph');
495+
// favor indexmap if the graph is indexed
496+
if('@index' in value) {
497+
containers.push('@graph@index', '@graph@index@set', '@index', '@index@set');
498+
}
499+
// favor idmap if the graph is has an @id
500+
if('@id' in value) {
501+
containers.push(
502+
'@graph@id', '@graph@id@set');
503+
}
504+
containers.push('@graph', '@graph@set');
505+
// allow indexmap if the graph is not indexed
506+
if(!('@index' in value)) {
507+
containers.push('@graph@index', '@graph@index@set', '@index', '@index@set');
508+
}
509+
// allow idmap if the graph does not have an @id
510+
if(!('@id' in value)) {
511+
containers.push('@graph@id', '@graph@id@set');
512+
}
501513
} else if(_isObject(value) && !_isValue(value)) {
502-
containers.push('@id@set');
503-
containers.push('@id');
504-
containers.push('@type@set');
505-
containers.push('@type');
514+
containers.push('@id', '@id@set', '@type','@set@type');
506515
}
507516

508517
// defaults for term selection based on type/language
@@ -572,16 +581,23 @@ api.compactIri = ({
572581
} else {
573582
if(_isValue(value)) {
574583
if('@language' in value && !('@index' in value)) {
575-
containers.push('@language');
584+
containers.push('@language', '@language@set');
576585
typeOrLanguageValue = value['@language'];
577586
} else if('@type' in value) {
578587
typeOrLanguage = '@type';
579588
typeOrLanguageValue = value['@type'];
589+
} else if(!('@index' in value)) {
590+
// allw indexing by language even if no language present
591+
containers.push('@language', '@language@set');
580592
}
581593
} else {
582594
typeOrLanguage = '@type';
583595
typeOrLanguageValue = '@id';
584596
}
597+
if(_isObject(value) && !('@index' in value)) {
598+
// allow indexing even if no @index present
599+
containers.push('@index', '@index@set');
600+
}
585601
containers.push('@set');
586602
}
587603

tests/test-common.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const manifest = options.manifest || {
2929
const TEST_TYPES = {
3030
'jld:CompactTest': {
3131
skip: {
32-
regex: [/#t0073/, /#t[anps]/
32+
regex: [/#t0073/, /#t[anps]/]
3333
},
3434
fn: 'compact',
3535
params: [
@@ -41,7 +41,7 @@ const TEST_TYPES = {
4141
},
4242
'jld:ExpandTest': {
4343
skip: {
44-
regex: [/#t[n]/]
44+
regex: [/#t[n]/, /#tm013/]
4545
},
4646
fn: 'expand',
4747
params: [

0 commit comments

Comments
 (0)