Skip to content

Commit 074527e

Browse files
committed
Ensure proper context is used when expanding/compacting IRIs.
- If a property-term-scoped context is in use in conjunction with a type-scoped context, then IRIs should be expanded/compacted using the previous context.
1 parent fdb27a0 commit 074527e

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

lib/compact.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,12 @@ api.compactIri = ({
587587
return iri;
588588
}
589589

590+
// if context is from a property term scoped context composed with a
591+
// type-scoped context, then use the previous context instead
592+
if(activeCtx.isPropertyTermScoped && activeCtx.previousContext) {
593+
activeCtx = activeCtx.previousContext;
594+
}
595+
590596
const inverseCtx = activeCtx.getInverse();
591597

592598
// if term is a keyword, it may be compacted to a simple alias

lib/context.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ api.process = ({
7474
if(isPropertyTermScopedContext && activeCtx.previousContext) {
7575
// TODO: consider optimizing to a shallow copy
7676
activeCtx = activeCtx.clone();
77+
activeCtx.isPropertyTermScoped = true;
7778
activeCtx.previousContext = api.process({
7879
activeCtx: activeCtx.previousContext,
7980
localCtx: ctxs,
@@ -734,6 +735,12 @@ function _expandIri(activeCtx, value, relativeTo, localCtx, defined, options) {
734735
api.createTermDefinition(activeCtx, localCtx, value, defined, options);
735736
}
736737

738+
// if context is from a property term scoped context composed with a
739+
// type-scoped context, then use previous context instead
740+
if(activeCtx.isPropertyTermScoped && activeCtx.previousContext) {
741+
activeCtx = activeCtx.previousContext;
742+
}
743+
737744
relativeTo = relativeTo || {};
738745
if(relativeTo.vocab) {
739746
const mapping = activeCtx.mappings.get(value);
@@ -989,6 +996,7 @@ api.getInitialContext = options => {
989996
child.getInverse = this.getInverse;
990997
child.protected = util.clone(this.protected);
991998
if(this.previousContext) {
999+
child.isPropertyTermScoped = this.previousContext.isPropertyTermScoped;
9921000
child.previousContext = this.previousContext.clone();
9931001
}
9941002
child.revertTypeScopedContext = this.revertTypeScopedContext;

0 commit comments

Comments
 (0)