The jena reasoners do not know about multiple graphs.

With Jena's store (TDB) you can make the default graph of the store into a virtual union over all the named graphs and then reason over that. Probably there's a way to do something similar with Virtuoso but you'll have to ask the Virtuoso folks about that.

Dave

On 10/03/14 06:51, Anila Sahar Butt wrote:
Hi,

I have multiple graphs in my virtuoso repository. Each graph stores an
ontology. I want to turn on RDFS Inferencing on all the graphs using Jena
Virtuoso provider API.

I am able to do turn on inferencing on a single graph, using the code :


import java.util.ArrayList;


import com.hp.hpl.jena.query.Query;

import com.hp.hpl.jena.query.QueryExecution;

import com.hp.hpl.jena.query.QueryExecutionFactory;

import com.hp.hpl.jena.query.QueryFactory;

import com.hp.hpl.jena.query.QuerySolution;

import com.hp.hpl.jena.query.ResultSet;

import com.hp.hpl.jena.rdf.model.InfModel;

import com.hp.hpl.jena.rdf.model.Model;

import com.hp.hpl.jena.rdf.model.ModelFactory;


import com.hp.hpl.jena.rdf.model.Resource;

import com.hp.hpl.jena.rdf.model.Statement;

import com.hp.hpl.jena.rdf.model.StmtIterator;

import com.hp.hpl.jena.reasoner.Reasoner;

import com.hp.hpl.jena.reasoner.ReasonerRegistry;


import virtuoso.jena.driver.VirtGraph;

import virtuoso.jena.driver.VirtModel;



public class InferenceExample {


  public static void main(String[] args)

     {

VirtGraph graph = new VirtGraph("http://purl.oclc.org/NET/ssnx/ssn";, url,
usename, password );

   System.out.println("Connection established .... ");

   Model virtModel = new VirtModel(graph);

     Reasoner reasoner = ReasonerRegistry.getRDFSReasoner();

     InfModel infModel = ModelFactory.createInfModel(reasoner, virtModel);

     infModel.commit();

     String query = "PREFIX ssn:<http://purl.oclc.org/NET/ssnx/ssn#>"

   + " PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>"

   + " CONSTRUCT {ssn:Device rdfs:subClassOf ?superClass} "

   + " WHERE {ssn:Device rdfs:subClassOf ?superClass}";


  System.out.println("Execute query=\n"+query) ;

   Query sparql = QueryFactory.create(query);

     QueryExecution vqe = QueryExecutionFactory.create (sparql, infModel);


  Model result = vqe.execConstruct();

  StmtIterator iter = result.listStatements();

         while (iter.hasNext()){

             Statement stmt = iter.nextStatement();

             String ontology = stmt.getObject().toString();

             System.out.println(" Ontology : " + ontology);

          }


}


Can run the same query on all graphs in the repository.


Reply via email to