@rmlio/yarrrml-parser
Advanced tools
Comparing version 1.3.1 to 1.3.2
@@ -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 @@ |
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
554677
280
5587
96
15
+ Addedgraphy@^4.3.3
+ Added@graphy/content.nq.read@4.3.7(transitive)
+ Added@graphy/content.nq.scan@4.3.7(transitive)
+ Added@graphy/content.nq.scribe@4.3.7(transitive)
+ Added@graphy/content.nq.write@4.3.7(transitive)
+ Added@graphy/content.nt.read@4.3.7(transitive)
+ Added@graphy/content.nt.scan@4.3.7(transitive)
+ Added@graphy/content.nt.scribe@4.3.7(transitive)
+ Added@graphy/content.nt.write@4.3.7(transitive)
+ Added@graphy/content.trig.read@4.3.7(transitive)
+ Added@graphy/content.trig.scribe@4.3.7(transitive)
+ Added@graphy/content.trig.write@4.3.7(transitive)
+ Added@graphy/content.ttl.read@4.3.7(transitive)
+ Added@graphy/content.ttl.scribe@4.3.7(transitive)
+ Added@graphy/content.ttl.write@4.3.7(transitive)
+ Added@graphy/content.xml.scribe@4.3.7(transitive)
+ Added@graphy/core.class.scribable@4.3.7(transitive)
+ Added@graphy/core.class.writable@4.3.7(transitive)
+ Added@graphy/core.data.factory@4.3.7(transitive)
+ Added@graphy/core.iso.stream@4.3.7(transitive)
+ Added@graphy/core.iso.threads@4.3.7(transitive)
+ Added@graphy/memory.dataset.fast@4.3.7(transitive)
+ Added@graphy/util.dataset.tree@4.3.7(transitive)
+ Added@types/node@22.9.1(transitive)
+ Addedansi-regex@5.0.1(transitive)
+ Addedansi-styles@4.3.0(transitive)
+ Addedbig-integer@1.6.52(transitive)
+ Addedbkit@2.1.3(transitive)
+ Addedcamelcase@5.3.1(transitive)
+ Addedchalk@4.1.2(transitive)
+ Addedcliui@6.0.0(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addedcommander@8.3.0(transitive)
+ Addeddecamelize@1.2.0(transitive)
+ Addedemoji-regex@8.0.0(transitive)
+ Addedfind-up@4.1.0(transitive)
+ Addedget-caller-file@2.0.5(transitive)
+ Addedgraphy@4.3.7(transitive)
+ Addedhas-flag@4.0.0(transitive)
+ Addedis-fullwidth-code-point@3.0.0(transitive)
+ Addedlocate-path@5.0.0(transitive)
+ Addedn3@1.23.0(transitive)
+ Addedp-limit@2.3.0(transitive)
+ Addedp-locate@4.1.0(transitive)
+ Addedp-try@2.2.0(transitive)
+ Addedpath-exists@4.0.0(transitive)
+ Addedpegjs@0.10.0(transitive)
+ Addedrequire-directory@2.1.1(transitive)
+ Addedrequire-main-filename@2.0.0(transitive)
+ Addedset-blocking@2.0.0(transitive)
+ Addedstring-width@4.2.3(transitive)
+ Addedstrip-ansi@6.0.1(transitive)
+ Addedsupports-color@7.2.0(transitive)
+ Addedundici-types@6.19.8(transitive)
+ Addedwhich-module@2.0.1(transitive)
+ Addedwrap-ansi@6.2.0(transitive)
+ Addedy18n@4.0.3(transitive)
+ Addedyargs@15.4.1(transitive)
+ Addedyargs-parser@18.1.3(transitive)
- Removed@types/node@22.10.0(transitive)
- Removedcommander@7.2.0(transitive)
- Removedn3@1.23.1(transitive)
- Removedundici-types@6.20.0(transitive)
Updatedcommander@^8.1.0
Updatedn3@^1.11.1
Updatedrdf-ext@^1.3.5
Updatedrdf-isomorphic@^1.3.0