Skip to content

More support for "@type": "@none" #350

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 3 commits into from
Jan 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# jsonld ChangeLog

### Fixed
- More support for "@type": "@none"

## 2.0.1 - 2019-12-10

### Fixed
Expand Down
9 changes: 4 additions & 5 deletions lib/compact.js
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,7 @@ api.compactValue = ({activeCtx, activeProperty, value, options}) => {
const preserveIndex = '@index' in value && !container.includes('@index');

// if there's no @index to preserve ...
if(!preserveIndex) {
if(!preserveIndex && type !== '@none') {
// matching @type or @language specified in context, compact value
if(value['@type'] === type || value['@language'] === language) {
return value['@value'];
Expand All @@ -971,6 +971,7 @@ api.compactValue = ({activeCtx, activeProperty, value, options}) => {
const hasNullMapping = (activeCtx.mappings.has(activeProperty) &&
activeCtx.mappings.get(activeProperty)['@language'] === null);
if(isValueOnlyKey &&
type !== '@none' &&
(!hasDefaultLanguage || !isValueString || hasNullMapping)) {
return value['@value'];
}
Expand Down Expand Up @@ -1169,17 +1170,15 @@ function _selectTerm(
prefs.push('@none');

const containerMap = activeCtx.inverse[iri];
for(let ci = 0; ci < containers.length; ++ci) {
for(const container of containers) {
// if container not available in the map, continue
const container = containers[ci];
if(!(container in containerMap)) {
continue;
}

const typeOrLanguageValueMap = containerMap[container][typeOrLanguage];
for(let pi = 0; pi < prefs.length; ++pi) {
for(const pref of prefs) {
// if type/language option not available in the map, continue
const pref = prefs[pi];
if(!(pref in typeOrLanguageValueMap)) {
continue;
}
Expand Down
14 changes: 13 additions & 1 deletion lib/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,15 @@ api.createTermDefinition = ({
{code: 'invalid type mapping', context: localCtx});
}

if(type !== '@id' && type !== '@vocab' && type !== '@json') {
if((type === '@json' || type === '@none')) {
if(api.processingMode(activeCtx, 1.0)) {
throw new JsonLdError(
'Invalid JSON-LD syntax; an @context @type value must not be ' +
`"${type}" in JSON-LD 1.0 mode.`,
'jsonld.SyntaxError',
{code: 'invalid type mapping', context: localCtx});
}
} else if(type !== '@id' && type !== '@vocab') {
// expand @type to full IRI
type = _expandIri(
activeCtx, type, {vocab: true, base: false}, localCtx, defined,
Expand Down Expand Up @@ -959,6 +967,10 @@ api.getInitialContext = options => {
if(mapping.reverse) {
// term is preferred for values using @reverse
_addPreferredTerm(term, entry['@type'], '@reverse');
} else if(mapping['@type'] === '@none') {
_addPreferredTerm(term, entry['@any'], '@none');
_addPreferredTerm(term, entry['@language'], '@none');
_addPreferredTerm(term, entry['@type'], '@none');
} else if('@type' in mapping) {
// term is preferred for values using specific type
_addPreferredTerm(term, entry['@type'], mapping['@type']);
Expand Down
2 changes: 1 addition & 1 deletion lib/expand.js
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,7 @@ function _expandValue({activeCtx, activeProperty, value, options}) {

const rval = {};

if(type && !['@id', '@vocab'].includes(type)) {
if(type && !['@id', '@vocab', '@none'].includes(type)) {
// other type
rval['@type'] = type;
} else if(_isString(value)) {
Expand Down
8 changes: 0 additions & 8 deletions tests/test-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ const TEST_TYPES = {
specVersion: ['json-ld-1.0'],
// FIXME
idRegex: [
// @type: @none
/compact-manifest.jsonld#ttn01$/,
/compact-manifest.jsonld#ttn02$/,
/compact-manifest.jsonld#ttn03$/,
// included
/compact-manifest.jsonld#tin01$/,
/compact-manifest.jsonld#tin02$/,
Expand Down Expand Up @@ -106,8 +102,6 @@ const TEST_TYPES = {
/expand-manifest.jsonld#thc03$/,
/expand-manifest.jsonld#thc04$/,
/expand-manifest.jsonld#thc05$/,
// @type: @none
/expand-manifest.jsonld#ttn02$/,
// misc
/expand-manifest.jsonld#te043$/,
/expand-manifest.jsonld#te044$/,
Expand Down Expand Up @@ -404,8 +398,6 @@ const TEST_TYPES = {
/toRdf-manifest.jsonld#tso08$/,
/toRdf-manifest.jsonld#tso10$/,
/toRdf-manifest.jsonld#tso11$/,
// type:none
/toRdf-manifest.jsonld#ttn02$/,
// colliding keyword
/toRdf-manifest.jsonld#te114$/,
// included
Expand Down