Skip to content

Commit

Permalink
Fix use of @vocab in custom vocabulary JSON-LD
Browse files Browse the repository at this point in the history
  • Loading branch information
pheyvaer committed Nov 3, 2021
1 parent bd50bc5 commit 2d1486d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## Unreleased

## [1.0.2] - 2021-11-03

### Fixed
- Use of @vocab in custom vocabulary JSON-LD

## [1.0.1] - 2021-11-03

### Fixed
- Add customBaseIri to shapes JSON-LD context


[1.0.2]: https://github.com/KNowledgeOnWebScale/merweb/compare/v1.0.1...v1.0.2
[1.0.1]: https://github.com/KNowledgeOnWebScale/merweb/compare/v1.0.0...v1.0.1
17 changes: 9 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,15 @@ function main(input, options) {

const finalCustomVocab = {
'@context': {
'@vocab': customBaseIri.iri,
'@vocab': 'http://www.w3.org/2000/01/rdf-schema#',
schema: 'https://schema.org/',
rdfs: 'http://www.w3.org/2000/01/rdf-schema#',
rdf: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
},
'@graph': customVocab
};

finalCustomVocab['@context'][customBaseIri.prefix] = customBaseIri.iri;

return {shapes: finalShapes, customVocab: finalCustomVocab};
} else {
return {shapes: finalShapes};
Expand All @@ -102,11 +103,11 @@ function parseMembers(options) {
idToType[id] = split[1];

if (customBaseIri && split[1].startsWith(customBaseIri.prefix + ':')) {
latestCustomVocabElementId = split[1].replace(customBaseIri.prefix + ':', '');
latestCustomVocabElementId = split[1];
customVocab.push({
'@id': latestCustomVocabElementId,
'@type': 'rdfs:Class',
'rdfs:subClassOf': {'@id': 'schema:Thing'}
'@type': 'Class',
'subClassOf': {'@id': 'schema:Thing'}
});
}
} else if (split[0] === '@extraTypes') {
Expand Down Expand Up @@ -134,11 +135,11 @@ function parseMembers(options) {
shape.property.push(property);
} else if (split[0] === '@label') {
if (customBaseIri) {
addAttributeToCustomVocabElement('rdfs:label', member.replace('@label ', ''), latestCustomVocabElementId, customVocab);
addAttributeToCustomVocabElement('label', member.replace('@label ', ''), latestCustomVocabElementId, customVocab);
}
} else if (split[0] === '@comment' && customBaseIri) {
if (customBaseIri) {
addAttributeToCustomVocabElement('rdfs:comment', member.replace('@comment ', ''), latestCustomVocabElementId, customVocab);
addAttributeToCustomVocabElement('comment', member.replace('@comment ', ''), latestCustomVocabElementId, customVocab);
}
} else if (split.length >= 3) {
if (!shape.property) {
Expand Down Expand Up @@ -173,7 +174,7 @@ function parseMembers(options) {
shape.property.push(property);

if (customBaseIri && split[2].startsWith(customBaseIri.prefix + ':')) {
latestCustomVocabElementId = split[2].replace(customBaseIri.prefix + ':', '');
latestCustomVocabElementId = split[2];
customVocab.push({
'@id': latestCustomVocabElementId,
'@type': 'rdf:Property'
Expand Down

0 comments on commit 2d1486d

Please sign in to comment.