# Basic subclass inference

**URL:** <https://community.stardog.com/t/basic-subclass-inference/420>\
**Category:** Support\
**Created:** [June 21, 2017, 5:25pm UTC](https://community.stardog.com/t/basic-subclass-inference/420 "2017-06-21T17:25:09Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![doggyfood](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/doggyfood/32/106_2.png) [@doggyfood](https://community.stardog.com/u/doggyfood)\
**Post date:** [June 21, 2017, 5:25pm UTC](https://community.stardog.com/t/basic-subclass-inference/420/1 "2017-06-21T17:25:09Z")

</div>

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" .
```

---

<div class="post-metadata">

**Author:** ![zachary.whitley](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/zachary.whitley/32/94_2.png) [@zachary.whitley](https://community.stardog.com/u/zachary.whitley)\
**Post date:** [June 21, 2017, 5:43pm UTC](https://community.stardog.com/t/basic-subclass-inference/420/2 "2017-06-21T17:43:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![doggyfood](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/doggyfood/32/106_2.png) [@doggyfood](https://community.stardog.com/u/doggyfood)\
**Post date:** [June 21, 2017, 6:18pm UTC](https://community.stardog.com/t/basic-subclass-inference/420/3 "2017-06-21T18:18:19Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![doggyfood](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/doggyfood/32/106_2.png) [@doggyfood](https://community.stardog.com/u/doggyfood)\
**Post date:** [June 21, 2017, 7:36pm UTC](https://community.stardog.com/t/basic-subclass-inference/420/4 "2017-06-21T19:36:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![stephen](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/stephen/32/27_2.png) [@stephen](https://community.stardog.com/u/stephen)\
**Post date:** [June 21, 2017, 7:40pm UTC](https://community.stardog.com/t/basic-subclass-inference/420/5 "2017-06-21T19:40:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![doggyfood](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/doggyfood/32/106_2.png) [@doggyfood](https://community.stardog.com/u/doggyfood)\
**Post date:** [June 21, 2017, 9:33pm UTC](https://community.stardog.com/t/basic-subclass-inference/420/6 "2017-06-21T21:33:39Z")

</div>

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](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.

---

<div class="post-metadata">

**Author:** ![doggyfood](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/doggyfood/32/106_2.png) [@doggyfood](https://community.stardog.com/u/doggyfood)\
**Post date:** [June 22, 2017, 7:50am UTC](https://community.stardog.com/t/basic-subclass-inference/420/7 "2017-06-22T07:50:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![stephen](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/stephen/32/27_2.png) [@stephen](https://community.stardog.com/u/stephen)\
**Post date:** [June 22, 2017, 1:40pm UTC](https://community.stardog.com/t/basic-subclass-inference/420/8 "2017-06-22T13:40:22Z")

</div>

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

```java
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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![doggyfood](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/doggyfood/32/106_2.png) [@doggyfood](https://community.stardog.com/u/doggyfood)\
**Post date:** [June 22, 2017, 1:55pm UTC](https://community.stardog.com/t/basic-subclass-inference/420/9 "2017-06-22T13:55:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![doggyfood](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/doggyfood/32/106_2.png) [@doggyfood](https://community.stardog.com/u/doggyfood)\
**Post date:** [June 22, 2017, 4:07pm UTC](https://community.stardog.com/t/basic-subclass-inference/420/10 "2017-06-22T16:07:07Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![stephen](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/stephen/32/27_2.png) [@stephen](https://community.stardog.com/u/stephen)\
**Post date:** [June 22, 2017, 4:13pm UTC](https://community.stardog.com/t/basic-subclass-inference/420/11 "2017-06-22T16:13:24Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![doggyfood](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/doggyfood/32/106_2.png) [@doggyfood](https://community.stardog.com/u/doggyfood)\
**Post date:** [June 22, 2017, 4:15pm UTC](https://community.stardog.com/t/basic-subclass-inference/420/12 "2017-06-22T16:15:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [July 6, 2017, 4:16pm UTC](https://community.stardog.com/t/basic-subclass-inference/420/13 "2017-07-06T16:16:00Z")

</div>

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