简体   繁体   中英

Modify Jena model returned by D2RQ

D2RQ creates a RDF representation of the DB using a Jena model.

Model m = new ModelD2RQ("file:outfile2.ttl");

I know that the returned model is a "read-only" model.

Hence, if I try to add a resource to the model I get a "jena.shared.AddDeniedException" exception.

    Resource r1=m.createResource("http://www.stackoverflow.com#34");
    r1.addProperty(RDF.type, ...); <-throws the exception

How can I decouple the model m from the database so that I can modify it? I don't want to write the model back, I just use D2RQ to get an RDF based DB-dump which I want to process further (I know that extensions like D2RQ update enable the modification of the database by modifying the RDF graph but I don't want to modify the DB)

Thanks

Take a copy to disconnect the model from the database:

Model m = new ModelD2RQ("file:outfile2.ttl");
Model mCopy = ModelFactory.createDefaultModel() ;
mCopy.add(m) ;
mCopy.addProperty(...)

Another way is to have a union model, where the in-memory part is the first, and update-able, part of the union.

Model m = new ModelD2RQ("file:outfile2.ttl");
Model extra = ModelFactory.createDefaultModel() ;
Model m2 = ModelFactory.createUnion(exrta, m2) ;
...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM