Type constraints in user-defined reasoner rules (bug?)

2 views
Skip to first unread message

Slava Kravchenko

unread,
Feb 11, 2016, 12:29:11 PM2/11/16
to Stardog
Hello!

I'm trying to implement a simplistic "visibility" of nodes in a graph by writing user rules for the reasoner.
But I'm getting strange results. I believe there must be a bug there.

So, here's an example:
@prefix rule: <tag:stardom:api:rule:>
@prefix ex: <http://example.org/stuff#>

[] a rule:SPARQLRule ;
   rule
:content """
     PREFIX ex: <http://example.org/stuff#>
     IF {
       ?n2 ex:has_parent :?n1 .
       ?g ex:can_view ?n1 ;
          a ex:Group
     }
     THEN {
       ?g ex:can_view ?n2
     }
   """
.

ex
:node2 ex:has_parent ex:node1 .
ex
:group1 a ex:Group ;
         ex:can_view ex:node1 .

It's simple: "if node2 is a child of node1, and group1 can view node1, then group1 can view node2".

I expect query
prefix ex: <http://example.org/stuff#>
select * where { ?s ex:can_view ?o }
to return
ex:group1 ex:can_view ex:node1
ex
:group1 ex:can_view ex:node2
... which it does, if I remove "a ex:Group" from SPARQLRule above, so that I get:
[] a rule:SPARQLRule ;
   rule
:content """
     PREFIX ex: <http://example.org/stuff#>
     IF {
       ?n2 ex:has_parent :?n1 .
       ?g ex:can_view ?n1
     }
     THEN {
       ?g ex:can_view ?n2
     }
   """
 .

Instead, I'm getting only the statement which is explicitly specified:
ex:group1 ex:can_view ex:node1
(I have SL reasoning switched on).

I tried using just "a ?c" to say that I don't really care about the type of "?g", but it won't fix the issue -- only complete removal of that extra type constraint works.
(I also tried using "rdf:type" instead of "a", providing explicit "rdf" prefix declaration; then using triples instead of a shortcut via ";"... but to no avail).

A SPARQL query like
select * where { ?s ex:can_view ?o ; a ex:Group }
works fine.

Zachary Whitley

unread,
Feb 11, 2016, 1:03:04 PM2/11/16
to Stardog
I can't reproduce the two results. It looks like you might have a typo in the rule definition. I think you have a typo. Can you confirm if the line "?n2 ex:has_parent :?n1" is correct. I'm specifically wondering about the colon in ":?n1".
 
... which it does, if I remove "a ex:Group" from SPARQLRule above, so that I get:
[] a rule:SPARQLRule ;
   rule
:content """
     PREFIX ex: <http://example.org/stuff#>
     IF {
       ?n2 ex:has_parent :?n1 .
       ?g ex:can_view ?n1
     }
     THEN {
       ?g ex:can_view ?n2
     }
   """
 .

Instead, I'm getting only the statement which is explicitly specified:
ex:group1 ex:can_view ex:node1
(I have SL reasoning switched on).

I tried using just "a ?c" to say that I don't really care about the type of "?g", but it won't fix the issue -- only complete removal of that extra type constraint works.
(I also tried using "rdf:type" instead of "a", providing explicit "rdf" prefix declaration; then using triples instead of a shortcut via ";"... but to no avail).

A SPARQL query like
select * where { ?s ex:can_view ?o ; a ex:Group }
works fine.

--
-- --
You received this message because you are subscribed to the C&P "Stardog" group.
To post to this group, send email to sta...@clarkparsia.com
To unsubscribe from this group, send email to
stardog+u...@clarkparsia.com
For more options, visit this group at
http://groups.google.com/a/clarkparsia.com/group/stardog?hl=en
---
You received this message because you are subscribed to the Google Groups "Stardog" group.
To unsubscribe from this group and stop receiving emails from it, send an email to stardog+u...@clarkparsia.com.

Zachary Whitley

unread,
Feb 11, 2016, 1:17:35 PM2/11/16
to Stardog
@prefix rule: <tag:stardom:api:rule:> should be <tag:stardog:api:rule:>   

Zachary Whitley

unread,
Feb 11, 2016, 1:27:15 PM2/11/16
to Stardog
If you fix up the typos and run with the following


@prefix rule: <tag:stardog:api:rule:>
@prefix ex: <http://example.org/stuff#>

