transform my rdf file to a named graph file

梦想与她 提交于 2019-12-11 12:49:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!