Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@rmlio/yarrrml-parser

Package Overview
Dependencies
Maintainers
2
Versions
49
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.0.2 to 1.1.0

.github/ISSUE_TEMPLATE/question.md

12

CHANGELOG.md

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

## [1.1.0] - 2020-04-02
### Added
- Issue template for question (see [issue 48](https://github.com/RMLio/yarrrml-parser/issues/48))
- Explain how to install locally for development (see [issue 45](https://github.com/RMLio/yarrrml-parser/issues/45))
- Add function shortcut (see [issue 57](https://github.com/RMLio/yarrrml-parser/issues/57))
### Fixed
- Function with empty parameter list works, but without parameters doesn't get parsed properly (see [issue 53](https://github.com/RMLio/yarrrml-parser/issues/53))
- Add quotes around rules specific part in error/warning message (see [issue 52](https://github.com/RMLio/yarrrml-parser/issues/52))
## [1.0.2] - 2020-01-17

@@ -147,2 +158,3 @@

[1.1.0]: https://github.com/RMLio/yarrrml-parser/compare/v1.0.2...v1.1.0
[1.0.2]: https://github.com/RMLio/yarrrml-parser/compare/v1.0.1...v1.0.2

@@ -149,0 +161,0 @@ [1.0.1]: https://github.com/RMLio/yarrrml-parser/compare/v1.0.0...v1.0.1

148

lib/abstract-generator.js

@@ -410,95 +410,97 @@ /**

o.parameters.forEach(pm => {
const pomSubject = namedNode(this.baseIRI + this.getUniqueID('pom'));
const pmSubject = namedNode(this.baseIRI + this.getUniqueID('pm'));
const omSubject = namedNode(this.baseIRI + this.getUniqueID('om'));
if (o.parameters) {
o.parameters.forEach(pm => {
const pomSubject = namedNode(this.baseIRI + this.getUniqueID('pom'));
const pmSubject = namedNode(this.baseIRI + this.getUniqueID('pm'));
const omSubject = namedNode(this.baseIRI + this.getUniqueID('om'));
this.quads.push(quad(
fnSubject,
namedNode(namespaces.rr + 'predicateObjectMap'),
pomSubject
));
this.quads.push(quad(
fnSubject,
namedNode(namespaces.rr + 'predicateObjectMap'),
pomSubject
));
this.quads.push(quad(
pomSubject,
namedNode(namespaces.rdf + 'type'),
namedNode(namespaces.rr + 'PredicateObjectMap')
));
this.quads.push(quad(
pomSubject,
namedNode(namespaces.rdf + 'type'),
namedNode(namespaces.rr + 'PredicateObjectMap')
));
this.quads.push(quad(
pomSubject,
namedNode(namespaces.rr + 'predicateMap'),
pmSubject
));
this.quads.push(quad(
pomSubject,
namedNode(namespaces.rr + 'predicateMap'),
pmSubject
));
this.quads.push(quad(
pmSubject,
namedNode(namespaces.rdf + 'type'),
namedNode(namespaces.rr + 'PredicateMap')
));
this.quads.push(quad(
pmSubject,
namedNode(namespaces.rdf + 'type'),
namedNode(namespaces.rr + 'PredicateMap')
));
const {predicate, object} = this.getAppropriatePredicateAndObjectForValue(pm.parameter, true);
const {predicate, object} = this.getAppropriatePredicateAndObjectForValue(pm.parameter, true);
this.quads.push(quad(
pmSubject,
predicate,
object
));
this.quads.push(quad(
pmSubject,
predicate,
object
));
this.quads.push(quad(
pomSubject,
namedNode(namespaces.rr + 'objectMap'),
omSubject
));
this.quads.push(quad(
pomSubject,
namedNode(namespaces.rr + 'objectMap'),
omSubject
));
this.quads.push(quad(
omSubject,
namedNode(namespaces.rdf + 'type'),
namedNode(namespaces.rr + 'ObjectMap')
));
if (pm.from === 'subject') {
//get type: iri or literal
const {predicate, object} = this.getAppropriatePredicateAndObjectForValue(pm.value);
this.quads.push(quad(
omSubject,
predicate,
object
namedNode(namespaces.rdf + 'type'),
namedNode(namespaces.rr + 'ObjectMap')
));
if (pm.type === 'iri') {
if (pm.from === 'subject') {
//get type: iri or literal
const {predicate, object} = this.getAppropriatePredicateAndObjectForValue(pm.value);
this.quads.push(quad(
omSubject,
namedNode(namespaces.rr + 'termType'),
namedNode(namespaces.rr + 'IRI')
predicate,
object
));
if (pm.type === 'iri') {
this.quads.push(quad(
omSubject,
namedNode(namespaces.rr + 'termType'),
namedNode(namespaces.rr + 'IRI')
));
} else {
this.quads.push(quad(
omSubject,
namedNode(namespaces.rr + 'termType'),
namedNode(namespaces.rr + 'Literal')
));
}
} else if (pm.from === 'function') {
this.generateFunctionTermMap(omSubject, pm.value, sourceSubject);
} else {
const parentTermMapSubject = namedNode(this.baseIRI + this.getUniqueID('ptm'));
this.quads.push(quad(
omSubject,
namedNode(namespaces.rr + 'termType'),
namedNode(namespaces.rr + 'Literal')
namedNode(namespaces.rml + 'parentTermMap'),
parentTermMapSubject
));
}
} else if (pm.from === 'function') {
this.generateFunctionTermMap(omSubject, pm.value, sourceSubject);
} else {
const parentTermMapSubject = namedNode(this.baseIRI + this.getUniqueID('ptm'));
this.quads.push(quad(
omSubject,
namedNode(namespaces.rml + 'parentTermMap'),
parentTermMapSubject
));
const {predicate, object} = this.getAppropriatePredicateAndObjectForValue(pm.value);
const {predicate, object} = this.getAppropriatePredicateAndObjectForValue(pm.value);
this.quads.push(quad(
parentTermMapSubject,
predicate,
object
));
}
});
this.quads.push(quad(
parentTermMapSubject,
predicate,
object
));
}
});
}
}

@@ -615,3 +617,3 @@

} else {
console.error(`prefix ${splits[0]} was not found.`);
console.error(`prefix "${splits[0]}" was not found.`);
return str.replace(/@@@@____@@@@/g, ':');

@@ -618,0 +620,0 @@ }

@@ -52,3 +52,3 @@ /**

} else {
console.error(`mapping ${mappingKey}: no rules are provided. Skipping.`);
console.error(`mapping "${mappingKey}": no rules are provided. Skipping.`);
delete input.mappings[mappingKey];

@@ -122,6 +122,6 @@ }

} else {
console.error(`mapping ${mappingKey}: no (valid) source is defined.`);
console.error(`mapping "${mappingKey}": no (valid) source is defined.`);
}
} else {
console.error(`mapping ${mappingKey}: no source is defined.`);
console.error(`mapping "${mappingKey}": no source is defined.`);
}

@@ -179,3 +179,3 @@ }

} else {
console.error(`mapping ${mappingKey}: no pos are defined.`)
console.error(`mapping "${mappingKey}": no pos are defined.`)
}

@@ -206,3 +206,3 @@ }

if (!po.objects || po.objects.length === 0) {
console.error(`mapping ${mappingKey}: po with predicate(s) "${po.predicates}" does not have an object defined. Skipping.`);
console.error(`mapping "${mappingKey}": po with predicate(s) "${po.predicates}" does not have an object defined. Skipping.`);
predicateobjects.splice(i, 1);

@@ -301,2 +301,8 @@ i--;

if (input.function && isFunctionShortcut(input.function)) {
const result = expandFunctionShortcut(input.function);
input.function = result.function;
input.parameters = result.parameters;
}
if (input.parameters) {

@@ -349,2 +355,32 @@ for (let i = 0; i < input.parameters.length; i++) {

function isFunctionShortcut(str) {
return str.indexOf('(') !== -1 && str.indexOf(')') > str.indexOf('(');
}
function expandFunctionShortcut(functionStr) {
const fn = functionStr.substr(0, functionStr.indexOf('('));
const prefix = fn.substr(0, fn.indexOf(':'));
const parameterStr = functionStr.substr(functionStr.indexOf('(')+1, functionStr.length - functionStr.indexOf('(') - 2);
const parameters = parameterStr.split(',');
const temp = [];
parameters.forEach(p => {
const split = p.split('=');
let parameter = split[0].trim();
if (parameter.indexOf(':') === -1) {
parameter = prefix + ':' + parameter;
}
let value = split[1].trim();
if (value[0] === '"' && value[value.length - 1] === '"') {
value = value.substr(1, value.length - 2);
}
temp.push({value, parameter, from: 'subject', type: 'literal'});
});
return {function: fn, parameters: temp};
}
function expandGraphs(mapping) {

@@ -351,0 +387,0 @@ replaceAll('graphs', mapping);

@@ -598,2 +598,49 @@ /**

it('function shortcut', () => {
const input = {
mappings: {
person: {
predicateobjects: [
{
predicates: ['foaf:test'],
objects: [
{
function: 'ex:toLowerCase(input= $(firstname))'
}
]
}
]
}
}
};
const expectedOutput = {
mappings: {
person: {
predicateobjects: [
{
predicates: ['foaf:test'],
objects: [
{
function: 'ex:toLowerCase',
parameters: [
{
parameter: 'ex:input',
value: '$(firstname)',
type: 'literal',
from: 'subject'
}
]
}
]
}
]
}
}
};
const output = expand(input);
assert.deepStrictEqual(output, expectedOutput);
});
it('function on subject', () => {

@@ -629,3 +676,3 @@ const input = {

}
]
]
}

@@ -632,0 +679,0 @@ }

@@ -108,2 +108,14 @@ /**

it('function shortcut without prefix', function (done) {
work('function-shortcut-without-prefix/mapping.yml', 'function-shortcut-without-prefix/mapping.rml.ttl', done);
});
it('function shortcut with prefix', function (done) {
work('function-shortcut-with-prefix/mapping.yml', 'function-shortcut-with-prefix/mapping.rml.ttl', done);
});
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);
});
it('subject with function', function (done) {

@@ -160,2 +172,6 @@ work('subjectmap-with-function/mapping.yml', 'subjectmap-with-function/mapping.rml.ttl', done);

});
it('function without parameters', function (done) {
work('function-without-parameters/mapping.yarrrml', 'function-without-parameters/mapping.rml.ttl', done);
});
});

@@ -162,0 +178,0 @@

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

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

@@ -18,3 +18,3 @@ # YARRRML Parser

If you want to generate RML rules from a YARRRML document,
If you want to generate RML rules from a YARRRML document,
you do the following: `yarrrml-parser -i rules.yml`.

@@ -44,3 +44,12 @@ The rules will be written to standard output.

## Development
- Clone this repo.
- Install the dependencies via `npm i`
- Update code, if needed.
- Run the tests via `npm test`
- Make the [CLI](#cli) (based on the code in the cloned repo)
available system-wide via `npm link` (optional).
## License
This code is copyrighted by [Ghent University – imec](http://idlab.ugent.be/) and released under the [MIT license](http://opensource.org/licenses/MIT).
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