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

Add the ability to save RDF models #17

Open
agarciadom opened this issue Dec 13, 2024 · 4 comments
Open

Add the ability to save RDF models #17

agarciadom opened this issue Dec 13, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@agarciadom
Copy link
Member

At the moment, the driver can only read RDF documents. At some point we need to add the ability to create new RDF resources, link them together, add properties, and save back the result.

This would probably have to wait until we have thought out the MOF2RDF mapping.

@agarciadom agarciadom added the enhancement New feature or request label Dec 19, 2024
@OwenR-York
Copy link
Contributor

OwenR-York commented Jan 7, 2025

Example of writing model to file in Turtle

        private Model model;  // should work with OntModel Class too.
	public void outputTTLFile() throws Exception {
		FileWriter file = new FileWriter("./resources/OWL/Model.ttl");
		model.write(file, "TTL");
		file.close();
	}

@OwenR-York
Copy link
Contributor

The preferred method for saving models is to use Output Streams, the writer can have character encoding issues.

Also, there is a .writeALL method which writes all imported and inferred triples.

	public void outputTTLFile() throws Exception {
		String path = "./resources/temp/savedModel.ttl";
		System.out.println("Saving to file: " + path);
		FileOutputStream file = new FileOutputStream(path);
		model.saveOntModel(file, "TTL");
		file.close();
	}

@OwenR-York
Copy link
Contributor

When saving/editing models there is a need for caution with the type of Class being used to handle the model.

A user's data model can be handled using Model or OntModel. When a user's data model is unchanged when handled using a Model. However, an OntModel adds additional information (triples) to the model (presumably to support Jena's Ont API).

Similarly, if a user's data model is passed to a reasoner with a schema; the resulting inferred model will contain triples not in the original data model (and likely not wanted) and should not be written out or edited.

@agarciadom
Copy link
Member Author

Thanks for looking into this! In the future, we may want to have separate RDFModel and OntRDFModel classes, and note in the documentation that saving OntRDFModels will have this issue about extra tuples being saved. (People may actually want this behaviour sometimes, just to see all the extra information that was inferred.)

A reminder: when doing I/O, please use try-with-resources blocks so that we always close the file properly.

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

No branches or pull requests

2 participants