@rmlio/rmlmapper-java-wrapper
Advanced tools
Comparing version 1.2.0 to 2.0.0
@@ -10,2 +10,7 @@ # Changelog | ||
## [2.0.0] - 2021-06-28 | ||
### Added | ||
- Support Target | ||
## [1.2.0] - 2021-05-03 | ||
@@ -75,2 +80,3 @@ | ||
[2.0.0]: https://github.com/RMLio/rmlmapper-java-wrapper-js/compare/v1.2.0...v2.0.0 | ||
[1.2.0]: https://github.com/RMLio/rmlmapper-java-wrapper-js/compare/v1.1.1...v1.2.0 | ||
@@ -77,0 +83,0 @@ [1.1.1]: https://github.com/RMLio/rmlmapper-java-wrapper-js/compare/v1.1.0...v1.1.1 |
@@ -187,4 +187,38 @@ /** | ||
}); | ||
}); | ||
it('Single target', async () => { | ||
const wrapper = new RMLMapperWrapper(rmlmapperPath, tempFolderPath, true); | ||
const rml = fs.readFileSync('./test/tc06/mapping.ttl', 'utf-8'); | ||
const sources = { | ||
'student.csv': fs.readFileSync('./test/tc06/student.csv', 'utf-8') | ||
}; | ||
let result = await wrapper.execute(rml, {sources, generateMetadata: false, asQuads: true}); | ||
assert.deepStrictEqual(result.output.stdout, []); | ||
result = await strToQuads(result.output['dump1.nt']); | ||
const expected = await strToQuads(fs.readFileSync('./test/tc06/output.nq', 'utf-8')); | ||
assert.ok(isomorphic(result, expected)); | ||
}); | ||
it('Two targets', async () => { | ||
const wrapper = new RMLMapperWrapper(rmlmapperPath, tempFolderPath, true); | ||
const rml = fs.readFileSync('./test/tc07/mapping.ttl', 'utf-8'); | ||
const sources = { | ||
'student.csv': fs.readFileSync('./test/tc07/student.csv', 'utf-8') | ||
}; | ||
let result = await wrapper.execute(rml, {sources, generateMetadata: false, asQuads: true}); | ||
assert.deepStrictEqual(result.output.stdout, []); | ||
const result1 = await strToQuads(result.output['dump1.nt']); | ||
const expected1 = await strToQuads(fs.readFileSync('./test/tc07/output-1.nq', 'utf-8')); | ||
assert.ok(isomorphic(result1, expected1)); | ||
const result2 = await strToQuads(result.output['dump2.nt']); | ||
const expected2 = await strToQuads(fs.readFileSync('./test/tc07/output-2.nq', 'utf-8')); | ||
assert.ok(isomorphic(result2, expected2)); | ||
}); | ||
}); |
@@ -11,7 +11,8 @@ /** | ||
const {DataFactory, Parser, Writer} = N3; | ||
const {literal, quad} = DataFactory; | ||
const {literal, quad, namedNode} = DataFactory; | ||
const newQuad = quad; | ||
const {strToQuads} = require('./utils'); | ||
const sourceFilePrefix = "data-"; | ||
const sourceFilePrefix = 'data-'; | ||
const targetFilePrefix = 'target-'; | ||
@@ -70,8 +71,9 @@ class RMLMapperWrapper { | ||
// folder where the data used by the RMLMapper is stored | ||
const processDir = path.resolve(this.tempFolder, '' + ms); | ||
const processDir = path.join(this.tempFolder, '' + ms); | ||
await fs.mkdir(processDir); | ||
const logFile = path.resolve(processDir, 'rmlmapper.log'); | ||
const sourceDirPrefix = path.resolve(processDir, sourceFilePrefix); | ||
const logFile = path.join(processDir, 'rmlmapper.log'); | ||
const sourceDirPrefix = path.join(processDir, sourceFilePrefix); | ||
const targetDirPrefix = path.join(processDir, targetFilePrefix); | ||
@@ -87,3 +89,4 @@ if (options.sources) { | ||
generateMetadata: options.generateMetadata, | ||
fno: options.fno | ||
fno: options.fno, | ||
targetDirPrefix | ||
}); | ||
@@ -98,14 +101,17 @@ resolve(result) | ||
async _executeCLI(options) { | ||
const {rml, sourceDirPrefix, processDir, logFile, serialization, asQuads, generateMetadata, fno} = options; | ||
const mappingFile = path.resolve(processDir, 'mapping.rml.ttl'); | ||
let {rml, sourceDirPrefix, processDir, logFile, serialization, asQuads, generateMetadata, fno, targetDirPrefix} = options; | ||
const mappingFile = path.join(processDir, 'mapping.rml.ttl'); | ||
let functionsFile; | ||
const result = this._updateTargetsWithLocalFiles({rmlQuads: rml, dirPrefix: targetDirPrefix}); | ||
rml = result.rml; | ||
const targetFiles = result.targetFiles; | ||
const rmlStr = await this._setSourcesInRMLRules(rml, sourceDirPrefix); | ||
await fs.writeFile(mappingFile, rmlStr); | ||
const outputFile = path.resolve(processDir, "output." + serialization); | ||
const metadataFile = path.resolve(processDir, "metadata." + serialization); | ||
const outputFile = path.join(processDir, "output." + serialization); | ||
const metadataFile = path.join(processDir, "metadata." + serialization); | ||
if (fno) { | ||
functionsFile = path.resolve(processDir, 'functions.ttl'); | ||
functionsFile = path.join(processDir, 'functions.ttl'); | ||
const fnoWriter = new Writer({format: 'text/turtle'}); | ||
@@ -116,3 +122,2 @@ const fnoStr = fnoWriter.quadsToString(fno); | ||
let execCommand = `java `; | ||
@@ -150,2 +155,20 @@ | ||
const targets = {}; | ||
for (let i = 0; i < targetFiles.length; i++){ | ||
const file = targetFiles[i]; | ||
try { | ||
targets[path.basename(file).replace(targetFilePrefix, '')] = await fs.readFile(file, 'utf8'); | ||
} catch (targetError) { | ||
targetError.message = `Error while reading target file '${file}'`; | ||
reject(targetError); | ||
} | ||
} | ||
if (targetFiles.length > 0) { | ||
targets.stdout = output; | ||
output = targets; | ||
} | ||
if (generateMetadata) { | ||
@@ -190,3 +213,3 @@ try { | ||
async _saveSource(names, index, sources, prefix) { | ||
return new Promise((resolve, reject) => { | ||
return new Promise(async (resolve, reject) => { | ||
const self = this; | ||
@@ -204,9 +227,8 @@ | ||
if (typeof sources[names[index]] === 'string') { | ||
fs.writeFile(prefix + names[index], sources[names[index]], (err) => { | ||
if (err) { | ||
reject(err); | ||
} | ||
try { | ||
await fs.writeFile(prefix + names[index], sources[names[index]]); | ||
done(); | ||
}); | ||
} catch (err) { | ||
reject(err); | ||
} | ||
} else { | ||
@@ -282,4 +304,47 @@ reject(new Error(`The source with name "${names[index]}" is not string.`)); | ||
} | ||
_updateTargetsWithLocalFiles(options = {}) { | ||
let {rmlQuads, dirPrefix} = options; | ||
const targetFiles = []; | ||
if (!rmlQuads) { | ||
throw new Error('RML quads are missing.'); | ||
} | ||
if (!dirPrefix) { | ||
throw new Error('Directory prefix is missing.'); | ||
} | ||
if (!path.isAbsolute(dirPrefix)) { | ||
dirPrefix = path.join(process.cwd(), dirPrefix); | ||
} | ||
const store = new N3.Store(); | ||
store.addQuads(rmlQuads); | ||
const logicalTargetNodes = store.getObjects(null, namedNode('http://semweb.mmlab.be/ns/rml#logicalTarget')); | ||
logicalTargetNodes.forEach(logicalTargetNode => { | ||
const targetNodes = store.getObjects(logicalTargetNode, namedNode('http://semweb.mmlab.be/ns/rml-target#target')); | ||
if (targetNodes.length > 0) { | ||
const targetNode = targetNodes[0]; | ||
const dataDumps = store.getObjects(targetNode, namedNode('http://rdfs.org/ns/void#dataDump')); | ||
if (dataDumps.length > 0) { | ||
const filename = path.basename(dataDumps[0].value); | ||
const p = dirPrefix + filename; | ||
store.addQuad(targetNode, namedNode('http://rdfs.org/ns/void#dataDump'), literal('file://' + p)); | ||
store.removeQuad(targetNode, namedNode('http://rdfs.org/ns/void#dataDump'), dataDumps[0]); | ||
targetFiles.push(p); | ||
} | ||
} | ||
}); | ||
return {rml: store.getQuads(), targetFiles}; | ||
} | ||
} | ||
module.exports = RMLMapperWrapper; |
{ | ||
"name": "@rmlio/rmlmapper-java-wrapper", | ||
"version": "1.2.0", | ||
"version": "2.0.0", | ||
"description": "A JavaScript wrapper around the Java RMLMapper.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
594433
41
531