Skip to content
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

Output Format #29

Closed
venkateshzifo opened this issue Apr 22, 2019 · 8 comments
Closed

Output Format #29

venkateshzifo opened this issue Apr 22, 2019 · 8 comments

Comments

@venkateshzifo
Copy link

Hi,

How to set the output format using the java code. I am getting the output as RDF triples now. I would like to get the output as JSON-LD. I would like to do this from the code. Do we need to define it somewhere with executor object ? Could you please help me on this ?

@bjdmeest
Copy link
Collaborator

Hi,

The executor.execute-command returns a QuadStore, which has a write method that takes the format as one of the parameters. For example, the snippet below writes the output as jsonld to stdout.

QuadStore result = executor.execute(triplesMaps, checkOptionPresence(removeduplicatesOption, lineArgs, configFile), metadataGenerator);
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
result.write(out, "jsonld");

Does this help?

@venkateshzifo
Copy link
Author

Thanks for the response.

Yeah that's what I am looking for. But its not working

It throws Serialization jsonld not supported when I try to write the output as jsonld.

@bjdmeest
Copy link
Collaborator

Ah, could it be that you are using a SimpleQuadStore instead of a RDF4JStore when creating the Executor?

Executor executor = new Executor(rmlStore, factory, functionLoader, outputStore, Utils.getBaseDirectiveTurtle(is));

The outputStore of this line should be an RDF4JStore.

@venkateshzifo
Copy link
Author

venkateshzifo commented Apr 23, 2019

I am using below code snippet. I am using RDF4JStore only.

                InputStream mappingStream = new FileInputStream(mappingFile);

		Model model = Rio.parse(mappingStream, "", RDFFormat.TURTLE);

		RDF4JStore outputStore = new RDF4JStore(model);

		Executor executor = new Executor(outputStore, new RecordsFactory(new DataFetcher(cwd, outputStore)));

		QuadStore chromResult = executor.execute(executor.getTriplesMaps());

		chromResult.removeDuplicates();

		BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
		
                chromResult.write(out, "jsonld");`

@bjdmeest
Copy link
Collaborator

Ah, yes, there's a bit of confusion here: you need QuadStore for your RML mapping, and a second QuadStore for your output data. You can check https://github.com/RMLio/rmlmapper-java/blob/master/src/main/java/be/ugent/rml/cli/Main.java for more details, but I guess you need something along the lines of

// Read mapping file
InputStream mappingStream = new FileInputStream(mappingFile);
Model model = Rio.parse(mappingStream, "", RDFFormat.TURTLE);
RDF4JStore rmlStore= new RDF4JStore(model);
// Load functions
FunctionLoader functionLoader = new FunctionLoader(null, null, new HashMap<>());
// Prepare output store
RDF4JStore outputStore = new RDF4JStore();
// Create executor
Executor executor = new Executor(rmlStore, new RecordsFactory(new DataFetcher(cwd, rmlStore)),functionLoader, outputStore, Utils.getBaseDirectiveTurtle(mappingStream ));
// Execute
QuadStore chromResult = executor.execute(executor.getTriplesMaps());
chromResult.removeDuplicates();
// Write result
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
chromResult.write(out, "jsonld");`

@venkateshzifo
Copy link
Author

I am facing new problem with this code. Utils.getBaseDirectiveTurtle is not available method in Utils class. Is this from be.ugent.rml.Utils class ?

@bjdmeest
Copy link
Collaborator

@venkateshzifo
Copy link
Author

Thanks, It worked, the problem is, I was using older jar. Thanks for helping out :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants