-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
YARRRML supported? #20
Comments
Hi! You should be able to use the yarrrml-parser (https://github.com/RMLio/yarrrml-parser) with this lib. I have been doing something like this to convert yarrrml to rml/turtle: import { Writer as N3Writer } from 'n3';
import YarrrmlParser from '@rmlio/yarrrml-parser/lib/rml-generator.js';
import rocketrml from 'rocketrml';
const yarrrmlParse = (yaml) =>
new Promise((resolve) => {
const y2r = new YarrrmlParser();
const yamlQuads = y2r.convert(yaml);
let prefixes = {
rr: 'http://www.w3.org/ns/r2rml#',
rml: 'http://semweb.mmlab.be/ns/rml#',
xsd: 'http://www.w3.org/2001/XMLSchema#',
schema: 'http://schema.org/',
rdf: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
rdfs: 'http://www.w3.org/2000/01/rdf-schema#',
fnml: 'http://semweb.mmlab.be/ns/fnml#',
fno: 'http://w3id.org/function/ontology#',
mex: 'http://mapping.example.com/',
};
prefixes = { ...prefixes, ...y2r.getPrefixes() };
const writer = new N3Writer({ prefixes });
writer.addQuads(yamlQuads);
writer.end((_, result) => {
resolve(result);
});
});
(async () => {
const yarrrml = `
prefixes:
ex: "http://example.com/"
mappings:
person:
sources:
- ['data.json~jsonpath', '$.persons[*]']
s: http://example.com/$(firstname)
po:
- [a, foaf:Person]
- [ex:name, $(firstname)]
`
const rml = await yarrrmlParse(yarrrml);
const jsonld = await rocketrml.parseFileLive(rml, {
'data.json': JSON.stringify({
"persons": [
{
"firstname": "John",
"lastname": "Doe"
},
{
"firstname": "Jane",
"lastname": "Smith"
},
{
"firstname": "Sarah",
"lastname": "Bladinck"
}
]
})
})
console.log(jsonld);
})(); |
Great, thank you! This is exactly what I want to do... except I want to use the library in the browser. However, I see that it uses the Node.js fs module so it is not client javascript compatible. Do you have any advice if I need to run this in the browser? |
It is possible to run rocktrml&yarrrml-parser in the browser, that is what we do here: https://github.com/semantifyit/rml-editor The So, you should be able to use parseFileLive in the browser (just as we do here: https://github.com/semantifyit/rml-editor/blob/e15e5964023ef5d88e9faa485ea5d0d58d54538d/src/rmlmapper.ts#L139) |
Thanks for the reply. I see what you did there and
|
Ah I see, yes that's tricky. I'm afraid there is no easy way to fix that. Depending on your exact vue (or webpack) setup, it might still be possible. I tried a bit around with nuxt and the following worked for me: in nuxt.config.js ...
build: {
extend (config, { isDev, isClient }) {
config.node = {
fs: 'empty', // to ignore fs
}
},
plugins: [
new webpack.IgnorePlugin({ resourceRegExp: /^/u, contextRegExp: /xpath-iterator/u }) // to ignore xpath-iterator package, which is a optional packages that uses nodejs c++ addon
],
},
... With this I am able to run the code sample from #20 (comment) in the browser with vue/nuxt. |
Incredible, it worked like a charm! Thank you. I will see if I can get it to work with the latest version of |
I got it working with Nuxt by adding the following to
In case it might help anyone, the full config to get both
|
@ThibaultGerrier It feels a bit silly and wasteful to turn Yarrrml's quads into Turtle and have RocketRML re-parse it. Is there a lower-level API that could accept RML as |
@Peeja I agree. RocketRML spends a lot of cycles parsing the RML. I often thought it would be useful if I could pre-parse the RML, and present the "compiled" RML to "the rocket" and skip the parsing altogether. |
❓ Question
Does this library support YARRRML out of the box? Or do I need yarrrml-parser?
The text was updated successfully, but these errors were encountered: