将我的rdf文件转换为命名的图形文件 [英] transform my rdf file to a named graph file
本文介绍了将我的rdf文件转换为命名的图形文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对于一个项目,我必须使用Apache Jena作为API,并使用Blazegraph作为三重存储,我正在尝试编写一个代码,该代码允许我将数据集(N-Triples File)转换为包含NamedGraph的文件.每个声明.
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){
}
推荐答案
您可以将模型直接加载到远程命名图:
You can load the model directly to a remote named graph:
conn.load(model);
加载默认图形.
conn.load(graphName, model);
加载命名图.
这篇关于将我的rdf文件转换为命名的图形文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文