1 Reply Latest reply on Jun 6, 2008 6:47 PM by alwu-Oracle

    Future Support for Named Graphs?

    637657
      It would be nice to execute a SPARQL query containing named graphs in the WHERE clause via the Jena Adaptor. I don't think this is possible given that when one adds triples to the database only their model is specified (no parameter for a named graph). Please instruct me if 've missed how to do this! Is there any plan to support named graphs in the future?

      Thanks
        • 1. Re: Future Support for Named Graphs?
          alwu-Oracle
          It is supported by Oracle Jena Adaptor. The following shows one way to do that. You need to customize.

          Oracle oracle = new Oracle(jdbcUrl, user, password);
          ModelOracleSem model = ModelOracleSem.createOracleSemModel(oracle, modelName);
          populateGraph(model.getGraph()); // insert some data for testing

          DataSource ds = DatasetFactory.create();
          ds.setDefaultModel(model);

          ModelOracleSem model1 = ModelOracleSem.createOracleSemModel(oracle, modelName+"1");
          Node sub = Node.createURI("http://fromModel1/sub");
          Node pre = Node.createURI("http://fromModel1/pre");
          Node obj = Node.createURI("http://fromBothModel/obj");
          model1.getGraph().add(Triple.create(sub, pre, obj));

          ModelOracleSem model2 = ModelOracleSem.createOracleSemModel(oracle, modelName+"2");
          sub = Node.createURI("http://fromModel2/sub");
          pre = Node.createURI("http://fromModel2/pre");
          obj = Node.createURI("http://fromBothModel/obj");
          model2.getGraph().add(Triple.create(sub, pre, obj));

          String queryString =
          " PREFIX ns1: <http://fromModel1/> " +
          " PREFIX ns2: <http://fromModel2/> " +
          " SELECT ?obj " +
          " FROM NAMED <http://model1.rdf> " +
          " FROM NAMED <http://model2.rdf> " +
          " WHERE { " +
          " GRAPH <http://model1.rdf> { " +
          " ?x ns1:pre ?obj . " +
          " } . " +
          " GRAPH <http://model2.rdf> { " +
          " ?y ns2:pre ?obj . " +
          " } . " +
          " } ";

          Query query = null;
          QueryExecution qexec = null;
          ds.addNamedModel("http://model1.rdf",model1);
          ds.addNamedModel("http://model2.rdf",model2);
          query = QueryFactory.create(queryString) ;
          qexec = QueryExecutionFactory.create(query, ds) ;

          try {
          ResultSet results = qexec.execSelect() ;
          for ( ; results.hasNext() ; ) {
          QuerySolution soln = results.nextSolution() ;
          psOut.println("soln " + soln);
          }
          }
          finally {
          qexec.close() ;
          }