IF {
       ?n2 ex:has_parent ?n1 .
       ?g ex:can_view ?n1 ;
          a ex:Group
     }
     THEN {
       ?g ex:can_view ?n2
     }
   """ .

ex:node2 ex:has_parent ex:node1 .
ex:group1 a ex:Group ;
         ex:can_view ex:node1 .
  }

You'll get the following messages in stardog.log after executing the query "select * where { ?s ex:can_view ?o }"

WARN  2016-02-11 13:22:47,748 [SPEC-Server-1-4] com.complexible.stardog.reasoning.blackout.ViewAtomToPlanNode:transformView(100): Unsupported cycle or rule for property http://example.org/stuff#can_view
WARN  2016-02-11 13:22:47,748 [SPEC-Server-1-4] com.complexible.stardog.reasoning.blackout.ViewAtomToPlanNode:transformView(101): Rewriting:
http://example.org/stuff#can_view_VIEW(x0, x1) <- http://example.org/stuff#can_view(x0, x1)
http://example.org/stuff#can_view_VIEW(x0, x1) <- http://example.org/stuff#Group(x0) ^ http://example.org/stuff#can_view_VIEW(x0, x2) ^ http://example.org/stuff#has_parent(x1, x2)

I'm not sure how you were getting the two results that you were expecting though.

Zachary Whitley

unread,
Feb 11, 2016, 1:32:08 PM2/11/16
to Stardog
Sorry, now I'm rockin' the typos. Let me try this again


prefix rule: <tag:stardog:api:rule:>
prefix ex: <http://example.org/stuff#>

insert data {

Zachary Whitley

unread,
Feb 11, 2016, 1:47:33 PM2/11/16
to Stardog
Looks like there might be a small bug in the Stardog web console. If you enter

prefix rule: <tag:stardog:api:rule:>
prefix ex: <http://example.org/stuff#>

insert data {

[] a rule:SPARQLRule ;
   rule:content """
     PREFIX ex: <http://example.org/stuff#>
     IF {
       ?n2 ex:has_parent ?n1 .
       ?g ex:can_view ?n1 ;
          a ex:Group
     }
     THEN {
       ?g ex:can_view ?n2
     }
   """ .

ex:node2 ex:has_parent ex:node1 .
ex:group1 a ex:Group ;
         ex:can_view ex:node1 .
  }


and then hit the back buttton it becomes

Slava Kravchenko

unread,
Feb 12, 2016, 4:40:29 AM2/12/16
to Stardog
It's that stupid browser autocorrection fault with "stardom" and and extra ";" stuff, sorry ;-)
I don't have those typos in my original code.

Anyway, I'll double-check some stuff here and let you know if the problem persists.

Thank you for looking up stuff for me.

Slava Kravchenko

unread,
Feb 12, 2016, 5:19:06 AM2/12/16
to Stardog
So, it's still there.

If I use this data:
@prefix rule: <tag:stardog:api:rule:> .

[] a rule:SPARQLRule ;
   rule:content """
     PREFIX ex: <http://example.org/stuff#>

     IF {
       ?n2 ex:has_parent ?n1 .
       ?g ex:can_view ?n1
     }
     THEN {
       ?g ex:can_view ?n2
     }
   """ .

ex:node2 ex:has_parent ex:node1 .
ex:group1 a ex:Group ;
          ex:can_view ex:node1 .

and send query "select * where {?s ex:can_view ?o}", I get the pair:


- no complaints in stardog.log too.

But with this:

@prefix rule: <tag:stardog:api:rule:> .

[] a rule:SPARQLRule ;
   rule:content """
     PREFIX ex: <http://example.org/stuff#>

     IF {
       ?n2 ex:has_parent ?n1 .
       ?g ex:can_view ?n1 ;
          a ex:Group .
     }
     THEN {
       ?g ex:can_view ?n2
     }
   """ .

ex:node2 ex:has_parent ex:node1 .
ex:group1 a ex:Group ;
          ex:can_view ex:node1 .

... I'm getting no inferred statements and this stuff in stardog.log:

WARN  2016-02-12 11:04:17,552 [SPEC-Server-1-1] com.complexible.stardog.reasoning.blackout.ViewAtomToPlanNode:transformView(100): Unsupported cycle or rule for property http://example.org/stuff#can_view 
WARN  2016-02-12 11:04:17,552 [SPEC-Server-1-1] com.complexible.stardog.reasoning.blackout.ViewAtomToPlanNode:transformView(101): Rewriting:

What could be wrong here?

Evren Sirin

unread,
Feb 12, 2016, 8:43:01 AM2/12/16
to Stardog
It is what the error message says: your rule contains a cycle
involving has_parent property and that is not supported. Having the
same predicate both in the rule body (IF) and the the rule head (THEN)
are supported in a limited way. Cycles are allowed only if the rule
body does not contain type triples or filters and the triples in the
rule body are linear (i.e. no cycles in the rule body either). So the
following version of your rule would be supported:

IF {
?n2 ex:has_parent ?n1 .
?g ex:can_view ?n1 .
}
THEN {
?g ex:can_view ?n2
}

Best,
evren

Slava Kravchenko

unread,
Feb 12, 2016, 10:10:30 AM2/12/16
to Stardog
Thanks, Evren!

So the key restriction in my case is that "ex:group a ex:Group" type triple in the rule body, apparently.

May I suggest adding that information about the rule restrictions in Stardog docs?
They look rather significant to me to be ignored :-)

Regardless, thank you for the prompt reply and support!

Zachary Whitley

unread,
Feb 12, 2016, 10:21:32 AM2/12/16
to Stardog
Just put in a pull request for updating docs :)

--
-- --
You received this message because you are subscribed to the C&P "Stardog" group.
To post to this group, send email to sta...@clarkparsia.com
To unsubscribe from this group, send email to
stardog+u...@clarkparsia.com
For more options, visit this group at
http://groups.google.com/a/clarkparsia.com/group/stardog?hl=en

Kendall Clark

unread,
Feb 12, 2016, 10:24:16 AM2/12/16
to Stardog
Slava,

We're updating the docs to be more clear about this, thanks to Zach's PR.

There are warnings about recursion in rules but we're trying to make the warnings more explicit.

--
Reply all
Reply to author
Forward
0 new messages