New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@rmlio/yarrrml-parser

Package Overview
Dependencies
Maintainers
2
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rmlio/yarrrml-parser - npm Package Compare versions

Comparing version 1.1.1 to 1.2.0

.dockerignore

64

bin/parser.js

@@ -17,2 +17,3 @@ #!/usr/bin/env node

const watch = require('../lib/watcher.js');
const glob = require('glob');

@@ -23,14 +24,40 @@ namespaces.ql = 'http://semweb.mmlab.be/ns/ql#';

/**
* This method collect all values when an option is used multiple times.
* @param val A single value.
* @param memo The current array of values.
* @returns {*} The updated array with the new value.
*/
function collect(val, memo) {
memo.push(val);
return memo;
}
program.version(module.exports.version);
program.option('-i, --input <input>', 'input file');
program.option('-o, --output <output>', 'output file (default: stdout)');
program.option('-f, --format <output>', 'RML or R2RML (default: RML)');
program.option('-i, --input <file>', 'input file (can be used multiple times)', collect, []); // We support multiple uses of this option.
program.option('-c, --class', 'use rr:class when appropriate');
program.option('-o, --output <file>', 'output file (default: stdout)');
program.option('-f, --format <format>', 'RML or R2RML (default: RML)');
program.option('-w, --watch', 'watch for file changes');
program.option('-e, --external <value>', 'external references (key=value, can be used multiple times', collect, []); // We support multiple uses of this option.
program.option('-m, --skip-metadata', 'include metadata in generated rules');
program.parse(process.argv);
if (!program.input) {
console.error('Please provide an input file.');
console.error('Please provide an input file using -i| --input.');
} else {
if (!path.isAbsolute(program.input)) {
program.input = path.join(process.cwd(), program.input);
let inputPaths = [];
for (let input of program.input) {
// Check if the input is a regex, e.g., *.yarrrml
if (glob.hasMagic(input)) {
const foundFiles = glob.sync(input).map(file => path.join(process.cwd(), file));
inputPaths = inputPaths.concat(foundFiles);
} else {
if (!path.isAbsolute(input)) {
input = path.join(process.cwd(), input);
}
inputPaths.push(input);
}
}

@@ -40,4 +67,9 @@

try {
const inputData = fs.readFileSync(program.input, 'utf8');
const inputData = [];
for (const p of inputPaths) {
const yarrrml = fs.readFileSync(p, 'utf8');
inputData.push({yarrrml, file: p});
}
if (program.format) {

@@ -55,7 +87,19 @@ program.format = program.format.toUpperCase();

fno: "https://w3id.org/function/ontology#",
d2rq: "http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#"
d2rq: "http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#",
void: "http://rdfs.org/ns/void#",
dc: "http://purl.org/dc/terms/",
foaf: "http://xmlns.com/foaf/0.1/"
};
const externalReferences = {};
for (const e of program.external) {
const keyValue = e.split('=');
externalReferences[keyValue[0]] = keyValue[1];
}
const includeMetadata =!(!!program.skipMetadata);
if (!program.format || program.format === 'RML') {
const y2r = new Y2R();
const y2r = new Y2R({class: !!program.class, externalReferences, includeMetadata});
triples = y2r.convert(inputData);

@@ -68,3 +112,3 @@

} else {
const y2r = new Y2R2();
const y2r = new Y2R2({class: !!program.class, externalReferences, includeMetadata});
triples = y2r.convert(inputData);

@@ -71,0 +115,0 @@ prefixes[''] = y2r.getBaseIRI();

@@ -10,2 +10,20 @@ # Changelog

## [1.2.0] - 2020-08-17
### Added
- rr:class flag (see [issue 73](https://github.com/RMLio/yarrrml-parser/issues/73))
- Allow multiple input files for the CLI (see [issue 34](https://github.com/RMLio/yarrrml-parser/issues/34))
- reference formulation for CSS (see [issue 37](https://github.com/RMLio/yarrrml-parser/issues/37))
- Allow multiple input files for the CLI (see [issue 34](https://github.com/RMLio/yarrrml-parser/issues/34))
- Overwrite references (see [issue 35](https://github.com/RMLio/yarrrml-parser/issues/35))
- Support authors (see [issue 87](https://github.com/RMLio/yarrrml-parser/issues/87))
### Fixed
- Condition on mapping when subject has function fails (see [issue 75](https://github.com/RMLio/yarrrml-parser/issues/75))
- Create blank node as object (see [issue 59](https://github.com/RMLio/yarrrml-parser/issues/59))
- Condition on mapping with blank node as subject gives error (see [issue 31](https://github.com/RMLio/yarrrml-parser/issues/31))
### Changed
- Pad suffixes to keep ordering (see [issue 78](https://github.com/RMLio/yarrrml-parser/issues/78))
## [1.1.1] - 2020-05-11

@@ -164,2 +182,3 @@

[1.2.0]: https://github.com/RMLio/yarrrml-parser/compare/v1.1.1...v1.2.0
[1.1.1]: https://github.com/RMLio/yarrrml-parser/compare/v1.1.0...v1.1.1

@@ -166,0 +185,0 @@ [1.1.0]: https://github.com/RMLio/yarrrml-parser/compare/v1.0.2...v1.1.0

410

lib/abstract-generator.js

@@ -6,16 +6,16 @@ /**

const YAML = require('yamljs');
const expand = require('./expander.js');
const namespaces = require('prefix-ns').asMap();
const rdfaVocs = require('./rdfa-context.json')['@context'];
const { DataFactory } = require('n3');
const YAML = require('yamljs');
const expand = require('./expander.js');
const namespaces = require('prefix-ns').asMap();
const rdfaVocs = require('./rdfa-context.json')['@context'];
const {DataFactory} = require('n3');
const {namedNode, literal, quad} = DataFactory;
namespaces.ql = 'http://semweb.mmlab.be/ns/ql#';
namespaces.ql = 'http://semweb.mmlab.be/ns/ql#';
namespaces.fnml = 'http://semweb.mmlab.be/ns/fnml#';
namespaces.fno = 'https://w3id.org/function/ontology#';
namespaces.fno = 'https://w3id.org/function/ontology#';
class AbstractGenerator {
constructor() {
constructor(options = null) {
this.mappingsAndIRIs = {};

@@ -26,31 +26,57 @@ this.referencingObjectMapDetails = {};

this.quads = [];
this.options = {...{class: false, externalReferences: {}, includeMetadata: true}, ...options}
this.externalReferences = this.options.externalReferences;
this.authors = [];
}
/**
* This method converts YARRRML to another set of rules.
* @param yarrrml {string|array} This is either an array of objects {yarrrml, file} that need to be converted or
* a single YARRRML string.
*/
convert(yarrrml) {
// To make it backwards compatible.
if (typeof yarrrml === 'string' || yarrrml instanceof String) {
yarrrml = [{yarrrml}];
}
this.counter = {};
let json;
const expandedJSONs = [];
try {
json = YAML.parse(yarrrml);
} catch(e) {
e.code = 'INVALID_YAML';
throw e;
}
for (const el of yarrrml) {
const {yarrrml, file} = el;
try {
//expand JSON
const expandedJSON = expand(json);
let json;
if (expandedJSON.prefixes) {
this.prefixes = expandedJSON.prefixes;
try {
json = YAML.parse(yarrrml);
} catch (e) {
e.code = 'INVALID_YAML';
e.file = file
throw e;
}
//convert to RML
return this.convertExpandedJSON(expandedJSON);
try {
const expandedJSON = expand(json);
if (expandedJSON.external) {
this.externalReferences = {...this.externalReferences, ...expandedJSON.external};
}
//return JSON.stringify(jsonld);
} catch(e) {
e.code = 'INVALID_YARRRML';
throw e;
if (expandedJSON.authors) {
this.authors = this.authors.concat(expandedJSON.authors);
}
expandedJSONs.push(expandedJSON);
} catch (e) {
e.code = 'INVALID_YARRRML';
throw e;
}
}
const combinedExpandedJSON = this._combineExpandedJSONs(expandedJSONs);
this.prefixes = combinedExpandedJSON.prefixes;
this.externalReferences = {...this.externalReferences, ...this.options.externalReferences};
//convert to RML
return this.convertExpandedJSON(combinedExpandedJSON);
}

@@ -64,4 +90,53 @@

}
if (this.options.includeMetadata) {
this._generateDatasetDescription(this.authors);
}
}
/**
* This method combines multiple expanded JSONs in a single one.
* @param expandedJSONs An array of expanded JSONs that need to be combined.
* @returns {{mappings: {}, prefixes: {}, sources: {}}} The combined expanded JSON.
* @private
*/
_combineExpandedJSONs(expandedJSONs) {
const result = {mappings: {}, prefixes: {}, sources: {}};
for (const json of expandedJSONs) {
this._addSourceValuesToTarget(json.mappings, result.mappings, 'Mapping');
this._addSourceValuesToTarget(json.prefixes, result.prefixes, 'Prefix');
this._addSourceValuesToTarget(json.sources, result.sources, 'Source');
if (json.base) {
if (result.base) {
console.warn(`Base is multiple times defined. Using only "${result.base}".`);
} else {
result.base = json.base;
}
}
}
return result;
}
/**
* This method adds all key-values from a source object to a target object.
* Warning messages are outputted if a key already exists in the target object.
* In this case the value in the target object for that key is preserved.
* @param sourceObj {object} The object from which the key-value pairs are read.
* @param targetObj {object} The object to which the non-existing key-value pairs are added.
* @param messageValue {string} The type of key. This is used in the warning message.
* @private
*/
_addSourceValuesToTarget(sourceObj, targetObj, messageValue) {
for (const key in sourceObj) {
if (targetObj[key]) {
console.warn(`${messageValue} with key "${key}" is multiple times defined. Using only fist occurrence.`);
} else {
targetObj[key] = sourceObj[key];
}
}
}
generateMapping(tmSubject, mapping, mappingName, sourceSubject) {

@@ -75,37 +150,5 @@

if (mapping.subjects) {
mapping.subjects.forEach(subject => {
const smSubject = namedNode(this.baseIRI + this.getUniqueID('s'));
const subjectMaps = []
this.quads.push(quad(
smSubject,
namedNode(namespaces.rdf + 'type'),
namedNode(namespaces.rr + 'SubjectMap')
));
this.quads.push(quad(
tmSubject,
namedNode(namespaces.rr + 'subjectMap'),
smSubject
));
if (typeof subject === "object") {
this.generateFunctionTermMap(smSubject, subject, sourceSubject, 'IRI');
} else {
const {predicate, object} = this.getAppropriatePredicateAndObjectForValue(subject);
this.quads.push(quad(
smSubject,
predicate,
object
));
}
if (mapping.graphs) {
mapping.graphs.forEach(graph => {
this.generateGraphMap(smSubject, graph, sourceSubject);
});
}
});
} else {
//we are dealing with a blank node
mapping.subjects.forEach(subject => {
const smSubject = namedNode(this.baseIRI + this.getUniqueID('s'));

@@ -125,11 +168,52 @@

this.quads.push(quad(
smSubject,
namedNode(namespaces.rr + 'termType'),
namedNode(namespaces.rr + 'BlankNode')
));
}
if (typeof subject === "object") {
if (subject.function) {
this.generateFunctionTermMap(smSubject, subject, sourceSubject, subject.type === 'iri' ? 'IRI' : 'BlankNode');
} else {
this.quads.push(quad(
smSubject,
namedNode(namespaces.rr + 'termType'),
namedNode(namespaces.rr + 'BlankNode')
));
}
} else {
const {predicate, object} = this.getAppropriatePredicateAndObjectForValue(subject);
this.quads.push(quad(
smSubject,
predicate,
object
));
}
if (mapping.graphs) {
mapping.graphs.forEach(graph => {
this.generateGraphMap(smSubject, graph, sourceSubject);
});
}
subjectMaps.push(smSubject);
});
if (mapping.predicateobjects) {
mapping.predicateobjects.forEach(po => {
if (this.options.class && // flag
po.predicates.length === 1 && // only one predicate
po.predicates[0].indexOf('$(') === -1 && // without template, ie, a constant value
['a', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type'].indexOf(AbstractGenerator.expandPrefix(po.predicates[0])) !== -1 && // is `a` or `rdf:type`
po.objects.filter(o => o.function).length === 0 && // no functions
po.objects.filter(o => o.mapping).length === 0 // no mappings
) {
subjectMaps.forEach(sMap => {
po.objects.forEach(o => {
const {object} = this.getAppropriatePredicateAndObjectForValue(o.value, true);
this.quads.push(quad(
sMap,
namedNode(namespaces.rr + 'class'),
object
));
});
});
return;
}
const pomSubject = namedNode(this.baseIRI + this.getUniqueID('pom'));

@@ -170,3 +254,6 @@

if (p === 'a') {
appropriatePO = {object: namedNode(namespaces.rdf + 'type'), predicate: namedNode(namespaces.rr + 'constant')};
appropriatePO = {
object: namedNode(namespaces.rdf + 'type'),
predicate: namedNode(namespaces.rr + 'constant')
};
isPredicateRDFTYPE = true;

@@ -223,10 +310,2 @@ } else {

const {predicate, object} = this.getAppropriatePredicateAndObjectForValue(o.value);
this.quads.push(quad(
omSubject,
predicate,
object
));
switch (o.type) {

@@ -236,3 +315,6 @@ case 'iri':

break;
case "literal":
case 'blank':
o.type = namedNode(namespaces.rr + 'BlankNode');
break;
case 'literal':
default:

@@ -243,2 +325,12 @@ o.type = namedNode(namespaces.rr + 'Literal');

if (o.value) {
const {predicate, object} = this.getAppropriatePredicateAndObjectForValue(o.value);
this.quads.push(quad(
omSubject,
predicate,
object
));
}
this.quads.push(quad(

@@ -475,22 +567,23 @@ omSubject,

if (pm.from === 'subject') {
//get type: iri or literal
const {predicate, object} = this.getAppropriatePredicateAndObjectForValue(pm.value);
this.quads.push(quad(
omSubject,
predicate,
object
));
if (pm.type === 'iri') {
if (pm.type === 'blank') {
this.quads.push(quad(
omSubject,
namedNode(namespaces.rr + 'termType'),
namedNode(namespaces.rr + 'IRI')
namedNode(namespaces.rr + 'BlankNode')
));
} else {
const {predicate, object} = this.getAppropriatePredicateAndObjectForValue(pm.value);
this.quads.push(quad(
omSubject,
predicate,
object
));
const termTypeObject = pm.type === 'iri' ? 'IRI' : 'Literal';
this.quads.push(quad(
omSubject,
namedNode(namespaces.rr + 'termType'),
namedNode(namespaces.rr + 'Literal')
namedNode(namespaces.rr + termTypeObject)
));

@@ -553,2 +646,65 @@ }

/**
* This method creates quads for the void dataset representing the rules with
* the authors as contributors.
* @param authors - An array of authors that will be added as contributors.
*/
_generateDatasetDescription(authors) {
this.datasetIRI = namedNode(this.baseIRI + this.getUniqueID('rules'));
this.quads.push(quad(
this.datasetIRI,
namedNode(namespaces.rdf + 'type'),
namedNode(namespaces.void + 'Dataset')
));
for (const author of authors) {
if (author.webid) {
this.quads.push(quad(
this.datasetIRI,
namedNode(namespaces.dcterms + 'contributor'),
namedNode(author.webid)
));
} else {
const personIRI = namedNode(this.baseIRI + this.getUniqueID('person'));
this.quads.push(quad(
this.datasetIRI,
namedNode(namespaces.dcterms + 'contributor'),
personIRI
));
this.quads.push(quad(
personIRI,
namedNode(namespaces.dcterms + 'contributor'),
namedNode(namespaces.foaf + 'Person')
));
if (author.name) {
this.quads.push(quad(
personIRI,
namedNode(namespaces.rdfs + 'label'),
literal(author.name)
));
}
if (author.email) {
this.quads.push(quad(
personIRI,
namedNode(namespaces.foaf + 'mbox'),
namedNode(`mailto:${author.email}`)
));
}
if (author.website) {
this.quads.push(quad(
personIRI,
namedNode(namespaces.foaf + 'homepage'),
namedNode(author.website)
));
}
}
}
}
static parseTemplate(t) {

@@ -573,3 +729,3 @@ t = '' + t; // Make sure it's a string.

t = '' + t;
const match = t.match(/\{([^\}]*)\}/g);
const match = t.match(/\{([^\}]*)\}/g);

@@ -594,2 +750,28 @@ if (match === null) {

/**
* This function replaces all external references in a given string.
* @param {string} str - The string in which the external references have to be replaced with their values.
*/
_replaceExternalReferences(str) {
str = '' + str;
const refs = str.match(/\{([^\}]*)\}/g);
if (refs) {
for (const ref of refs) {
if (ref.startsWith('{_')) {
const refWithoutBrackets = ref.substr(2, ref.length - 3);
const externalRefValue = this.externalReferences[refWithoutBrackets];
if (externalRefValue) {
str = str.replace(ref, externalRefValue);
} else {
console.info(`No external reference is found for ${ref}. It is not replaced.`);
}
}
}
}
return str;
}
getUniqueID(prefix = '') {

@@ -603,10 +785,10 @@ if (!prefix) {

}
const id = this.counter[prefix];
const id = '' + this.counter[prefix];
this.counter[prefix]++;
return `${prefix}_${id}`;
return `${prefix}_${id.padStart(3, '0')}`;
}
static expandPrefix(str) {
if (!(typeof(str) === 'string' || str instanceof String)) {
if (!(typeof (str) === 'string' || str instanceof String)) {
return str;

@@ -645,2 +827,11 @@ }

this.mappingsAndIRIs[mappingName].push(iri);
if (this.datasetIRI) {
// Add the Triples Map to the void dataset.
this.quads.push(quad(
this.datasetIRI,
namedNode(namespaces.void + 'exampleResource'),
iri
));
}
}

@@ -660,18 +851,31 @@

const parsedValue = AbstractGenerator.parseTemplate(escapedValue);
let object = literal(parsedValue);
let object;
if (AbstractGenerator.countReference(parsedValue) === 1 && !AbstractGenerator.hasConstantPart(parsedValue)) {
object = AbstractGenerator.getFirstReference(parsedValue);
object = literal(AbstractGenerator.expandPrefix(object));
predicate = this.getReferenceOnlyPredicate();
object = this._replaceExternalReferences(parsedValue);
if (object === parsedValue) {
object = object.replace(/\\_/g, '_');
object = AbstractGenerator.getFirstReference(object);
object = AbstractGenerator.expandPrefix(object)
object = literal(object);
predicate = this.getReferenceOnlyPredicate();
} else {
object = literal(object);
predicate = namedNode(namespaces.rr + 'constant');
}
} else if (parsedValue === escapedValue) {
predicate = namedNode(namespaces.rr + 'constant');
predicate = namedNode(namespaces.rr + 'constant');
object = this._replaceExternalReferences(AbstractGenerator.expandPrefix(value));
if (isIRI) {
object = namedNode(AbstractGenerator.expandPrefix(value));
} else {
object = literal(AbstractGenerator.expandPrefix(value));
}
if (isIRI) {
object = namedNode(object);
} else {
object = literal(object);
}
} else {
object = literal(AbstractGenerator.expandPrefix(parsedValue));
const expandedValue = AbstractGenerator.expandPrefix(parsedValue);
object = this._replaceExternalReferences(expandedValue);
object = object.replace(/\\_/g, '_');
object = literal(object);
}

@@ -678,0 +882,0 @@

@@ -7,2 +7,3 @@ /**

const extend = require('extend');
const parseAuthor = require('parse-author');

@@ -27,2 +28,3 @@ const shortcuts = {

function expand(input) {

@@ -35,2 +37,3 @@ const output = {};

expandMappings(output);
expandAuthors(output);
expandSourcesInDocument(output);

@@ -74,2 +77,6 @@

expandFunction(mapping.subjects[i]);
if (!mapping.subjects[i].type) {
mapping.subjects[i].type = 'iri'
}
}

@@ -79,4 +86,11 @@ }

expandFunction(mapping.subjects);
if (!mapping.subjects.type) {
mapping.subjects.type = 'iri'
}
mapping.subjects = [mapping.subjects];
}
} else {
mapping.subjects = [{type: 'blank'}];
}

@@ -91,3 +105,3 @@

const subject = mapping.subjects[i];
mapping.subjects[0] = {
mapping.subjects[i] = {
function: idlabfn + 'trueCondition',

@@ -101,7 +115,8 @@ parameters: [

parameter: idlabfn + 'str',
value: subject,
from: 'subject'
value: subject.type === 'blank' ? null : subject,
from: subject.function !== undefined ? 'function' : 'subject',
type: subject.type ? subject.type : 'iri'
}
],
type: 'iri' // TODO include blank nodes
type: subject.type ? subject.type : 'iri'
};

@@ -509,2 +524,37 @@ delete mapping.conditions;

/**
* This method expands authors.
* @param input - The JSON object of the YARRRML rules.
*/
function expandAuthors(input) {
if (input.authors) {
let authors = input.authors;
if (typeof authors === 'string' || authors instanceof String) {
authors = [authors];
input.authors = authors;
}
for (let i = 0; i < authors.length; i ++) {
const author = authors[i];
if (typeof author === 'string' || author instanceof String) {
const parsedAuthor = parseAuthor(author);
// This is a WebID.
if (parsedAuthor.name && parsedAuthor.name.includes('://')) {
authors[i] = {webid: author};
} else {
if (parsedAuthor.url) {
parsedAuthor.website = parsedAuthor.url;
}
delete parsedAuthor.url;
authors[i] = parsedAuthor;
}
}
}
}
}
module.exports = expand;

@@ -131,3 +131,4 @@ /**

}
]
],
type: 'iri'
}

@@ -160,5 +161,7 @@ ]

person: {
subjects: [{type: 'blank'}],
predicateobjects: []
},
project: {
subjects: [{type: 'blank'}],
predicateobjects: []

@@ -187,2 +190,3 @@ }

person: {
subjects: [{type: 'blank'}],
predicateobjects: [

@@ -221,2 +225,3 @@ {

person: {
subjects: [{type: 'blank'}],
predicateobjects: [

@@ -259,2 +264,3 @@ {

person: {
subjects: [{type: 'blank'}],
predicateobjects: [

@@ -293,2 +299,3 @@ {

person: {
subjects: [{type: 'blank'}],
predicateobjects: [

@@ -327,2 +334,3 @@ {

person: {
subjects: [{type: 'blank'}],
predicateobjects: [

@@ -364,2 +372,3 @@ {

person: {
subjects: [{type: 'blank'}],
predicateobjects: [

@@ -398,2 +407,3 @@ {

person: {
subjects: [{type: 'blank'}],
predicateobjects: [

@@ -441,2 +451,3 @@ {

person: {
subjects: [{type: 'blank'}],
predicateobjects: [

@@ -478,2 +489,3 @@ {

person: {
subjects: [{type: 'blank'}],
predicateobjects: [

@@ -523,2 +535,5 @@ {

}
],
subjects: [
{type: 'blank'}
]

@@ -584,2 +599,3 @@ }

person: {
subjects: [{type: 'blank'}],
predicateobjects: [

@@ -632,2 +648,3 @@ {

person: {
subjects: [{type: 'blank'}],
predicateobjects: [

@@ -687,5 +704,6 @@ {

}
]
],
type: 'iri'
}
]
]
}

@@ -745,2 +763,3 @@ }

{
subjects: [{type: 'blank'}],
predicateobjects:

@@ -818,2 +837,3 @@ [{

{
subjects: [{type: 'blank'}],
predicateobjects:

@@ -884,2 +904,3 @@ [{

{
subjects: [{type: 'blank'}],
predicateobjects:

@@ -929,2 +950,459 @@ [{

});
it('condition on mapping with blank node as subject', () => {
const input = {
"prefixes": {
"idlab-fn": "http://example.com/idlab/function/",
"grel": "http://users.ugent.be/~bjdmeest/function/grel.ttl#"
},
"mappings": {
"test": {
"condition": {
"function": "idlab-fn:equal",
"parameters": [
[
"grel:valueParameter",
"$(id)"
],
[
"grel:valueParameter2",
1
]
]
},
"po": [
[
"a",
"http://example.com/Test"
]
]
}
}
};
const expectedOutput = {
"prefixes": {
"idlab-fn": "http://example.com/idlab/function/",
"grel": "http://users.ugent.be/~bjdmeest/function/grel.ttl#"
},
"mappings": {
"test": {
"subjects": [
{
"function": "http://example.com/idlab/function/trueCondition",
"parameters": [
{
"parameter": "http://example.com/idlab/function/strBoolean",
"value": {
"function": "idlab-fn:equal",
"parameters": [
{
"parameter": "grel:valueParameter",
"value": "$(id)",
"type": "literal",
"from": "subject"
},
{
"parameter": "grel:valueParameter2",
"value": "1",
"type": "literal",
"from": "subject"
}
]
},
"from": "function"
},
{
"parameter": "http://example.com/idlab/function/str",
"value": null,
"type": "blank",
"from": "subject"
}
],
"type": "blank"
}
],
"predicateobjects": [
{
"predicates": [
"a"
],
"objects": [
{
"value": "http://example.com/Test",
"type": "iri"
}
]
}
]
}
}
};
const output = expand(input);
assert.deepStrictEqual(output, expectedOutput);
});
describe('authors', () => {
it('array with objects', () => {
const input = {
"prefixes": {
"ex": "http://example.com/"
},
"authors": [
{
"name": "John Doe",
"email": "john@doe.com"
},
{
"name": "Jane Doe",
"website": "https://janedoe.com"
}
],
"mappings": {
"person": {
"sources": [
[
"data.json~jsonpath",
"$.persons[*]"
]
],
"s": "http://example.com/$(firstname)",
"po": [
[
"a",
"foaf:Person"
],
[
"ex:name",
"$(firstname)"
]
]
}
}
};
const expectedOutput = {
"prefixes": {
"ex": "http://example.com/"
},
"authors": [
{
"name": "John Doe",
"email": "john@doe.com"
},
{
"name": "Jane Doe",
"website": "https://janedoe.com"
}
],
"mappings": {
"person": {
"sources": [
{
"access": "data.json",
"referenceFormulation": "jsonpath",
"iterator": "$.persons[*]"
}
],
"subjects": [
"http://example.com/$(firstname)"
],
"predicateobjects": [
{
"predicates": [
"a"
],
"objects": [
{
"value": "foaf:Person",
"type": "iri"
}
]
},
{
"predicates": [
"ex:name"
],
"objects": [
{
"value": "$(firstname)",
"type": "literal"
}
]
}
]
}
}
};
const output = expand(input);
assert.deepStrictEqual(output, expectedOutput);
});
it('array with strings', () => {
const input = {
"prefixes": {
"ex": "http://example.com/"
},
"authors": [
"John Doe <john@doe.com>",
"Jane Doe (https://janedoe.com)"
],
"mappings": {
"person": {
"sources": [
[
"data.json~jsonpath",
"$.persons[*]"
]
],
"s": "http://example.com/$(firstname)",
"po": [
[
"a",
"foaf:Person"
],
[
"ex:name",
"$(firstname)"
]
]
}
}
};
const expectedOutput = {
"prefixes": {
"ex": "http://example.com/"
},
"authors": [
{
"name": "John Doe",
"email": "john@doe.com"
},
{
"name": "Jane Doe",
"website": "https://janedoe.com"
}
],
"mappings": {
"person": {
"sources": [
{
"access": "data.json",
"referenceFormulation": "jsonpath",
"iterator": "$.persons[*]"
}
],
"subjects": [
"http://example.com/$(firstname)"
],
"predicateobjects": [
{
"predicates": [
"a"
],
"objects": [
{
"value": "foaf:Person",
"type": "iri"
}
]
},
{
"predicates": [
"ex:name"
],
"objects": [
{
"value": "$(firstname)",
"type": "literal"
}
]
}
]
}
}
};
const output = expand(input);
assert.deepStrictEqual(output, expectedOutput);
});
it('array with Web IDs', () => {
const input = {
"prefixes": {
"ex": "http://example.com/"
},
"authors": [
"http://johndoe.com/#me",
"http://janedoe.com/#me"
],
"mappings": {
"person": {
"sources": [
[
"data.json~jsonpath",
"$.persons[*]"
]
],
"s": "http://example.com/$(firstname)",
"po": [
[
"a",
"foaf:Person"
],
[
"ex:name",
"$(firstname)"
]
]
}
}
};
const expectedOutput = {
"prefixes": {
"ex": "http://example.com/"
},
"authors": [
{
"webid": "http://johndoe.com/#me"
},
{
"webid": "http://janedoe.com/#me"
}
],
"mappings": {
"person": {
"sources": [
{
"access": "data.json",
"referenceFormulation": "jsonpath",
"iterator": "$.persons[*]"
}
],
"subjects": [
"http://example.com/$(firstname)"
],
"predicateobjects": [
{
"predicates": [
"a"
],
"objects": [
{
"value": "foaf:Person",
"type": "iri"
}
]
},
{
"predicates": [
"ex:name"
],
"objects": [
{
"value": "$(firstname)",
"type": "literal"
}
]
}
]
}
}
};
const output = expand(input);
assert.deepStrictEqual(output, expectedOutput);
});
it('single string', () => {
const input = {
"prefixes": {
"ex": "http://example.com/"
},
"authors": "John Doe <john@doe.com>",
"mappings": {
"person": {
"sources": [
[
"data.json~jsonpath",
"$.persons[*]"
]
],
"s": "http://example.com/$(firstname)",
"po": [
[
"a",
"foaf:Person"
],
[
"ex:name",
"$(firstname)"
]
]
}
}
};
const expectedOutput = {
"prefixes": {
"ex": "http://example.com/"
},
"authors": [
{
"name": "John Doe",
"email": "john@doe.com"
}
],
"mappings": {
"person": {
"sources": [
{
"access": "data.json",
"referenceFormulation": "jsonpath",
"iterator": "$.persons[*]"
}
],
"subjects": [
"http://example.com/$(firstname)"
],
"predicateobjects": [
{
"predicates": [
"a"
],
"objects": [
{
"value": "foaf:Person",
"type": "iri"
}
]
},
{
"predicates": [
"ex:name"
],
"objects": [
{
"value": "$(firstname)",
"type": "literal"
}
]
}
]
}
}
};
const output = expand(input);
assert.deepStrictEqual(output, expectedOutput);
});
});
});

@@ -22,4 +22,5 @@ {

"xpath": "http://semweb.mmlab.be/ns/ql#XPath",
"csv": "http://semweb.mmlab.be/ns/ql#CSV"
"csv": "http://semweb.mmlab.be/ns/ql#CSV",
"css3": "http://semweb.mmlab.be/ns/ql#CSS3"
}
}
}

@@ -16,4 +16,4 @@ /**

constructor() {
super();
constructor(options = null) {
super(options);
}

@@ -20,0 +20,0 @@

@@ -11,43 +11,78 @@ /**

this.timeout(10000);
const options = {includeMetadata: false};
it('example1', function (done) {
work('example1/r2rml/mapping.yml', 'example1/r2rml/mapping.r2rml.ttl', done);
work('example1/r2rml/mapping.yml', 'example1/r2rml/mapping.r2rml.ttl', done, options);
});
it('example4', function (done) {
work('example4/r2rml/mapping.yml', 'example4/r2rml/mapping.r2rml.ttl', done);
work('example4/r2rml/mapping.yml', 'example4/r2rml/mapping.r2rml.ttl', done, options);
});
it('example5', function (done) {
work('example5/r2rml/mapping.yml', 'example5/r2rml/mapping.r2rml.ttl', done);
work('example5/r2rml/mapping.yml', 'example5/r2rml/mapping.r2rml.ttl', done, options);
});
it('example8', function (done) {
work('example8/r2rml/mapping.yml', 'example8/r2rml/mapping.r2rml.ttl', done);
work('example8/r2rml/mapping.yml', 'example8/r2rml/mapping.r2rml.ttl', done, options);
});
it('condition on po', function (done) {
work('condition-on-po/r2rml/mapping.yml', 'condition-on-po/r2rml/mapping.r2rml.ttl', done);
work('condition-on-po/r2rml/mapping.yml', 'condition-on-po/r2rml/mapping.r2rml.ttl', done, options);
});
it('condition on mapping with IRI as subject', function (done) {
work('condition-on-mapping/r2rml/mapping.yml', 'condition-on-mapping/r2rml/mapping.r2rml.ttl', done);
work('condition-on-mapping/r2rml/mapping.yml', 'condition-on-mapping/r2rml/mapping.r2rml.ttl', done, options);
});
it('metadata', function (done) {
work('metadata/r2rml/mapping.yarrrml', 'metadata/r2rml/mapping.r2rml.ttl', done);
});
describe('R2RML test cases', function () {
doR2RMLTestCase('R2RMLTC0001a');
doR2RMLTestCase('R2RMLTC0002a');
doR2RMLTestCase('R2RMLTC0002d');
doR2RMLTestCase('R2RMLTC0002i');
doR2RMLTestCase('R2RMLTC0009a');
it('R2RMLTC0001a', function (done) {
doR2RMLTestCase('R2RMLTC0001a', done, options);
});
it('R2RMLTC0002a', function (done) {
doR2RMLTestCase('R2RMLTC0002a', done, options);
});
it('R2RMLTC0002d', function (done) {
doR2RMLTestCase('R2RMLTC0002d', done, options);
});
it('R2RMLTC0002i', function (done) {
doR2RMLTestCase('R2RMLTC0002i', done, options);
});
it('R2RMLTC0009a', function (done) {
doR2RMLTestCase('R2RMLTC0009a', done, options);
});
});
describe('rr:class', function () {
const options = {class: true, includeMetadata: false};
doTestCase('rr_class/1-single', options);
doTestCase('rr_class/2-multiple', options);
doTestCase('rr_class/3-no-iri', options);
doTestCase('rr_class/4-rdf-type', options);
doTestCase('rr_class/5-custom-rdf-prefix', options);
doTestCase('rr_class/6-multiple-rows', options);
doTestCase('rr_class/7-function', options);
});
});
function work(path1, path2, cb) {
compareY2R2RFiles(path.resolve(__dirname, '../test/', path1), path.resolve(__dirname, '../test/', path2), cb);
}
function doR2RMLTestCase(testCaseID) {
it(testCaseID, function (done) {
work(`r2rml-test-cases/${testCaseID}/mapping.yarrrml`, `r2rml-test-cases/${testCaseID}/mapping.r2rml.ttl`, done);
function doTestCase(testCaseID, options) {
it(testCaseID.replace(/[-]/g, ' '), function (done) {
work(`${testCaseID}/mapping.yarrr.yml`, `${testCaseID}/mapping.r2rml.ttl`, done, options);
});
}
function work(path1, path2, cb, options = null) {
compareY2R2RFiles(path.resolve(__dirname, '../test/', path1), path.resolve(__dirname, '../test/', path2), options, cb);
}
function doR2RMLTestCase(testCaseID, done, options) {
work(`r2rml-test-cases/${testCaseID}/mapping.yarrrml`, `r2rml-test-cases/${testCaseID}/mapping.r2rml.ttl`, done, options);
}

@@ -18,4 +18,4 @@ /**

constructor() {
super();
constructor(options = null) {
super(options);
}

@@ -22,0 +22,0 @@

@@ -27,7 +27,7 @@ /**

it('works for an empty file', function (done) {
work('trivial/null.yml', 'trivial/null.rml.ttl', done);
work('trivial/null.yml', 'trivial/null.rml.ttl', done, {includeMetadata: false});
});
it('works for example1', function (done) {
work('example1/rml/mapping.yml', 'example1/rml/mapping.rml.ttl', done);
work('example1/rml/mapping.yml', 'example1/rml/mapping.rml.ttl', done, {includeMetadata: false});
});

@@ -40,11 +40,11 @@

it('works for example3', function (done) {
work('example3/mapping.yml', 'example3/mapping.rml.ttl', done);
work('example3/mapping.yml', 'example3/mapping.rml.ttl', done, {includeMetadata: false});
});
it('works for example4', function (done) {
work('example4/rml/mapping.yml', 'example4/rml/mapping.rml.ttl', done);
work('example4/rml/mapping.yml', 'example4/rml/mapping.rml.ttl', done, {includeMetadata: false});
});
it.skip('works for example5', function (done) {
work('example5/rml/mapping.yml', 'example5/rml/mapping.rml.ttl', done);
work('example5/rml/mapping.yml', 'example5/rml/mapping.rml.ttl', done, {includeMetadata: false});
});

@@ -57,23 +57,23 @@

it('works for example8', function (done) {
work('example8/rml/mapping.yml', 'example8/rml/mapping.rml.ttl', done);
work('example8/rml/mapping.yml', 'example8/rml/mapping.rml.ttl', done, {includeMetadata: false});
});
it('works for prefix expansion', function (done) {
work('prefixExpand/mapping.yml', 'prefixExpand/mapping.rml.ttl', done);
work('prefix-expand/mapping.yml', 'prefix-expand/mapping.rml.ttl', done, {includeMetadata: false});
});
it('works for graph', function (done) {
work('graph/mapping.yml', 'graph/mapping.rml.ttl', done);
work('graph/mapping.yml', 'graph/mapping.rml.ttl', done, {includeMetadata: false});
});
it('works for graph with function', function (done) {
work('graph/mapping_fno.yml', 'graph/mapping_fno.rml.ttl', done);
work('graph/mapping_fno.yml', 'graph/mapping_fno.rml.ttl', done, {includeMetadata: false});
});
it('recursive functions', function (done) {
work('recursive-functions/mapping.yml', 'recursive-functions/mapping.rml.ttl', done);
work('recursive-functions/mapping.yml', 'recursive-functions/mapping.rml.ttl', done, {includeMetadata: false});
});
it('works for strings starting with "{"', function (done) {
work('template-escape/mapping.yml', 'template-escape/mapping.rml.ttl', done);
work('template-escape/mapping.yml', 'template-escape/mapping.rml.ttl', done, {includeMetadata: false});
});

@@ -83,7 +83,7 @@

it('anime', function (done) {
work('betweenourworlds/rules-anime.yml', 'betweenourworlds/rules-anime.rml.ttl', done);
work('betweenourworlds/anime/mapping.yarrrml', 'betweenourworlds/anime/mapping.rml.ttl', done, {includeMetadata: false});
});
it('character', function (done) {
work('betweenourworlds/rules-character.yml', 'betweenourworlds/rules-character.rml.ttl', done);
work('betweenourworlds/character/mapping.yarrrml', 'betweenourworlds/character/mapping.rml.ttl', done, {includeMetadata: false});
});

@@ -93,104 +93,184 @@ });

it('fno-parameter-as-iri', function (done) {
work('fno-parameter-as-iri/mapping.yml', 'fno-parameter-as-iri/mapping.rml.ttl', done);
work('fno-parameter-as-iri/mapping.yml', 'fno-parameter-as-iri/mapping.rml.ttl', done, {includeMetadata: false});
});
it('joincondition with function', function (done) {
work('joincondition-with-function/mapping.yml', 'joincondition-with-function/mapping.rml.ttl', done);
work('joincondition-with-function/mapping.yml', 'joincondition-with-function/mapping.rml.ttl', done, {includeMetadata: false});
});
it('condition on po', function (done) {
work('condition-on-po/rml/mapping.yml', 'condition-on-po/rml/mapping.rml.ttl', done);
work('condition-on-po/rml/mapping.yml', 'condition-on-po/rml/mapping.rml.ttl', done, {includeMetadata: false});
});
it('condition on mapping with IRI as subject', function (done) {
work('condition-on-mapping/rml/mapping.yml', 'condition-on-mapping/rml/mapping.rml.ttl', done);
work('condition-on-mapping/rml/mapping.yml', 'condition-on-mapping/rml/mapping.rml.ttl', done, {includeMetadata: false});
});
it('predicate with prefix and template', function (done) {
work('predicate-with-prefix-template/mapping.yml', 'predicate-with-prefix-template/mapping.rml.ttl', done);
work('predicate-with-prefix-template/mapping.yml', 'predicate-with-prefix-template/mapping.rml.ttl', done, {includeMetadata: false});
});
it('function shortcut without prefix', function (done) {
work('function-shortcut-without-prefix/mapping.yml', 'function-shortcut-without-prefix/mapping.rml.ttl', done);
work('function-shortcut-without-prefix/mapping.yml', 'function-shortcut-without-prefix/mapping.rml.ttl', done, {includeMetadata: false});
});
it('function shortcut with prefix', function (done) {
work('function-shortcut-with-prefix/mapping.yml', 'function-shortcut-with-prefix/mapping.rml.ttl', done);
work('function-shortcut-with-prefix/mapping.yml', 'function-shortcut-with-prefix/mapping.rml.ttl', done, {includeMetadata: false});
});
it('function shortcut with 2 parameters', function (done) {
work('function-shortcut-with-2-parameters/mapping.yml', 'function-shortcut-with-2-parameters/mapping.rml.ttl', done);
work('function-shortcut-with-2-parameters/mapping.yml', 'function-shortcut-with-2-parameters/mapping.rml.ttl', done, {includeMetadata: false});
});
it('subject with function', function (done) {
work('subjectmap-with-function/mapping.yml', 'subjectmap-with-function/mapping.rml.ttl', done);
work('subjectmap-with-function/mapping.yml', 'subjectmap-with-function/mapping.rml.ttl', done, {includeMetadata: false});
});
it('condition and function on same po', function (done) {
work('condition-function-on-po/mapping.yarrrml', 'condition-function-on-po/mapping.rml.ttl', done);
work('condition-function-on-po/mapping.yarrrml', 'condition-function-on-po/mapping.rml.ttl', done, {includeMetadata: false});
});
it('datatype on function result', function (done) {
work('datatype-on-function/mapping.yarrrml', 'datatype-on-function/mapping.rml.ttl', done);
work('datatype-on-function/mapping.yarrrml', 'datatype-on-function/mapping.rml.ttl', done, {includeMetadata: false});
});
it('condition on single object', function (done) {
work('condition-on-single-object/mapping.yarrrml', 'condition-on-single-object/mapping.rml.ttl', done);
work('condition-on-single-object/mapping.yarrrml', 'condition-on-single-object/mapping.rml.ttl', done, {includeMetadata: false});
});
it('escape character', function (done) {
work('escape-character/mapping.yarrrml', 'escape-character/mapping.rml.ttl', done);
work('escape-character/mapping.yarrrml', 'escape-character/mapping.rml.ttl', done, {includeMetadata: false});
});
it('escape colon in object', function (done) {
work('escape-colon-object/mapping.yarrrml', 'escape-colon-object/mapping.rml.ttl', done);
work('escape-colon-object/mapping.yarrrml', 'escape-colon-object/mapping.rml.ttl', done, {includeMetadata: false});
});
it('escape bracket in reference', function (done) {
work('escape-bracket/mapping.yarrrml', 'escape-bracket/mapping.rml.ttl', done);
work('escape-bracket/mapping.yarrrml', 'escape-bracket/mapping.rml.ttl', done, {includeMetadata: false});
});
it('object is number', function (done) {
work('object-number/mapping.yarrrml', 'object-number/mapping.rml.ttl', done);
work('object-number/mapping.yarrrml', 'object-number/mapping.rml.ttl', done, {includeMetadata: false});
});
it('oracle', function (done) {
work('oracle/mapping.yarrrml', 'oracle/mapping.rml.ttl', done);
work('oracle/mapping.yarrrml', 'oracle/mapping.rml.ttl', done, {includeMetadata: false});
});
it('condition on mapping with constant', function (done) {
work('condition-on-mapping-constant/mapping.yarrrml', 'condition-on-mapping-constant/mapping.rml.ttl', done);
work('condition-on-mapping-constant/mapping.yarrrml', 'condition-on-mapping-constant/mapping.rml.ttl', done, {includeMetadata: false});
});
it('template with two references', function (done) {
work('template-2-references/mapping.yarrrml', 'template-2-references/mapping.rml.ttl', done);
work('template-2-references/mapping.yarrrml', 'template-2-references/mapping.rml.ttl', done, {includeMetadata: false});
});
it('join condition with one reference and text', function (done) {
work('joincondition-template-1-reference-text/mapping.yarrrml', 'joincondition-template-1-reference-text/mapping.rml.ttl', done);
work('joincondition-template-1-reference-text/mapping.yarrrml', 'joincondition-template-1-reference-text/mapping.rml.ttl', done, {includeMetadata: false});
});
it('join condition with two references', function (done) {
work('joincondition-template-2-references/mapping.yarrrml', 'joincondition-template-2-references/mapping.rml.ttl', done);
work('joincondition-template-2-references/mapping.yarrrml', 'joincondition-template-2-references/mapping.rml.ttl', done, {includeMetadata: false});
});
it('function without parameters', function (done) {
work('function-without-parameters/mapping.yarrrml', 'function-without-parameters/mapping.rml.ttl', done);
work('function-without-parameters/mapping.yarrrml', 'function-without-parameters/mapping.rml.ttl', done, {includeMetadata: false});
});
it('equal', function (done) {
work('equal/mapping.yarrrml', 'equal/mapping.rml.ttl', done);
work('equal/mapping.yarrrml', 'equal/mapping.rml.ttl', done, {includeMetadata: false});
});
it('nested condition on object with mapping', function (done) {
work('condition-on-mapping-nested/mapping.yarrrml', 'condition-on-mapping-nested/mapping.rml.ttl', done);
work('condition-on-mapping-nested/mapping.yarrrml', 'condition-on-mapping-nested/mapping.rml.ttl', done, {includeMetadata: false});
});
it('condition on po with datatype', function (done) {
work('condition-on-po-datatype/mapping.yarrrml', 'condition-on-po-datatype/mapping.rml.ttl', done);
work('condition-on-po-datatype/mapping.yarrrml', 'condition-on-po-datatype/mapping.rml.ttl', done, {includeMetadata: false});
});
it('condition on mapping with function for subject', function (done) {
work('condition-on-mapping-subject-function/mapping.yarrrml', 'condition-on-mapping-subject-function/mapping.rml.ttl', done, {includeMetadata: false});
});
it('condition on mapping with blank node', function (done) {
work('condition-on-mapping-with-blanknode/mapping.yarrrml', 'condition-on-mapping-with-blanknode/mapping.rml.ttl', done, {includeMetadata: false});
});
describe('rr:class', function () {
let options = {class: true, includeMetadata: false};
doTestCase('rr_class/1-single', options);
doTestCase('rr_class/2-multiple', options);
doTestCase('rr_class/3-no-iri', options);
doTestCase('rr_class/4-rdf-type', options);
doTestCase('rr_class/5-custom-rdf-prefix', options);
doTestCase('rr_class/6-multiple-rows', options);
doTestCase('rr_class/7-function', options);
doTestCase('rr_class/8-reference', options);
});
describe('object blank node', function () {
it('no template or constant', function (done) {
work('object-blank-node/mapping.yarrrml', 'object-blank-node/mapping.rml.ttl', done, {includeMetadata: false});
});
it('template', function (done) {
work('object-blank-node/template/mapping.yarrrml', 'object-blank-node/template/mapping.rml.ttl', done, {includeMetadata: false});
});
it('constant', function (done) {
work('object-blank-node/constant/mapping.yarrrml', 'object-blank-node/constant/mapping.rml.ttl', done, {includeMetadata: false});
});
});
it('multiple input files', function (done) {
workMultipleInputFiles(['multiple-input-files/mapping-1.yarrrml', 'multiple-input-files/mapping-2.yarrrml'],
'multiple-input-files/mapping.rml.ttl', done, {includeMetadata: false});
});
describe('external references', function () {
const options = {includeMetadata: false};
doTestCase('external-references/1', options);
doTestCase('external-references/2', options);
doTestCase('external-references/3', options);
doTestCase('external-references/4', options);
doTestCase('external-references/5', options);
});
describe('authors', function () {
it('array with objects', function (done) {
work('author/array-with-objects/mapping.yarrrml', 'author/array-with-objects/mapping.rml.ttl', done);
});
it('array with strings', function (done) {
work('author/array-with-strings/mapping.yarrrml', 'author/array-with-strings/mapping.rml.ttl', done);
});
it('array with Web IDs', function (done) {
work('author/array-with-webids/mapping.yarrrml', 'author/array-with-webids/mapping.rml.ttl', done);
});
it('single string', function (done) {
work('author/single-string/mapping.yarrrml', 'author/single-string/mapping.rml.ttl', done);
});
});
it('metadata', function (done) {
work('metadata/rml/mapping.yarrrml', 'metadata/rml/mapping.rml.ttl', done);
});
});
function work(path1, path2, cb) {
compareY2RFiles(path.resolve(__dirname, '../test/', path1), path.resolve(__dirname, '../test/', path2), cb);
function doTestCase(testCaseID, options) {
it(testCaseID.replace(/[-]/g, ' '), function (done) {
work(`${testCaseID}/mapping.yarrr.yml`, `${testCaseID}/mapping.rml.ttl`, done, options);
});
}
function work(path1, path2, cb, options = null) {
compareY2RFiles(path.resolve(__dirname, '../test/', path1), path.resolve(__dirname, '../test/', path2), options, cb);
}
function workMultipleInputFiles(inputFiles, expectedOutputFile, cb, options = null) {
const processedInputFiles = inputFiles.map(file => path.resolve(__dirname, '../test/', file));
compareY2RFiles(processedInputFiles, path.resolve(__dirname, '../test/', expectedOutputFile), options, cb);
}

@@ -17,16 +17,26 @@ const assert = require('assert');

function compareY2RFiles(ymlPath, ttlPath, cb) {
const yaml = fs.readFileSync(ymlPath, 'utf8');
function compareY2RFiles(ymlPaths, ttlPath, options, cb) {
const yamls = [];
if (typeof ymlPaths === 'string' || ymlPaths instanceof String) {
ymlPaths = [ymlPaths];
}
for (const ymlPath of ymlPaths) {
const yarrrml = fs.readFileSync(ymlPath, 'utf8');
yamls.push({yarrrml});
}
const ttl = fs.readFileSync(ttlPath, 'utf8');
compareY2RData(yaml, ttl, cb);
compareY2RData(yamls, ttl, options, cb);
}
function compareY2R2RFiles(ymlPath, ttlPath, cb) {
function compareY2R2RFiles(ymlPath, ttlPath, options, cb) {
const yaml = fs.readFileSync(ymlPath, 'utf8');
const ttl = fs.readFileSync(ttlPath, 'utf8');
compareY2R2RData(yaml, ttl, cb);
compareY2R2RData(yaml, ttl, options, cb);
}
function compareY2RData(yaml, ttl, cb) {
const y2r = new convertYAMLtoRML();
function compareY2RData(yaml, ttl, options, cb) {
const y2r = new convertYAMLtoRML(options);
const yamlQuads = y2r.convert(yaml);

@@ -40,3 +50,8 @@ const rmlQuads = [];

else {
assert(isomorphic(yamlQuads, rmlQuads), true);
try {
assert(isomorphic(yamlQuads, rmlQuads), true);
} catch (e) {
assert.deepStrictEqual(yamlQuads,rmlQuads);
assert(false, true);
}
cb();

@@ -47,4 +62,4 @@ }

function compareY2R2RData(yaml, ttl, cb) {
const y2r = new convertYAMLtoR2RML();
function compareY2R2RData(yaml, ttl, options, cb) {
const y2r = new convertYAMLtoR2RML(options);
const yamlQuads = y2r.convert(yaml);

@@ -58,6 +73,8 @@ const rmlQuads = [];

else {
if (error) {
return cb(error);
try {
assert(isomorphic(yamlQuads, rmlQuads), true);
} catch (e) {
assert.deepStrictEqual(yamlQuads, rmlQuads);
assert(false, true);
}
assert(isomorphic(yamlQuads, rmlQuads), true);
cb();

@@ -81,2 +98,3 @@ }

makeReadable(triples, writer);
compareY2RFiles
writer.end(cb);

@@ -83,0 +101,0 @@ }

@@ -19,3 +19,3 @@ /**

function watch(input, output, format) {
inputFile = input;
inputFile = input[0];
outputFile = output;

@@ -22,0 +22,0 @@

{
"name": "@rmlio/yarrrml-parser",
"version": "1.1.1",
"version": "1.2.0",
"description": "Parse YARRRML descriptions into RML RDF statements",

@@ -23,3 +23,5 @@ "main": "lib/yarrrml2rml.js",

"extend": "^3.0.2",
"glob": "^7.1.6",
"n3": "^1.3.5",
"parse-author": "^2.0.0",
"pkginfo": "^0.4.1",

@@ -35,3 +37,3 @@ "prefix-ns": "^0.1.2",

"devDependencies": {
"mocha": "^6.2.2"
"mocha": "^8.0.1"
},

@@ -38,0 +40,0 @@ "bin": {

@@ -22,4 +22,19 @@ # YARRRML Parser

If you want to write them to a file, you can add the `-o` option.
By default RML rules are generated,
if you want to generate R2RML rules add `-f R2RML`.
By default, the parser generates RML rules.
If you want to generate R2RML rules add `-f R2RML`.
If you want to use `rr:class` instead of Predicate Object Maps, use the `-c` flag.
You can use multiple input files too: `yarrrml-parser -i rules-1.yml -i rules-2.yml`.
They are converted to a single RML document.
Note that the keys in `prefixes`, `sources`, and `mappings` have to be unique across all files.
`base` can only be set once.
You find an [`test/multiple-input-files`](test/multiple-input-files).
You can overwrite external references via the `-e`.
An external reference starts with `_`.
For example, `-e name=John` will replace all occurrences of `$(_name)` with `John`.
Repeat `-e` for multiple references.
When you do not provide a value for an external reference,
the reference will not be replaced.
You find an example in [`test/template-escape`](test/template-escape).
If you want to use for example `$(_name)` as both an external reference and a normal reference,
then you add a `\` for the latter resulting in `$(\_name)` for the latter.

@@ -36,3 +51,3 @@ #### yarrrml-generator

```
```javascript
let yarrrml = require('@rmlio/yarrrml-parser/lib/rml-generator');

@@ -54,3 +69,18 @@

## Docker
Run (from [DockerHub](https://hub.docker.com/repository/docker/rmlio/yarrrml-parser)):
```bash
docker run --rm -it -v $(pwd)/resources:/data rmlio/yarrrml-parser:latest -i /data/test.yarrr.yml
```
Build from source:
```bash
docker build -t umids/yarrrml-parser .
```
## License
This code is copyrighted by [Ghent University – imec](http://idlab.ugent.be/) and released under the [MIT license](http://opensource.org/licenses/MIT).

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc