-
Notifications
You must be signed in to change notification settings - Fork 202
Remove shortcut from compactIri when iri is a keyword #218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -160,7 +160,7 @@ api.compact = ({ | |
} | ||
|
||
// use keyword alias and add value | ||
const alias = api.compactIri({activeCtx, iri: expandedProperty}); | ||
const alias = api.compactIri({activeCtx, iri: expandedProperty, relativeTo: {vocab: true}}); | ||
const isArray = _isArray(compactedValue) && expandedValue.length === 0; | ||
_addValue(rval, alias, compactedValue, {propertyIsArray: isArray}); | ||
continue; | ||
|
@@ -194,7 +194,7 @@ api.compact = ({ | |
|
||
if(Object.keys(compactedValue).length > 0) { | ||
// use keyword alias and add value | ||
const alias = api.compactIri({activeCtx, iri: expandedProperty}); | ||
const alias = api.compactIri({activeCtx, iri: expandedProperty, relativeTo: {vocab: true}}); | ||
_addValue(rval, alias, compactedValue); | ||
} | ||
|
||
|
@@ -211,7 +211,7 @@ api.compact = ({ | |
} | ||
|
||
// use keyword alias and add value | ||
const alias = api.compactIri({activeCtx, iri: expandedProperty}); | ||
const alias = api.compactIri({activeCtx, iri: expandedProperty, relativeTo: {vocab: true}}); | ||
_addValue(rval, alias, expandedValue); | ||
continue; | ||
} | ||
|
@@ -220,7 +220,7 @@ api.compact = ({ | |
if(expandedProperty !== '@graph' && expandedProperty !== '@list' && | ||
_isKeyword(expandedProperty)) { | ||
// use keyword alias and add value as is | ||
const alias = api.compactIri({activeCtx, iri: expandedProperty}); | ||
const alias = api.compactIri({activeCtx, iri: expandedProperty, relativeTo: {vocab: true}}); | ||
_addValue(rval, alias, expandedValue); | ||
continue; | ||
} | ||
|
@@ -289,12 +289,12 @@ api.compact = ({ | |
if(!container.includes('@list')) { | ||
// wrap using @list alias | ||
compactedItem = { | ||
[api.compactIri({activeCtx, iri: '@list'})]: compactedItem | ||
[api.compactIri({activeCtx, iri: '@list', relativeTo: {vocab: true}})]: compactedItem | ||
}; | ||
|
||
// include @index from expanded @list, if any | ||
if('@index' in expandedItem) { | ||
compactedItem[api.compactIri({activeCtx, iri: '@index'})] = | ||
compactedItem[api.compactIri({activeCtx, iri: '@index', relativeTo: {vocab: true}})] = | ||
expandedItem['@index']; | ||
} | ||
} else if(itemActiveProperty in rval) { | ||
|
@@ -312,12 +312,12 @@ api.compact = ({ | |
if(isSimpleGraph && !container.includes('@graph')) { | ||
// wrap using @graph alias | ||
compactedItem = { | ||
[api.compactIri({activeCtx, iri: '@graph'})]: compactedItem | ||
[api.compactIri({activeCtx, iri: '@graph', relativeTo: {vocab: true}})]: compactedItem | ||
}; | ||
|
||
// include @index from expanded @graph, if any | ||
if('@index' in expandedItem) { | ||
compactedItem[api.compactIri({activeCtx, iri: '@index'})] = | ||
compactedItem[api.compactIri({activeCtx, iri: '@index', relativeTo: {vocab: true}})] = | ||
expandedItem['@index']; | ||
} | ||
} | ||
|
@@ -393,12 +393,13 @@ api.compactIri = ({ | |
|
||
const inverseCtx = activeCtx.getInverse(); | ||
|
||
// if term is a keyword, it can only be compacted to a simple alias | ||
if(_isKeyword(iri)) { | ||
if(iri in inverseCtx) { | ||
return inverseCtx[iri]['@none']['@type']['@none']; | ||
} | ||
return iri; | ||
// if term is a keyword, it can may be compacted to a simple alias | ||
if(_isKeyword(iri) && | ||
iri in inverseCtx && | ||
'@none' in inverseCtx[iri] && | ||
'@type' in inverseCtx[iri]['@none'] && | ||
'@none' in inverseCtx[iri]['@none']['@type']) { | ||
return inverseCtx[iri]['@none']['@type']['@none']; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another option would be to leave this in place, and exit quickly if an |
||
// use inverse context to pick a term if iri is relative to vocab | ||
|
@@ -621,20 +622,20 @@ api.compactValue = ({activeCtx, activeProperty, value}) => { | |
|
||
// preserve @index | ||
if(preserveIndex) { | ||
rval[api.compactIri({activeCtx, iri: '@index'})] = value['@index']; | ||
rval[api.compactIri({activeCtx, iri: '@index', relativeTo: {vocab: true}})] = value['@index']; | ||
} | ||
|
||
if('@type' in value) { | ||
// compact @type IRI | ||
rval[api.compactIri({activeCtx, iri: '@type'})] = api.compactIri( | ||
rval[api.compactIri({activeCtx, iri: '@type', relativeTo: {vocab: true}})] = api.compactIri( | ||
{activeCtx, iri: value['@type'], relativeTo: {vocab: true}}); | ||
} else if('@language' in value) { | ||
// alias @language | ||
rval[api.compactIri({activeCtx, iri: '@language'})] = value['@language']; | ||
rval[api.compactIri({activeCtx, iri: '@language', relativeTo: {vocab: true}})] = value['@language']; | ||
} | ||
|
||
// alias @value | ||
rval[api.compactIri({activeCtx, iri: '@value'})] = value['@value']; | ||
rval[api.compactIri({activeCtx, iri: '@value', relativeTo: {vocab: true}})] = value['@value']; | ||
|
||
return rval; | ||
} | ||
|
@@ -651,7 +652,7 @@ api.compactValue = ({activeCtx, activeProperty, value}) => { | |
} | ||
|
||
return { | ||
[api.compactIri({activeCtx, iri: '@id'})]: compacted | ||
[api.compactIri({activeCtx, iri: '@id', relativeTo: {vocab: true}})]: compacted | ||
}; | ||
}; | ||
|
||
|
@@ -698,7 +699,7 @@ api.removePreserve = (ctx, input, options) => { | |
} | ||
|
||
// handle in-memory linked nodes | ||
const idAlias = api.compactIri({activeCtx: ctx, iri: '@id'}); | ||
const idAlias = api.compactIri({activeCtx: ctx, iri: '@id', relativeTo: {vocab: true}}); | ||
if(idAlias in input) { | ||
const id = input[idAlias]; | ||
if(id in options.link) { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type:
it can may be
=>it may be compacted