0

I am trying to retrieve the individuals of a class (note: the class has no subclasses) with rdf:type Jena in Java.

Onto Data (x individuals):

Class A: x1, x2, x3, x4 Class B: x5, x6, x7, x8 Class C: x9, x10, x11, x12

Object Properties: z1 (CLASS A with B), z2 (CLASS A WITH C), z3 (CLASS B with C)

RESULTS for rdf:type of CLassA:

In Protege: x1, x2, x3, x4 In Eclipse through jena: x1, x2, x3, x4, x5, x6, x7, x8, x9....

Select ?x
where { ?x rdf:type :ClassA }

In the ontology editor it works perfectly. However, in Java, when I execute the query I also get individuals which do not belong in that class, but they are connected through a property with one of the class individuals. Anyone knows how to fix this? The ontology is correct.

  • I am using eclipse as editor in java
  • I am using Protege to build the ontology

Eclipse/Jena:

PropertyConfigurator.configure("D:\\apache-jena-2.10.1\\jena-log4j.properties");
OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_MICRO_RULE_INF);
FileManager.get().readModel( model, "file:.owl" );

String queryString =
    "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 bio: <http://www.semanticweb.org/vassilis/ontologies/2013/5/Bio#> " +

    " SELECT ?x " +
    " WHERE { ?x rdf:type bio:Class } " ;

Query query = QueryFactory.create(queryString);
QueryExecution qe= QueryExecutionFactory.create(query, model);
com.hp.hpl.jena.query.ResultSet resultset = qe.execSelect();
ResultSetFormatter.out(System.out, resultset, query);

Protégé:

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 bio: <http://www.semanticweb.org/vassilis/ontologies/2013/5/Bio#> 

SELECT ?x 
WHERE { ?x rdf:type bio:ClassA }
user2598911
  • 379
  • 2
  • 6
  • 22
  • Please show the RDF data that you're querying, the SPARQL query that you're running, and the actual results that you're getting. If possible, the code you're using to run the query may help, too. It will be next to impossible to diagnose your problem without these data. – Joshua Taylor Sep 07 '13 at 15:33
  • You tagged with Protégé, so when you say "in the ontology editor it works perfectly," I assume you mean Protégé and not Eclipse, despite "I am using Eclipse as an editor." Are you running the same query in Protégé? Perhaps you could attach a screenshot? – Joshua Taylor Sep 07 '13 at 15:42
  • I am not getting an error nor in Protege or eclipse. But I do get individuals that do not belong in the class i query in eclipse, while in protege I get the right query results. – user2598911 Sep 07 '13 at 15:56
  • Thanks for the clarification. As I asked in the first comment, please show your data and the actual SPARQL query that you're using (the one in the question can't be it, since the prefixes `:` and `rdf:` aren't defined in it), the results you're getting from each, and possibly the Java code that you're running. Without seeing the data, we as users can't know whether Protégé is getting something wrong, or Jena is getting something wrong, or what. We need the data. – Joshua Taylor Sep 07 '13 at 16:01
  • Your update appeared just as I was posting that last comment. Thanks for the code. (Though, it's not entirely complete, where does `model` come from?). We still need the ontology though. – Joshua Taylor Sep 07 '13 at 16:04
  • What do you mean where does model come from? It is an owl file made with Protege and i retrieve it in order to query through jena – user2598911 Sep 09 '13 at 14:58
  • Not "the model", but the actual variable `model`. I mean, yes, we can see how the variable is initialized, but we still don't have the contents of the model. As I've said a number of times now, we can't know what the query _ought_ to return when we haven't got the data. – Joshua Taylor Sep 09 '13 at 16:29
  • in what form you need to see the data. Its pretty big. Should i present you an example of it? – user2598911 Sep 09 '13 at 16:47
  • Ideally you'd show a minimal example which still shows the problematic behavior. "Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself." Can you create a smaller version of your ontology where the problem still occurs, and present that? It would need to have some occurrences of `bio:Classe`es, so that `?x rdf:type bio:Class` will match, and also some data that appears in the results, but shouldn't (so that we can see your problem). – Joshua Taylor Sep 09 '13 at 16:50
  • I hope that helps a bit – user2598911 Sep 09 '13 at 17:40
  • I'm afraid it doesn't, actually; you haven't provided any actual RDF or OWL data (I do see the update at the top of the post). You say that you're running "Select ?x where { ?x rdf:type :ClassA }" but your Java code shows "SELECT ?x WHERE { ?x rdf:type bio:Class }". From what you've shown, it would be easy enough to create an ontology with three classes and 12 individuals as you've described, and to write a SPARQL query that would retrieve the individuals of one of the classes, but without the actual data and code that you're using, it's impossible to say what's going wrong in your code. – Joshua Taylor Sep 09 '13 at 17:48

2 Answers2

1

If the ontology is correct then could you show us your code?

Are you sure ":Class" is correct?

If the default namespace is owl or another vocabulary then it could be possible its returning all individuals using that vocabulary or possibly a difference in inference rules used in Jena. This is an assumption.

Anthony Hughes
  • 576
  • 3
  • 12
  • owl:Class looks more likely. – AndyS Sep 07 '13 at 19:58
  • It is owl. Maybe thats the case but what could i do to fix it – user2598911 Sep 09 '13 at 17:42
  • @user2598911 If you're looking to find the classes, query for `?x rdf:type owl:Class`. If you're looking for instances of `bio:ClassA`, then query for `?x rdf:type bio:ClassA`. – Joshua Taylor Sep 09 '13 at 17:49
  • I am looking to find the instances of the class. Problem is in eclipse it will all show instances not belonging in that class. In Proteges sparql it shows the right instances though – user2598911 Sep 09 '13 at 19:35
0

check the domain and range of your data type proprties for exampla in z3 if you set domain of z3 as CLASS A every individual which take part in this property is consider as a member of class A although you specify that individual as an class B individual in your ontology