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.3.1 to 1.3.2

lib/tools.test.js

21

bin/parser.js

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

const Y2R2 = require('../lib/r2rml-generator.js');
const { canonicalize } = require('../lib/tools');
const pkginfo = require('pkginfo');

@@ -42,4 +43,5 @@ const N3 = require('n3');

program.option('-w, --watch', 'watch for file changes');
program.option('-p, --pretty', 'output prettified triples');
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.option('-m, --skip-metadata', 'skip metadata in generated rules');
program.parse(process.argv);

@@ -74,3 +76,3 @@

const yarrrml = fs.readFileSync(p, 'utf8');
inputData.push({yarrrml, file: p});
inputData.push({ yarrrml, file: p });
}

@@ -103,6 +105,6 @@

const includeMetadata =!(!!options.skipMetadata);
const includeMetadata = !(!!options.skipMetadata);
if (!options.format || options.format === 'RML') {
const y2r = new Y2R({class: !!options.class, externalReferences, includeMetadata});
const y2r = new Y2R({ class: !!options.class, externalReferences, includeMetadata });
triples = y2r.convert(inputData);

@@ -115,3 +117,3 @@

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

@@ -122,6 +124,9 @@ prefixes[''] = y2r.getBaseIRI();

const writer = new N3.Writer({prefixes});
const writer = new N3.Writer({ prefixes });
writer.addQuads(triples);
writer.end((error, result) => {
writer.end(async (error, result) => {
if (options.pretty) {
result = await canonicalize(result);
}
if (options.output) {

@@ -133,3 +138,3 @@ if (!path.isAbsolute(options.output)) {

try {
fs.writeFileSync(options.output, result);
await fs.promises.writeFile(options.output, result);
} catch (e) {

@@ -136,0 +141,0 @@ Logger.error(`The RML could not be written to the output file ${options.output}`);

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

## [1.3.2] - 2021-09-29
### Added
- `pretty` parameter for pretty output
### Fixed
- Help text of CLI
- Object type 'iri' discarded as of second source in a mapping that has multiple sources (see [issue 137](https://github.com/RMLio/yarrrml-parser/issues/137))
## [1.3.1] - 2021-08-11

@@ -225,2 +234,3 @@

[1.3.2]: https://github.com/RMLio/yarrrml-parser/compare/v1.3.1...v1.3.2
[1.3.1]: https://github.com/RMLio/yarrrml-parser/compare/v1.3.0...v1.3.1

@@ -227,0 +237,0 @@ [1.3.0]: https://github.com/RMLio/yarrrml-parser/compare/v1.2.3...v1.3.0

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

generateMapping(tmSubject, mapping, mappingName, sourceSubject, targetsIRIMap) {
this.quads.push(quad(

@@ -146,0 +145,0 @@ tmSubject,

@@ -137,3 +137,3 @@ /**

if (typeof source == 'object' && source.security && source.security == 'none' ) {
if (typeof source == 'object' && source.security && source.security === 'none' ) {
source.security = [ { type: 'none'} ]

@@ -140,0 +140,0 @@ } else if (typeof mapping.sources === 'string') {

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

generateMapping(tmSubject, mapping, mappingName, sourceSubject, targetsIRIMap) {
mapping = JSON.parse(JSON.stringify(mapping));
this.quads.push(quad(

@@ -346,3 +347,3 @@ tmSubject,

break
case 'write':

@@ -405,3 +406,3 @@ default:

});
}
}

@@ -408,0 +409,0 @@ this.quads.push(quad(

@@ -312,2 +312,6 @@ /**

it('multiple sources', function (done) {
work('multiple-sources/mapping.yarrrml', 'multiple-sources/mapping.rml.ttl', done, {includeMetadata: false});
});
describe('external references', function () {

@@ -314,0 +318,0 @@ const options = {includeMetadata: false};

@@ -5,3 +5,2 @@ const assert = require('assert');

const fs = require("fs");
const path = require('path');
const N3 = require("n3");

@@ -15,6 +14,11 @@ const makeReadable = require("./readable-rml.js").makeReadable;

rdfExt.parsers['text/turtle'] = N3Parser;
rdfExt.serializers['application/json+ld'] = new JsonLdSerializerExt({outputFormat: 'string'});
const {isomorphic} = require("rdf-isomorphic");
rdfExt.serializers['application/json+ld'] = new JsonLdSerializerExt({ outputFormat: 'string' });
const { isomorphic } = require("rdf-isomorphic");
const Logger = require('./logger');
const ttlRead = require('@graphy/content.ttl.read');
const ttlWrite = require('@graphy/content.ttl.write');
const dataset = require('@graphy/memory.dataset.fast');
const { Readable } = require('stream')
function compareY2RFiles(ymlPaths, ttlPath, options, cb) {

@@ -29,3 +33,3 @@ const yamls = [];

const yarrrml = fs.readFileSync(ymlPath, 'utf8');
yamls.push({yarrrml});
yamls.push({ yarrrml });
}

@@ -56,3 +60,3 @@

} catch (e) {
assert.deepStrictEqual(yamlQuads,rmlQuads);
assert.deepStrictEqual(yamlQuads, rmlQuads);
assert(false, true);

@@ -97,3 +101,3 @@ }

}
let writer = new N3.Writer({prefixes});
let writer = new N3.Writer({ prefixes });
makeReadable(triples, writer);

@@ -104,5 +108,31 @@ compareY2RFiles

/**
* Create a pretty-printed turtle string from an ugly turtle string
* @param {*} ttlString
* @returns
*/
async function canonicalize(ttlString) {
const stream = Readable.from([ttlString]);
const outStreamPretty = stream
.pipe(ttlRead())
.pipe(dataset({
canonicalize: false,
}))
.pipe(ttlWrite());
return streamToString(outStreamPretty);
}
function streamToString(stream) {
const chunks = [];
return new Promise((resolve, reject) => {
stream.on('data', (chunk) => chunks.push(Buffer.from(chunk)));
stream.on('error', (err) => reject(err));
stream.on('end', () => resolve(Buffer.concat(chunks).toString('utf8')));
})
}
module.exports = {
canonicalize,
compareY2RFiles,
compareY2R2RFiles,
};
{
"name": "@rmlio/yarrrml-parser",
"version": "1.3.1",
"version": "1.3.2",
"description": "Parse YARRRML descriptions into RML RDF statements",

@@ -21,7 +21,9 @@ "main": "lib/yarrrml2rml.js",

"dependencies": {
"commander": "^7.2.0",
"@rdfjs/serializer-jsonld-ext": "^2.0.0",
"commander": "^8.1.0",
"extend": "^3.0.2",
"glob": "^7.1.6",
"graphy": "^4.3.3",
"js-logger": "^1.6.1",
"n3": "^1.8.0",
"n3": "^1.11.1",
"parse-author": "^2.0.0",

@@ -31,10 +33,9 @@ "pkginfo": "^0.4.1",

"q": "^1.5.1",
"rdf-ext": "^1.3.1",
"rdf-isomorphic": "^1.2.0",
"rdf-ext": "^1.3.5",
"rdf-isomorphic": "^1.3.0",
"rdf-parser-n3": "^1.1.0",
"@rdfjs/serializer-jsonld-ext": "^2.0.0",
"yamljs": "^0.3.0"
},
"devDependencies": {
"mocha": "^8.1.3"
"mocha": "^9.1.1"
},

@@ -41,0 +42,0 @@ "bin": {

@@ -20,7 +20,11 @@ # YARRRML Parser

you do the following: `yarrrml-parser -i rules.yml`.
The rules will be written to standard output.
If you want to write them to a file, you can add the `-o` option.
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`.

@@ -30,3 +34,4 @@ They are converted to a single RML document.

`base` can only be set once.
You find an [`test/multiple-input-files`](test/multiple-input-files).
You find an example at [`test/multiple-input-files`](test/multiple-input-files).
You can overwrite external references via the `-e`.

@@ -42,2 +47,4 @@ An external reference starts with `_`.

If you want the outputted RML to be pretty, please provide the `-p` or `--pretty` parameter.
#### yarrrml-generator

@@ -44,0 +51,0 @@

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