Query using Rule Reasoning doesn't return results

Hi,
Among some rules that I have set up, there is only one that doesn't seem to be working, as the query doesn't return any results. Query has been executed with reasoning option on.
Can you spot what is missing?

The rule:

    @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
    @prefix ub: <http://swat.cse.lehigh.edu/onto/univ-bench.owl#> .
    RULE :Type9
    IF {
        ?student a ub:Student .
        ?faculty a ub:Faculty .
        ?course a ub:Course .
        ?student ub:advisor ?faculty .
        ?faculty ub:teacherOf ?course .
        ?student ub:takesCourse ?course .
        BIND(BNODE() AS ?ID) .
    }
    THEN {
        ?ID ub:hasStudent ?student .
        ?ID ub:hasFaculty ?faculty .
        ?ID ub:hasCourse ?course .
    }
    :Type9 rdfs:comment "This rule defines Type 9" ;
    	a :MyRule .

And here's the query:

    PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
    PREFIX ub: <http://swat.cse.lehigh.edu/onto/univ-bench.owl#>
    SELECT ?X ?Y ?Z
    WHERE
    {
    ?ID ub:hasStudent ?X .
    ?ID ub:hasFaculty ?Y .
    ?ID ub:hasCourse ?Z .
    # ?X rdf:type ub:Student .
    # ?Y rdf:type ub:Faculty .
    # ?Z rdf:type ub:Course .
    # ?X ub:advisor ?Y . 
    # ?Y ub:teacherOf ?Z .
    # ?X ub:takesCourse ?Z
    }

Thanks so much,
Regards,
Marcelo.

Marcelo,

Introducing new IRIs/bnodes in this way is non-deterministic. When combined with multiple triple patterns in the head (THEN), it would lead to a distinct bnodes being created for each triple. If you can share the query plan when run with reasoning, we can confirm this behavior. Perhaps you can use the IRI() or BNODE() function with an argument identifying the node. Given what I see here, an initial suggestion would be to use the local names of the student, faculty and course bindings and create a new IRI, eg BIND(IRI(CONCAT("http://http://swat.cse.lehigh.edu/onto/univ-bench.owl/", LOCALNAME(?student), "/", LOCALNAME(?faculty), "/", LOCALNAME(?course))) as ?ID).

Hope this helps,
Jess

Hi Jess,
Thanks for the tip. It doesn't seem to work either. I was just wondering if importing the same rule a second time replaces the old one. Also, how do I delete a rule? I couldn't find it in the documentation. However, I was able to delete the triples that defined the rule - I guess I should be ok here, right?
I'm sharing the dataset, the ontology and the rule in the following location, which I think is everything you need to emulate this.

Please let me know if you need anything else.
Thanks again,
Marcelo.

The recommended way to delete rules (or any axioms with RDF serialisations which involve bnodes) is to put them into a named graph, then replace the entire graph.

Best,
Pavel

1 Like

Hi there.
So, I have tried the one below as suggested with no luck. I also tried to look at the execution plan, but with reasoning, it's giving me an empty result.
In a previous reply, I sent a link to the dataset and ontology I'm using in the hope you could emulate what I'm seeing.

@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix ub: <http://swat.cse.lehigh.edu/onto/univ-bench.owl#> .
RULE :Type9
IF {
   ?student a ub:Student .
   ?faculty a ub:Faculty .
   ?course a ub:Course .
   ?student ub:advisor ?faculty .
   ?faculty ub:teacherOf ?course .
   ?student ub:takesCourse ?course . 
BIND(IRI(CONCAT("http://http://swat.cse.lehigh.edu/onto/univ-bench.owl/", LOCALNAME(?student), "/", LOCALNAME(?faculty), "/", LOCALNAME(?course))) as ?ID) .
}
THEN {
   ?ID ub:hasStudent ?student ;
       ub:hasFaculty ?faculty ;
       ub:hasCourse ?course .
}
:Type9 rdfs:comment "This rule defines Type 9" ;
   a :MyRule .

Thanks so much.
Regards,
Marcelo.

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