# Enabling reasoner on a virtual graph

**URL:** <https://community.stardog.com/t/enabling-reasoner-on-a-virtual-graph/2942>\
**Category:** Support\
**Created:** [March 17, 2021, 8:15pm UTC](https://community.stardog.com/t/enabling-reasoner-on-a-virtual-graph/2942 "2021-03-17T20:15:05Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![serge](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/serge/32/376_2.png) [@serge](https://community.stardog.com/u/serge)\
**Post date:** [March 17, 2021, 8:15pm UTC](https://community.stardog.com/t/enabling-reasoner-on-a-virtual-graph/2942/1 "2021-03-17T20:15:05Z")

</div>

I have an ontology, and I am wondering if the reasoner can be enabled with the GRAPH Component.

First let right the query where I am doing the reasoning

```
SELECT *  
{ 
    GRAPH <virtual://Customers> {
        ?s a ?c
    }
    ?c rdfs:subClassOf vcard:Individual
}

```

Ideally I would much prefer to let the stardog reasoner do this for me. And simply have something a kind to

```
   SELECT *  
    { 
        GRAPH <virtual://Customers/reasoning> {
            ?s a ?c
        }
    }

```

like I would if I was calling a real SPARQL endpoint

```
SELECT *  
{ 
    {
        SERVICE <http://admin:admin@localhost:5820/example3/query/reasoning> {
            ?s a vcard:Individual
        }
    }
}

```

Is reasoning on virtual graph supported, if so what the syntax to enable it.

Thanks  
-Serge

---

<div class="post-metadata">

**Author:** ![jess](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/jess/32/10_2.png) [@jess](https://community.stardog.com/u/jess)\
**Post date:** [March 17, 2021, 8:25pm UTC](https://community.stardog.com/t/enabling-reasoner-on-a-virtual-graph/2942/2 "2021-03-17T20:25:51Z")

</div>

What type of virtual graph did you create? We don't currently support variable type or variable predicate queries on virtual graphs with reasoning. However, an error should be returned. Can you share the query plan?

---

<div class="post-metadata">

**Author:** ![serge](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/serge/32/376_2.png) [@serge](https://community.stardog.com/u/serge)\
**Post date:** [March 17, 2021, 8:42pm UTC](https://community.stardog.com/t/enabling-reasoner-on-a-virtual-graph/2942/3 "2021-03-17T20:42:59Z")

</div>

You are correct, enabling reasoning locally will cause an issue, similar to how it was describe in this post: [Behaviour with federation and reasoning](https://community.stardog.com/t/behaviour-with-federation-and-reasoning/880).

A workaround was to ask the service to do the reasoning remotely. Let re-use the queries in my previous post.

If I do a virtual import in database example3, I can use the following

```
 SELECT *  
{ 
    {
        SERVICE <http://admin:admin@localhost:5820/example3/query/reasoning> {
            ?s a vcard:Individual
        }
    }
}

```

Reasoning works because I added /reasoning at the end of my service endpoint. It done on the remote endpoint but that fine.

My question is, is there a way to achieve the same thing within a virtual add graph? I understand the performance would probably be impacted, but only looking at using T-box type of inferencing.

no worries, Was hoping there an undocumented option.

---

<div class="post-metadata">

**Author:** ![jess](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/jess/32/10_2.png) [@jess](https://community.stardog.com/u/jess)\
**Post date:** [March 17, 2021, 8:46pm UTC](https://community.stardog.com/t/enabling-reasoner-on-a-virtual-graph/2942/4 "2021-03-17T20:46:46Z")

</div>

Is this a SPARQL virtual graph? If so, the `sparql.url` can include the reasoning path element in the URL and it should function as you need.

Virtual graphs _in general_ only point to an upstream data source and whether reasoning is done there or not is unknown to Stardog.

---

<div class="post-metadata">

**Author:** ![serge](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/serge/32/376_2.png) [@serge](https://community.stardog.com/u/serge)\
**Post date:** [March 17, 2021, 9:02pm UTC](https://community.stardog.com/t/enabling-reasoner-on-a-virtual-graph/2942/5 "2021-03-17T21:02:02Z")

</div>

thanks that answers my question. There is no SPARQL query rewriting of any kind done by the virtual service.

I guess would not be trivial to support. Anyway was just curious since I was playing with virtual graph today.

Thanks  
-Serge

---

<div class="post-metadata">

**Author:** ![jess](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/jess/32/10_2.png) [@jess](https://community.stardog.com/u/jess)\
**Post date:** [March 17, 2021, 9:38pm UTC](https://community.stardog.com/t/enabling-reasoner-on-a-virtual-graph/2942/6 "2021-03-17T21:38:30Z")

</div>

> [@jess](#):
>
> We don't currently support variable type or variable predicate queries on virtual graphs with reasoning.

These are the main limitations but we do support reasoning over virtual graphs in general. Can you share which database is underlying your virtual graph? This might shed some light on things. If you're running a query with reasoning which is not producing the expected results (and not using a variable type or property), we can help you debug that.

---

<div class="post-metadata">

**Author:** ![serge](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/serge/32/376_2.png) [@serge](https://community.stardog.com/u/serge)\
**Post date:** [March 17, 2021, 10:08pm UTC](https://community.stardog.com/t/enabling-reasoner-on-a-virtual-graph/2942/7 "2021-03-17T22:08:40Z")

</div>

I have this query

```
SELECT * 
WHERE {
    GRAPH <virtual://Customers> {
        ?s a ex:Customer 
    }
}

```

which return a list of customer.

Now I modify the query to be

```
   SELECT * 
    WHERE {
        GRAPH <virtual://Customers> {
            ?s a vcard:Individual
        }
    }

```

An execute it on a database with reasoning that has a rule

`ex:Customer rdfs:subClassOf vcard:Individual`

I would expect at least the same list to be return (in my case the exact same one) but no record is return. If I ask for the plan, it's empty.

I don't believe ?s is considered a variable type or variable predicate query, or is it.

To reproduce, is simple you can use any virtual graph that as rdfs:Class, and create a DB with the rule above.

-Serge

---

<div class="post-metadata">

**Author:** ![jess](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/jess/32/10_2.png) [@jess](https://community.stardog.com/u/jess)\
**Post date:** [March 17, 2021, 10:09pm UTC](https://community.stardog.com/t/enabling-reasoner-on-a-virtual-graph/2942/8 "2021-03-17T22:09:34Z")

</div>

Those are type/classes. You would need to use `rdfs:subClassOf` instead of `rdfs:subPropertyOf`.

---

<div class="post-metadata">

**Author:** ![serge](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/serge/32/376_2.png) [@serge](https://community.stardog.com/u/serge)\
**Post date:** [March 17, 2021, 10:13pm UTC](https://community.stardog.com/t/enabling-reasoner-on-a-virtual-graph/2942/9 "2021-03-17T22:13:08Z")

</div>

sorry that was in the post only. I do have a subClassOf

![image](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/1X/fc2e92b8aba0b849ae3dd3c1a2615e6707a0f82a.png)

(I fixed my previous post)

---

<div class="post-metadata">

**Author:** ![jess](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/jess/32/10_2.png) [@jess](https://community.stardog.com/u/jess)\
**Post date:** [March 17, 2021, 10:14pm UTC](https://community.stardog.com/t/enabling-reasoner-on-a-virtual-graph/2942/10 "2021-03-17T22:14:38Z")

</div>

Can you double check the prefixes of the `ex:Customer` used in the query and the rule?

---

<div class="post-metadata">

**Author:** ![jess](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/jess/32/10_2.png) [@jess](https://community.stardog.com/u/jess)\
**Post date:** [March 17, 2021, 10:16pm UTC](https://community.stardog.com/t/enabling-reasoner-on-a-virtual-graph/2942/11 "2021-03-17T22:16:47Z")

</div>

Also check that you haven't somehow disabled the database option "Flag to enable reasoning over virtual graphs and SERVICE clauses." (`reasoning.virtual.graph.enabled`)

---

<div class="post-metadata">

**Author:** ![serge](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/serge/32/376_2.png) [@serge](https://community.stardog.com/u/serge)\
**Post date:** [March 17, 2021, 10:21pm UTC](https://community.stardog.com/t/enabling-reasoner-on-a-virtual-graph/2942/12 "2021-03-17T22:21:03Z")

</div>

sure they are converted from the prefix registered with the DB by studio, but to confirmed that they are the same I looked at the json

From rule  
{  
"s": {  
"type": "uri",  
"value": "[https://example.org/Customer](https://example.org/Customer)"

From virtual graph

```
    "c": {
      "type": "uri",
      "value": "https://example.org/Customer"

```

They are indeed the same

---

<div class="post-metadata">

**Author:** ![jess](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/jess/32/10_2.png) [@jess](https://community.stardog.com/u/jess)\
**Post date:** [March 17, 2021, 10:22pm UTC](https://community.stardog.com/t/enabling-reasoner-on-a-virtual-graph/2942/13 "2021-03-17T22:22:08Z")

</div>

Are you using Studio to enable reasoning for the query? Have you defined multiple reasoning schemas?

---

<div class="post-metadata">

**Author:** ![serge](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/serge/32/376_2.png) [@serge](https://community.stardog.com/u/serge)\
**Post date:** [March 17, 2021, 10:25pm UTC](https://community.stardog.com/t/enabling-reasoner-on-a-virtual-graph/2942/14 "2021-03-17T22:25:34Z")

</div>

Confirm that reasoning is enabled for virtual graph  
 ![image](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/1X/50d9986636326b111b722a103f19cc38f45f1231.png)

Using out of the box config. I loaded my rule with a turtle file. It is loaded in a namegraph by itself however, let me see if I load it in the default graph what happens.

---

<div class="post-metadata">

**Author:** ![jess](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/jess/32/10_2.png) [@jess](https://community.stardog.com/u/jess)\
**Post date:** [March 17, 2021, 10:37pm UTC](https://community.stardog.com/t/enabling-reasoner-on-a-virtual-graph/2942/15 "2021-03-17T22:37:42Z")

</div>

Can you try inserting the data locally and see if the reasoning query works? It's gotta be something simple somewhere. This is a pretty straightforward query.

---

<div class="post-metadata">

**Author:** ![serge](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/serge/32/376_2.png) [@serge](https://community.stardog.com/u/serge)\
**Post date:** [March 17, 2021, 10:49pm UTC](https://community.stardog.com/t/enabling-reasoner-on-a-virtual-graph/2942/16 "2021-03-17T22:49:37Z")

</div>

Before doing anything, I deleted the database and the virtual graph. During my tests, I often reseted either the database or the virtual graph but never both at the same time. I found it weird that there was no query plan so wanted to start from a clean slate thinking maybe something is not being cleanup properly.

Anyway , after resetting my installation and reloading exactly the same data , inference is working now. Maybe a simple server restart would of suffice, should of tried that first, but just happy it now works.

Thank for your help @jess

---

<div class="post-metadata">

**Author:** ![jess](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/jess/32/10_2.png) [@jess](https://community.stardog.com/u/jess)\
**Post date:** [March 17, 2021, 10:59pm UTC](https://community.stardog.com/t/enabling-reasoner-on-a-virtual-graph/2942/17 "2021-03-17T22:59:56Z")

</div>

Glad it's working. Let us know if you have any further questions or issues.

---

<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:** [March 31, 2021, 11:00pm UTC](https://community.stardog.com/t/enabling-reasoner-on-a-virtual-graph/2942/18 "2021-03-31T23:00:42Z")

</div>

Closed on March 31, 2021, 11:00pm UTC

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