java - Write to Jena RDF model through pagination -
i intend convert data in sql database rdf dump. have model , ontology defined.
model model = modelfactory.createdefaultmodel(); ontmodel ontmodel = modelfactory.createontologymodel(ontmodelspec.owl_dl_mem, model); the ontmodel has many classes defined in it. let suppose have 10000 records in sql db , want load them model , write file. however, want paginate in case of memory overflow.
int fromindex = 0; int toindex = 10; while(true) { //1. resources between fromindex toindex sql db // if no more resources 'break' //2. push these resources in model //3. write model file rdfwriter writer = model.getwriter(); file file = new file(file_path); filewriter filewriter = new filewriter(file, true); writer.write(this.model, filewriter, base_url); model.close(); = to+1; = to+10; } now, how 1 append new resources existing resources in file. because see ontology getting written twice , throws exception
org.apache.jena.riot.riotexception: markup in document following root element must well-formed.
is there way handle already?
now, how 1 append new resources existing resources in file. because see ontology getting written twice , throws exception
a model set of triples. can add more triples set, that's not quite same thing "appending", since model doesn't contain duplicate triples, , sets don't have specified order, "appending" isn't quite right metaphor.
jena can handle pretty big models, might first see whether can create model , add it, , write model file. while it's cautious, it's not bad idea see whether can want without jumping through hoops.
if have problems in-memory models, might consider using tdb backed model use disk storage. incremental updates model using model api, or sparql queries, , extract model afterward in serialization.
one more option, , easiest if want append file, use non-xml serialization of rdf, such turtle or n-triples. these text based (n-triples line-based), appending new content file not problem. approach described in answer adding more individuals existing rdf ontology.
Comments
Post a Comment