Skip to content

Commit

Permalink
v1.2.0 (#90)
Browse files Browse the repository at this point in the history
* Add Dockerfile to run yarrrml-parser using Docker. Also added short instructions to build and run to the readme

* Add DockerHub URL to readme

* now Dockerfile build from current folder instead of installing from npm. Updated readme.

* add .dockerignore to avoid copying node_modules when docker build

* fixes #73

* Delete generator.test.js

* nit

* readme error

* fix #75

* add action.yml to use YARRRML parser as GitHub action

* action is now dockerfile instead of node

* wip #59

* add more test cases

* update changelog

* fix #37

* fix #78

* Allow multiple input files (#80)

fix #34

Co-authored-by: Ben De Meester <Ben.DeMeester@UGent.be>

* Fix #35 (#84)

fix #35

* fix remarks

* Fix #31 (#86)

fix #31

* Fix #87 (#88)

fix #87

* v1.2.0 (#89)

v1.2.0

Co-authored-by: Vincent Emonet <vincent.emonet@gmail.com>
Co-authored-by: Ben De Meester <Ben.DeMeester@UGent.be>
  • Loading branch information
3 people authored Aug 17, 2020
1 parent 6e4f3c5 commit 8a47e47
Show file tree
Hide file tree
Showing 136 changed files with 6,302 additions and 2,990 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## Unreleased

## [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

### Fixed
Expand Down Expand Up @@ -160,6 +178,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- fix failing test
- support for recursive functions

[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
[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
Expand Down
10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM node:12-alpine

WORKDIR /app

ADD . .

RUN npm install -g .

ENTRYPOINT ["yarrrml-parser"]
CMD ["-h"]
36 changes: 33 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,23 @@ If you want to generate RML rules from a YARRRML document,
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 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.

#### yarrrml-generator

Expand All @@ -32,7 +47,7 @@ If you want to write them to a file, you can add the `-o` option.

`npm i --save @rmlio/yarrrml-parser`

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

const yaml = "[yarrrml string]";
Expand All @@ -49,5 +64,20 @@ const triples = y2r.convert(yaml);
- Make the [CLI](#cli) (based on the code in the cloned repo)
available system-wide via `npm link` (optional).

## 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).
32 changes: 32 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# GitHub Actions to run the RML Mapper
name: 'YARRRML Parser'
description: 'Convert YARRRML rules to RML rules using the YARRRML Parser.'
branding:
icon: 'edit-3'
color: 'blue'
inputs:
input:
description: 'Input YARRRML file to convert to RML'
required: true
default: 'input.yarrr.yml'
output:
description: 'Path to output file'
required: true
default: 'output.rml.ttl'
format:
description: 'RML or R2RML (default: RML)'
required: false
default: 'RML'
outputs:
rml_output:
description: 'RML rules generated from the YARRRML rules.'
runs:
using: 'docker'
image: 'Dockerfile'
args:
- "--input"
- ${{ inputs.input }}
- "--output"
- ${{ inputs.output }}
- "--format"
- ${{ inputs.format }}
64 changes: 54 additions & 10 deletions bin/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,60 @@ const pkginfo = require('pkginfo');
const N3 = require('n3');
const namespaces = require('prefix-ns').asMap();
const watch = require('../lib/watcher.js');
const glob = require('glob');

namespaces.ql = 'http://semweb.mmlab.be/ns/ql#';

pkginfo(module, 'version');

/**
* 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);
}
}

if (!program.watch) {
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) {
program.format = program.format.toUpperCase();
Expand All @@ -49,19 +81,31 @@ if (!program.input) {
rdfs: namespaces.rdfs,
fnml: "http://semweb.mmlab.be/ns/fnml#",
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);

prefixes.rml = namespaces.rml;
prefixes.ql = namespaces.ql;
prefixes[''] = y2r.getBaseIRI();
prefixes = Object.assign({}, prefixes, y2r.getPrefixes());
} else {
const y2r = new Y2R2();
const y2r = new Y2R2({class: !!program.class, externalReferences, includeMetadata});
triples = y2r.convert(inputData);
prefixes[''] = y2r.getBaseIRI();
prefixes = Object.assign({}, prefixes, y2r.getPrefixes());
Expand Down
Loading

0 comments on commit 8a47e47

Please sign in to comment.