@rmlio/yarrrml-parser
Advanced tools
Comparing version 0.1.4 to 0.1.5
@@ -18,2 +18,3 @@ #!/usr/bin/env node | ||
const watch = require('../lib/watcher.js'); | ||
const logger = require('winston'); | ||
@@ -52,3 +53,5 @@ namespaces.ql = 'http://semweb.mmlab.be/ns/ql#'; | ||
rdf: namespaces.rdf, | ||
rdfs: namespaces.rdfs | ||
rdfs: namespaces.rdfs, | ||
fnml: "http://semweb.mmlab.be/ns/fnml#", | ||
fno: "http://w3id.org/function/ontology#" | ||
}; | ||
@@ -120,7 +123,8 @@ | ||
if (e.code === 'ENOENT') { | ||
console.error(`The input file ${program.input} is not found.`); | ||
logger.error(`The input file ${program.input} is not found.`); | ||
} else if (e.code === 'INVALID_YAML') { | ||
console.error(`The input file contains invalid YAML.`); | ||
logger.error(`The input file contains invalid YAML.`); | ||
logger.error(`line ${e.parsedLine}: ${e.message}`); | ||
} else { | ||
console.error(e); | ||
logger.error(e); | ||
} | ||
@@ -127,0 +131,0 @@ } |
@@ -7,2 +7,3 @@ /** | ||
const extend = require('extend'); | ||
const logger = require('winston'); | ||
@@ -39,13 +40,22 @@ const shortcuts = { | ||
mappings.forEach(mappingKey => { | ||
for (let i = 0; i < mappings.length; i ++) { | ||
const mappingKey = mappings[i]; | ||
const mapping = input.mappings[mappingKey]; | ||
expandSubjects(mapping); | ||
expandSourcesInMapping(mapping); | ||
expandPredicateObjects(mapping); | ||
expandGraphs(mapping); | ||
}) | ||
if (mapping) { | ||
expandSubjects(mapping, mappingKey); | ||
expandSourcesInMapping(mapping, mappingKey); | ||
expandPredicateObjects(mapping, mappingKey); | ||
expandGraphs(mapping); | ||
} else { | ||
logger.warn(`mapping ${mappingKey}: no rules are provided. Skipping.`); | ||
delete input.mappings[mappingKey]; | ||
} | ||
} | ||
} else { | ||
logger.warn('A YARRRML document should have at least the key "mappings".'); | ||
} | ||
} | ||
function expandSubjects(mapping) { | ||
function expandSubjects(mapping, mappingKey) { | ||
replaceAll('subjects', mapping); | ||
@@ -57,3 +67,3 @@ | ||
} else if (Array.isArray(mapping.subjects)) { | ||
for (let i = 0; i < mapping.subjects.length; i ++) { | ||
for (let i = 0; i < mapping.subjects.length; i++) { | ||
if (typeof mapping.subjects[i] === 'object') { | ||
@@ -67,7 +77,7 @@ expandFunction(mapping.subjects[i]); | ||
function expandSourcesInMapping(mapping) { | ||
function expandSourcesInMapping(mapping, mappingKey) { | ||
replaceAll('sources', mapping); | ||
if (mapping.sources && Array.isArray(mapping.sources)) { | ||
for (let i = 0; i < mapping.sources.length; i ++) { | ||
for (let i = 0; i < mapping.sources.length; i++) { | ||
const source = mapping.sources[i]; | ||
@@ -79,2 +89,4 @@ | ||
} | ||
} else { | ||
logger.warn(`mapping ${mappingKey}: no source is defined.`); | ||
} | ||
@@ -89,3 +101,3 @@ } | ||
for (let i = 0; i < sourceKeys.length; i ++) { | ||
for (let i = 0; i < sourceKeys.length; i++) { | ||
const source = document.sources[sourceKeys[i]]; | ||
@@ -100,7 +112,7 @@ | ||
function expandPredicateObjects(mapping) { | ||
function expandPredicateObjects(mapping, mappingKey) { | ||
replaceAll('predicateobjects', mapping); | ||
if (mapping.predicateobjects) { | ||
for (let i = 0; i < mapping.predicateobjects.length; i ++) { | ||
for (let i = 0; i < mapping.predicateobjects.length; i++) { | ||
const po = mapping.predicateobjects[i]; | ||
@@ -131,3 +143,5 @@ | ||
expandPredicates(mapping.predicateobjects); | ||
expandObjects(mapping.predicateobjects); | ||
expandObjects(mapping.predicateobjects, mappingKey); | ||
} else { | ||
logger.warn(`mapping ${mappingKey}: no pos are defined.`) | ||
} | ||
@@ -146,4 +160,5 @@ } | ||
function expandObjects(predicateobjects) { | ||
predicateobjects.forEach(po => { | ||
function expandObjects(predicateobjects, mappingKey) { | ||
for (let i = 0; i < predicateobjects.length; i++) { | ||
const po = predicateobjects[i]; | ||
replaceAll('objects', po); | ||
@@ -157,82 +172,88 @@ | ||
for (let j = 0; j < po.objects.length; j ++) { | ||
if (typeof po.objects[j] === 'string') { | ||
if (po.predicates.indexOf('a') === -1 && po.objects[j].indexOf('~iri') === -1) { | ||
po.objects[j] = { | ||
value: po.objects[j], | ||
type: 'literal' | ||
if (!po.objects || po.objects.length === 0) { | ||
logger.warn(`mapping ${mappingKey}: po with predicate(s) "${po.predicates}" does not have an object defined. Skipping.`); | ||
predicateobjects.splice(i, 1); | ||
i --; | ||
} else { | ||
for (let j = 0; j < po.objects.length; j++) { | ||
if (typeof po.objects[j] === 'string') { | ||
if (po.predicates.indexOf('a') === -1 && po.objects[j].indexOf('~iri') === -1) { | ||
po.objects[j] = { | ||
value: po.objects[j], | ||
type: 'literal' | ||
} | ||
} else { | ||
po.objects[j] = { | ||
value: po.objects[j].replace('~iri', ''), | ||
type: 'iri' | ||
} | ||
} | ||
} else { | ||
po.objects[j] = { | ||
value: po.objects[j].replace('~iri', ''), | ||
type: 'iri' | ||
} else if (Array.isArray(po.objects[j])) { | ||
let newPO; | ||
if (po.objects[j][0].indexOf('~iri') === -1) { | ||
newPO = { | ||
value: po.objects[j][0], | ||
type: 'literal' | ||
} | ||
} else { | ||
newPO = { | ||
value: po.objects[j][0].replace('~iri', ''), | ||
type: 'iri' | ||
} | ||
} | ||
} | ||
} else if (Array.isArray(po.objects[j])){ | ||
let newPO; | ||
if (po.objects[j][0].indexOf('~iri') === -1) { | ||
newPO = { | ||
value: po.objects[j][0], | ||
type: 'literal' | ||
if (po.objects[j].length > 1) { | ||
if (po.objects[j][1].indexOf('~lang') === -1) { | ||
newPO.datatype = po.objects[j][1]; | ||
} else { | ||
newPO.language = po.objects[j][1].replace('~lang', ''); | ||
} | ||
} | ||
} else { | ||
newPO = { | ||
value: po.objects[j][0].replace('~iri', ''), | ||
type: 'iri' | ||
} | ||
po.objects[j] = newPO; | ||
} | ||
if (po.objects[j].length > 1) { | ||
if (po.objects[j][1].indexOf('~lang') === -1) { | ||
newPO.datatype = po.objects[j][1]; | ||
} else { | ||
newPO.language = po.objects[j][1].replace('~lang', ''); | ||
} | ||
if (!po.objects[j].datatype && po.datatype) { | ||
po.objects[j].datatype = po.datatype; | ||
} | ||
po.objects[j] = newPO; | ||
} | ||
if (!po.objects[j].language && po.language) { | ||
po.objects[j].language = po.language; | ||
} | ||
if (!po.objects[j].datatype && po.datatype) { | ||
po.objects[j].datatype = po.datatype; | ||
} | ||
replaceAll('value', po.objects[j]); | ||
replaceAll('inversepredicates', po.objects[j]); | ||
if (!po.objects[j].language && po.language) { | ||
po.objects[j].language = po.language; | ||
} | ||
expandFunction(po.objects[j]); | ||
replaceAll('value', po.objects[j]); | ||
replaceAll('inversepredicates', po.objects[j]); | ||
expandFunction(po.objects[j]); | ||
//condition | ||
replaceAll('conditions', po.objects[j]); | ||
if (po.objects[j].conditions) { | ||
//condition | ||
replaceAll('conditions', po.objects[j]); | ||
if (typeof po.objects[j].conditions === 'object' && !Array.isArray(po.objects[j].conditions)) { | ||
po.objects[j].conditions = [po.objects[j].conditions]; | ||
} | ||
if (po.objects[j].conditions) { | ||
po.objects[j].conditions.forEach(c => { | ||
expandFunction(c); | ||
}); | ||
} | ||
if (typeof po.objects[j].conditions === 'object' && !Array.isArray(po.objects[j].conditions)) { | ||
po.objects[j].conditions = [po.objects[j].conditions]; | ||
if (po.objects[j].mapping && Array.isArray(po.objects[j].mapping)) { | ||
po.objects[j].mapping.forEach(m => { | ||
const anotherObject = JSON.parse(JSON.stringify(po.objects[j])); | ||
anotherObject.mapping = m; | ||
po.objects.push(anotherObject); | ||
}); | ||
po.objects.splice(j, 1); | ||
} | ||
po.objects[j].conditions.forEach(c => { | ||
expandFunction(c); | ||
}); | ||
} | ||
if (po.objects[j].mapping && Array.isArray(po.objects[j].mapping)) { | ||
po.objects[j].mapping.forEach(m => { | ||
const anotherObject = JSON.parse(JSON.stringify(po.objects[j])); | ||
anotherObject.mapping = m; | ||
po.objects.push(anotherObject); | ||
}); | ||
po.objects.splice(j, 1); | ||
} | ||
delete po.datatype; | ||
delete po.language; | ||
} | ||
delete po.datatype; | ||
delete po.language; | ||
}); | ||
} | ||
} | ||
@@ -245,3 +266,3 @@ | ||
if (input.parameters) { | ||
for (let i = 0; i < input.parameters.length; i ++) { | ||
for (let i = 0; i < input.parameters.length; i++) { | ||
const e = input.parameters[i]; | ||
@@ -258,2 +279,6 @@ | ||
} | ||
if (e.value instanceof Object) { | ||
expandFunction(e.value); | ||
} | ||
} | ||
@@ -298,4 +323,2 @@ } | ||
//console.log(wanted); | ||
//console.log(value); | ||
shortcuts[wanted].forEach(shortcut => { | ||
@@ -302,0 +325,0 @@ //console.log(shortcut); |
@@ -14,5 +14,5 @@ /** | ||
{subject: namespaces.ex + 'TM1', predicate: namespaces.rdf + 'type', object: namespaces.rr + 'TriplesMap'}, | ||
{subject: namespaces.ex + 'TM1', predicate: namespaces.rdfs + 'label', object: 'person'}, | ||
{subject: namespaces.ex + 'TM1', predicate: namespaces.rdfs + 'label', object: '"person"'}, | ||
{subject: namespaces.ex + 'TM1', predicate: namespaces.rr + 'subjectMap', object: namespaces.ex + 'SM1'}, | ||
{subject: namespaces.ex + 'SM1', predicate: namespaces.rr + 'template', object: 'http://example.com/{ID}'} | ||
{subject: namespaces.ex + 'SM1', predicate: namespaces.rr + 'template', object: '"http://example.com/{ID}"'} | ||
]; | ||
@@ -22,3 +22,3 @@ | ||
person: | ||
s: 'http://example.com/{ID}' | ||
s: 'http://example.com/$(ID)' | ||
`; | ||
@@ -53,2 +53,2 @@ | ||
}); | ||
}); | ||
}); |
@@ -25,5 +25,12 @@ /** | ||
this.counter = {}; | ||
let json; | ||
try { | ||
const json = YAML.parse(yarrrml); | ||
json = YAML.parse(yarrrml); | ||
} catch(e) { | ||
e.code = 'INVALID_YAML'; | ||
throw e; | ||
} | ||
try { | ||
//expand JSON | ||
@@ -41,3 +48,3 @@ const expandedJSON = expand(json); | ||
} catch(e) { | ||
e.code = 'INVALID_YAML'; | ||
e.code = 'INVALID_YARRRML'; | ||
throw e; | ||
@@ -325,3 +332,3 @@ } | ||
}); | ||
} else { | ||
} else if (termType) { | ||
this.triples.push({ | ||
@@ -443,15 +450,19 @@ subject: omSubject, | ||
predicate = namespaces.rr + 'template'; | ||
if (pm.value instanceof Object) { | ||
this.generateFunctionTermMap(omSubject, pm.value, sourceSubject); | ||
} else { | ||
predicate = namespaces.rr + 'template'; | ||
if (YARRRML2Anything.parseTemplate(pm.value) === pm.value) { | ||
predicate = namespaces.rr + 'constant'; | ||
} | ||
if (YARRRML2Anything.parseTemplate(pm.value) === pm.value) { | ||
predicate = namespaces.rr + 'constant'; | ||
} | ||
object = `"${YARRRML2Anything.expandPrefix(YARRRML2Anything.parseTemplate(pm.value))}"`; | ||
object = `"${YARRRML2Anything.expandPrefix(YARRRML2Anything.parseTemplate(pm.value))}"`; | ||
this.triples.push({ | ||
subject: omSubject, | ||
predicate, | ||
object | ||
}); | ||
this.triples.push({ | ||
subject: omSubject, | ||
predicate, | ||
object | ||
}); | ||
} | ||
}); | ||
@@ -458,0 +469,0 @@ } |
{ | ||
"name": "@rmlio/yarrrml-parser", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"description": "Parse YARRRML descriptions into RML RDF statements", | ||
@@ -36,3 +36,3 @@ "main": "lib/yarrrml2rml.js", | ||
"uglify-es": "^3.3.9", | ||
"winston": "^2.4.0", | ||
"winston": "^2.4.3", | ||
"winston-daily-rotate-file": "^1.7.2", | ||
@@ -39,0 +39,0 @@ "yamljs": "^0.3.0" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
142105
65
2397
Updatedwinston@^2.4.3