问题
For a project I have to use Apache Jena as an API and Blazegraph as a triple store, I am trying to program a code that allows me to transform my dataset (N-Triples File) to a file that contains the NamedGraph of each statement.
String APIUrl = "http://localhost:9999/bigdata/namespace/drugbank/sparql";
String req = "select * WHERE {?x ?y ?z}";
RDFConnection conn = RDFConnectionFactory.connect(APIUrl);
FileManager.get().addLocatorClassLoader(Main.class.getClassLoader());
Model model = FileManager.get().loadModel("drugbank.nt",null,"NTRIPLES");
conn.load(model);
Query query = QueryFactory.create(req);
QueryExecution qexec = QueryExecutionFactory.create(query,model);
try {
ResultSet rs = qexec.execSelect();
Model m1 = RDFOutput.encodeAsModel(rs);
StmtIterator iter = m1.listStatements();
int i=0;
final Model mStat = ModelFactory.createDefaultModel();
while (iter.hasNext()) {
i++;
Statement stmt = iter.nextStatement() ;
// code for named Graph
}
}catch(Exception){
}
回答1:
You can load the model directly to a remote named graph:
conn.load(model);
loads the default graph.
conn.load(graphName, model);
loads a named graph.
来源:https://stackoverflow.com/questions/52060818/transform-my-rdf-file-to-a-named-graph-file