Im working on writing sparql queries in my java project using jena API.
I have multiple rdf files, and I need to write query which involves displaying values from multiple rdf files for an attribute.
For a single rdf file, I can load in into a model, create a query string and execute it.
But how do I do it for multiple rdf documents.
Note: All rdf files are locally stored.
My code for single rdf file:
in = new FileInputStream(new File("data.rdf"));
model = ModelFactory.createOntologyModel();
model.read(in,defaultNameSpace);
in.close();
String queryString ="<My SParql Query>";
Query query = QueryFactory.create(queryString);
// Execute the query and obtain results
QueryExecution qe = QueryExecutionFactory.create(query, model);
ResultSet response = qe.execSelect();
// Output query results
ResultSetFormatter.out(System.out, response, query);
// Important - free up resources used running the query
qe.close();
How do I work with multiple rdf files, Can I load them into different models and still use in the same query?? Or should I join the models to get a new model which is union of them?
model.readto read in each of the files to the model. Alternatively, as you say, you could create a union model. - Joshua Taylor