Basic subclass inference

I am not sure I am doing something wrong, but I just updated my Stardog 4.0.5 to 5.0RC1. While doing some queries I saw something unexpected, so I have created a minimalist example here:

I have a role1 which is a RoleOne. And RoleOne is a subclass of Role. From this query I was expecting role1 as a result, but I don’t get the result with or without reasoning (SL is configured):

SELECT ?s
WHERE {
  ?s a <http://www.example.com/ex#Role>
  }

I only get the result when I use RoleOne explicitly.
Am I missing something?

Full example:

@prefix : <http://www.example.com/ex#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@base <http://www.example.com/ex#> .
<http://www.example.com/ex#> rdf:type owl:Ontology .


<http://www.example.com/ex#name> rdf:type owl:DatatypeProperty ;
                                 
                                 rdfs:label "name" .

<http://www.example.com/ex#Role> rdf:type owl:Class ;                                
                                 rdfs:label "Role" .

<http://www.example.com/ex#RoleOne> rdf:type owl:Class ;
      
                                    rdfs:subClassOf <http://www.example.com/ex#Role> .

<http://www.example.com/ex#RoleTwo> rdf:type owl:Class ;
                                    
                                    rdfs:subClassOf <http://www.example.com/ex#Role> .


<http://www.example.com/ex#role1> rdf:type owl:NamedIndividual ,
                                           <http://www.example.com/ex#RoleOne> ;
                                 
<http://www.example.com/ex#name> "one" .

Are you using the WebConsole or the CLI? There have been some reported problems with the WebConsole and reasoning in 5.0-RC1

1 Like

I am using the Web Console, but I discovered the problem via my Java program.

Actually, it makes sense that for some reason the code underneath is different from the Web and Java, since there is something very strange that never happened to me before - I execute a query in Java and got no results, but if I copy the exact query (so I print the “query” to be executed) in the Web console, I got results as expected.

The issue that I posted here is a very simple one, just a subClassOf…

Confirmed… besides the class inference issue, I am getting different results from Java and the Web Console, which makes me feel very uncomfortable, don’t know what to trust. Perhaps rolling back to Stardog 4.0.5 is the only solution (I found v 4.2 had also some issues with reasoning and I couldn’t use it because it gave me wrong results). Let’s see if someone can bring some light to the issue.

Can you share the Java code that is producing different results with the data set and query you provided?

I can share this:

The Java code basically does this:

SelectQuery query = con.select(MYQUERY);
query.parameter("id", id);
System.out.println("Q: " + query);
try (TupleQueryResult qResult = query.execute()) {
    System.out.println("after");  // --> This is executed
    while (qResult.hasNext()) {
    // It never reaches here --> it gives no results

I have many methods like this one. So it is possible I have made a mistake in Java, but unlikely.
When I print the query, I get something like this:

SELECT ?docid ?name  
WHERE {        
  OPTIONAL { ?docid ex:name ?name . }   
  {            
    SELECT ?docid     
           WHERE {   
             GRAPH ex2:g1 {
               ?id a ?roleclass .    
               ?id ex2:canRead ?docid .
               FILTER (?roleclass IN (ex:roleOne, ex:roleTwo ) ) 
             }          
           }      
  }
} ORDER BY ?name 
# Overrides by the API: 
# PARAMETERS ( ?id ) {
# "http://example.com/ex#john"
# }

Note that ?id a ?roleclass . and FILTER (?roleclass IN (ex:roleOne, ex:roleTwo ) ) is just a workaround because the subclass inference did not work. Otherwise I would have simply used ?id a ex:Role .

So when I have 0 results I normally print the query and paste it in the WebConsole for debugging, until I get the query right. The funny thing is that I take this query and paste it directly in the WebConsole and it works. It gives me the expected results by replacing “?id” for the value in the PARAMETERS: http://example.com/ex#john. But it also gives me (all) the results if I just run the query without replacing it, binding ?id to any possible option.
I can also see all data as expected in the Web access (localhost:5820/databasename/browse/…). But the query don’t get results in Java.

So this post actually have ended up in two problems:
1- Subclass inference apparenlty not working
2 - Java code doesn’t give me the expected results as the WebConsole does

Note that it is very easy to make a mistake with this technology, so I am not discarding that (my apologies if I did). But what made me suspicious is that the printed query did not raise any results via Java when it actually does in the WebConsole.

Zachary, Were you able to reproduce the issue? Just to discard there is an issue with my installation.

I can execute the following Java program on your dataset and I get the expected output:

Connection c = ConnectionConfiguration.to("support")
				               .server("http://localhost:5820")
				               .credentials("admin", "admin")
				               .reasoning(true)
				               .connect();

		SelectQuery sq = c.select("select ?s where { ?s a <http://www.example.com/ex#Role> }");

		TupleQueryResult res = sq.execute();
		while (res.hasNext()) {
			System.out.println(res.next().getBinding("s"));
		}

Output:

s=http://www.example.com/ex#role1

Process finished with exit code 0

I’m not sure what you’re doing with your SelectQuery.parameter() call, but perhaps there’s something going on with that.

Thanks Stephen.

Can you verify the WebConsole too?

This is the exact link:

http://localhost:5820/support#!/query/prefix%20rdf%3A%20%3Chttp%3A%2F%2Fwww.w3.org%2F1999%2F02%2F22-rdf-syntax-ns%23%3E%0Aprefix%20owl%3A%20%3Chttp%3A%2F%2Fwww.w3.org%2F2002%2F07%2Fowl%23%3E%0Aprefix%20xsd%3A%20%3Chttp%3A%2F%2Fwww.w3.org%2F2001%2FXMLSchema%23%3E%0Aprefix%20rdfs%3A%20%3Chttp%3A%2F%2Fwww.w3.org%2F2000%2F01%2Frdf-schema%23%3E%0A%0ASELECT%20%3Fs%0AWHERE%20%7B%0A%20%20%3Fs%20a%20%3Chttp%3A%2F%2Fwww.example.com%2Fex%23Role%3E%0A%20%20%20%20%20%7D

When I execute this I get 0 answers, with or without reasoning.

For my query, the SelectQuery.parameter() is supposed to work fine, since I get the correct output:

# Overrides by the API: 
# PARAMETERS ( ?id ) {
# "http://example.com/ex#john"
# }

In the WebConsole I try the same query (just replacing the “?id” by “<http://example.com/ex#john>” and get the expected results). Even without making this substitution I get results. But in Java I get nothing.

Ok, I have found a (very stupid) mistake with the Java code, and now I see the expected results.

But for the problem I reported in the post (basic subclass inference) I am still not getting results. Perhaps this is the issue that Zachary commented.

Yes, the webconsole in 5.0-RC1 does not work with reasoning on. This is a known bug that has been fixed and will be included in the final 5.0 release.

Perfect, thanks. I think this clarifies the issue. I was getting mad!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.