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):

  ?s a <>

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

Full example:

@prefix : <> .
@prefix owl: <> .
@prefix rdf: <> .
@prefix xml: <> .
@prefix xsd: <> .
@prefix rdfs: <> .
@base <> .
<> rdf:type owl:Ontology .

<> rdf:type owl:DatatypeProperty ;
                                 rdfs:label "name" .

<> rdf:type owl:Class ;                                
                                 rdfs:label "Role" .

<> rdf:type owl:Class ;
                                    rdfs:subClassOf <> .

<> rdf:type owl:Class ;
                                    rdfs:subClassOf <> .

<> rdf:type owl:NamedIndividual ,
                                           <> ;
<> "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 =;
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 ) {
# ""
# }

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: 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 ="support")
				               .credentials("admin", "admin")

		SelectQuery sq ="select ?s where { ?s a <> }");

		TupleQueryResult res = sq.execute();
		while (res.hasNext()) {



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:


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 ) {
# ""
# }

In the WebConsole I try the same query (just replacing the “?id” by “<>” 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.