You haven't said anything about how you created the TDB models so it is
pretty hard to diagnose.
First off, do you need to use TDB here? If you load your ontology into
memory as an OntModel then the import processing will be done and your
query would probably work. You should try that as a check.
If you really do need to use TDB here then how are you trying to process
the imports? You might be trying to:
(1) Load the imports closure as a single TDB graph.
(2) Load the ontology as one graph and load the imports as separate TDB
graphs but access the whole as a single OntModel.
(3) Load the ontology as one TDB graph, wrap an OntModel round it, but
go and fetch the imported ontologies from the web when they are a needed.
(1) is likely to be the best route. If this is what you are doing and it
is not working then look at how you are doing the TDB loading. If you
are doing it in your own program then ensure import processing has
happened. If you are using TDB loader then make sure you are including
in TDB loader all the imported ontologies.
(2) Can be done but you need to set up an appropriate OntDocumentManager
and associated ModelMaker to help the OntModel find the right graphs in
TDB. Someone else would have to help with the details of that if this
the route your are taking.
(3) For this and (2) the other thing that might go wrong is that the
import processing isn't being triggered. The OntModels normally do
import processing at read() time. With a TDB-model then there is no read
so you will need to call loadImports(). Do have this call?
Finally for all of these cases the import processing might fail because
one or more of the imports is not accessible - whether due to server
problems or firewall problems. You should see error messages in that case.
Dave
On 09/07/14 07:25, Dibyanshu Jaiswal wrote:
Friends!! I am really facing this problem. Any help or suggestion will be
greatly appreciated.
On Wed, Jun 25, 2014 at 3:58 PM, Dibyanshu Jaiswal <[email protected]>
wrote:
Hi all!
I am using Jena 2.11.
I have an ontology setup, in a form of OntModel and backed by jena TDB.
The ontology consists of a base owl file which import 4 other owl files.
Out of these 2 owl files further import other owl files.
I am unable to get results using a sparql query using jena ARQ engine,
where by exactly the same query when executed in Protege 4.3 returns
appropriate results.
Query being:
PREFIX un: <http://purl.oclc.org/NET/ssnx/ssn#>
PREFIX : <http://www.semanticweb.org/ontologies/2013/9/My_BASE_OWL.owl#>
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX geof: <http://www.opengis.net/def/function/geosparql/>
PREFIX sf: <http://www.opengis.net/ont/sf#>
PREFIX afn: <http://jena.hpl.hp.com/ARQ/function#>
PREFIX fn: <http://www.w3.org/2005/xpath-functions#>
PREFIX gml: <http://www.opengis.net/ont/gml#>
PREFIX j.0:<http://www.opengis.net/def/geosparql/#>
PREFIX my:<http://example.org/ApplicationSchema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX uo: <http://purl.obolibrary.org/obo/uo#>
PREFIX ssn: <http://purl.oclc.org/NET/ssnx/ssn#>
PREFIX ucum: <http://purl.oclc.org/NET/muo/ucum/>
PREFIX ucumpq: <http://purl.oclc.org/NET/muo/ucum/physical-quality/>
PREFIX uomvocab: <http://purl.oclc.org/NET/muo/muo#>
SELECT * WHERE {?UOM uomvocab:measuresQuality ucumpq:power}
In my java programs, i fire the query using two methods.
1.
public static String prefixTheQuery(String q){
q ="PREFIX un: <"+AppProperties.getImportedIRI()+">\n"+
"PREFIX : <"+AppProperties.getBaseIRI()+">\n"+
"PREFIX geo: <http://www.opengis.net/ont/geosparql#>\n" +
"PREFIX geof: <
http://www.opengis.net/def/function/geosparql/>\n" +
"PREFIX sf: <http://www.opengis.net/ont/sf#>\n"+
"PREFIX afn: <http://jena.hpl.hp.com/ARQ/function#>\n"+
"PREFIX fn: <http://www.w3.org/2005/xpath-functions#>\n"+
"PREFIX gml: <http://www.opengis.net/ont/gml#>\n"+
"PREFIX j.0:<http://www.opengis.net/def/geosparql/#>\n"+
"PREFIX my:<http://example.org/ApplicationSchema#>\n"+
"PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#
\n"+
"PREFIX owl: <http://www.w3.org/2002/07/owl#>\n"+
"PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>\n"+
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n"+
"PREFIX uo: <http://purl.obolibrary.org/obo/uo#>\n"+
"PREFIX ssn: <http://purl.oclc.org/NET/ssnx/ssn#>\n"+
"PREFIX ucum: <http://purl.oclc.org/NET/muo/ucum/>\n"+
"PREFIX ucumpq: <
http://purl.oclc.org/NET/muo/ucum/physical-quality/>\n"+
"PREFIX uomvocab: <http://purl.oclc.org/NET/muo/muo#
\n"+q;
return q;
}
which returns the actual query string prefixed with different prefixes
being used in all the ontologies in use.
2.
public static String sparqlQuery(String sparqlQueryString){
String r = null;
QueryExecution qexec = null;
Query query = null;
ResultSet results = null;
ModelGenerator.getDataset().begin(ReadWrite.READ); //returns
dataset
try {
sparqlQueryString = prefixTheQuery(sparqlQueryString);
query = QueryFactory.create(sparqlQueryString) ;
qexec =
QueryExecutionFactory.create(query,ModelGenerator.getDataset());
results = qexec.execSelect() ;
r = printResultsWithResultSetFormatter(results, OutputType.TEXT);
// to format output w.r.t JSON, XML,TEXT
} catch(Exception e){
System.out.println("Exception Occured while in QueryExecution: " );
e.printStackTrace();
} finally {
qexec.close() ;
ModelGenerator.getDataset().end();
}
return r;
}
Using this approach (have used this for a long time) I am unable to get
the results as expected, instead i get a blank results.
To me the problem is that I am unable to fetch triples which have been
imported indirectly via some ontology directly imported in my base
ontology, Which is not the case when Protege is used to do the same.
Is it so that the ontologies imported indirectly into the base model,
doest not imports the all the statements of it?
*Dibyanshu Jaiswal*
Mb: +91 9038304989