对于一个项目,我必须使用 Apache Jena 作为 API 和 Blazegraph 作为三重存储,我正在尝试编写一个代码,允许我将我的数据集(N-Triples 文件)转换为包含每个语句的 NamedGraph 的文件。
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){
}