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?
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.
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.
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.