swrl rules with sameAs

77 views
Skip to first unread message

Peter Neorr

unread,
May 17, 2016, 12:58:53 AM5/17/16
to Stardog
Hi all,

I need some help with some SWRL.  I don't understand why Stardog is not making the inferences I expect.

I have an simple test ontology that defines the following:
 * Peter is an Employee
 * Denise is an Employees.
 * Peter worksFor Champion
 * Denise worksFor Champion
 
Furthermore I have a SWRL rule that employees of the same company are coworkers:
  Employee(e1) ^ Employee(e2) ^ worksFor(e1, c1) ^ worksFor(e2, c2) ^ sameAs(c1, c2) -> hasCoworker(e1, e2)

Given this rule, I would expect to see that "Peter hasCoworker Denise" and "Denise hasCoworker Peter" but this isn't the case.

I've seen some clues on the web that sameAs reasoning will not work unless I explicitly have sameAs axioms in my ontology.  I can understand why this might be necessary if the 2 employees had different worksFor URIs, but in my example the URIs of Denise and Peter's companies are already identical.  In fact, my editor (Protege) won't even allow me to assert that tag:test#champion is the same as tag:test#champion.  

One solution that occured to me is using actual URI in a SWRL rule?  I know how to compare strings in SWRL but I don't know the to bind to the URI of an individual.  Is this possible?  Is there another better solution?

I've attached a turtle file with my test ontology and individuals if it helps explain the issue.

Thanks for any insights.

Regards,
Peter Neorr


test.ttl

Zachary Whitley

unread,
May 17, 2016, 9:00:55 AM5/17/16
to Stardog
I'm getting the following error when issuing a query against the data you sent.

Unknown body atom type: EQUALITY_PROPERTY_ASSERTION
I'm runnning Stardog 4.0.5. Do you see that as well?


--
-- --
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,
May 17, 2016, 9:51:53 AM5/17/16
to Stardog
On Tue, May 17, 2016 at 9:00 AM, Zachary Whitley <zachary...@wavestrike.com> wrote:
I'm getting the following error when issuing a query against the data you sent.

Unknown body atom type: EQUALITY_PROPERTY_ASSERTION
I'm runnning Stardog 4.0.5. Do you see that as well?


What did you set the option for sameAs reasoning to on the database, off, on, or full? (defaults to off if you didn't set it).

I've suspected that I might have some issues with my install so I started with a fresh install and still get the error (4.0.5 and 4.1-RC2)

That brings up an interesting question that I've never thought to ask. When sameAs reasoning is enabled can you explicitly query for the sameAs triple or is the query simply rewritten so that the expected result is entailed?


I suspect that the SameIndividualAtom is unnecessary with the way sameAs reasoning is handled but it's part of the spec so I would expect that it would be supported. I believe you can either set the sameAs option to "on" and assert that the c1 owl:sameAs c2 and drop the SameIndividualAtom from the rule or set the sameAs option to FULL and add axioms that would allow you to infer the sameAs relationship and still drop the SameIndifidualAtom from the rule and get what you're looking for.

 

On Tue, May 17, 2016 at 12:58 AM, Peter Neorr <peter...@gmail.com> wrote:
Hi all,

I need some help with some SWRL.  I don't understand why Stardog is not making the inferences I expect.

I have an simple test ontology that defines the following:
 * Peter is an Employee
 * Denise is an Employees.
 * Peter worksFor Champion
 * Denise worksFor Champion
 
Furthermore I have a SWRL rule that employees of the same company are coworkers:
  Employee(e1) ^ Employee(e2) ^ worksFor(e1, c1) ^ worksFor(e2, c2) ^ sameAs(c1, c2) -> hasCoworker(e1, e2)

Given this rule, I would expect to see that "Peter hasCoworker Denise" and "Denise hasCoworker Peter" but this isn't the case.

I've seen some clues on the web that sameAs reasoning will not work unless I explicitly have sameAs axioms in my ontology.  I can understand why this might be necessary if the 2 employees had different worksFor URIs, but in my example the URIs of Denise and Peter's companies are already identical.  In fact, my editor (Protege) won't even allow me to assert that tag:test#champion is the same as tag:test#champion.  

You'll need explicit sameAs axioms if the sameAs option is set to "on"
 

Evren Sirin

unread,
May 17, 2016, 10:05:48 AM5/17/16
to Stardog
Hi Peter,

I don't understand why you want to use sameAs atom in your rule. You
can simply use one variable (c) instead of two variables (c1 and c2)
and this would be semantically equivalent and should work as expected
without turning on sameAs reasoning.

Best,
Evren

On Tue, May 17, 2016 at 9:51 AM, Zachary Whitley

Zachary Whitley

unread,
May 17, 2016, 1:11:52 PM5/17/16
to Stardog
It looks like I should have looked closer at the data. I assumed that there were at least two people that worked for separate named companies that were inferred to be the same company. I updated the data slightly with the following modifications

Created two separate companies :champion and :championtech, made :peter an employee at :champtech, :denise an employee at :champion and poor bucky an employee at :pizzaplanet. I updated the rule to assert that someone has a coworker if they work at the same company Employee(e1) ^ Employee(e2) ^ worksFor(e1, c1) ^ worksFor(e2, c1)  -> hasCoworker(e1, e2)

The changes are included in the atached file test-new.ttl.


#load data
stardog-admin db create -o reasoning.sameas=ON -n test -- test-new.ttl

#query w/o reasonng
stardog query test "select * where {?s :hasCoworker ?o}"

+---------+---------+
|    s    |    o    |
+---------+---------+
| :denise | :denise |
| :bucky  | :bucky  |
| :peter  | :peter  |
+---------+---------+

#I'm actually a little surprised that it asserted this. Is this correct?

#query w/ reasoning

stardog query test -r  "select * where {?s :hasCoworker ?o}"

+---------+---------+
|    s    |    o    |
+---------+---------+
| :denise | :denise |
| :bucky  | :bucky  |
| :peter  | :peter  |
+---------+---------+


# assert :champion and :champtech are the same

stardog query test "insert data { :champion owl:sameAs :champtech }"

#query with reasoning again


stardog query test -r  "select * where {?s :hasCoworker ?o}"

+---------+---------+
|    s    |    o    |
+---------+---------+
| :bucky  | :bucky  |
| :peter  | :peter  |
| :peter  | :denise |
| :denise | :peter  |
| :denise | :denise |
+---------+---------+




test-new.ttl

Peter Neorr

unread,
May 17, 2016, 1:59:46 PM5/17/16
to Stardog
It was just that simple.  Using the a single company variable c, did what I wanted.  Leave it to me to over-complicate things.  :)

However,  this leads a Now the reasoner concludes that "Denise hasCoworker Denise".  How might I prevent this?



Thank You!

-Peter

Zachary Whitley

unread,
May 17, 2016, 2:07:15 PM5/17/16
to Stardog
I was a little confused when I saw that at first as well. It really highlights how much better the Stardog SWRL synatax is. Once you rewrite it it's much easier to see. I believe you need to update your rule to include e1 != e2

Zachary Whitley

unread,
May 17, 2016, 2:14:39 PM5/17/16
to Stardog
@prefix rule: <tag:stardog:api:rule:> .

[]
  a rule:SPARQLRule ;
  rule:content """
    PREFIX co: <http://purl.org/co/>
    PREFIX swrlb: <http://www.w3.org/2003/11/swrlb#>
      IF {

        ?e1 :worksFor ?c .
        ?e1 a :Employee .
        ?e2 :worksFor ?c .
        ?e2 a :Employee .
        FILTER(?e1 != ?e2)
          }
      THEN {
        ?e1 :hasCoworker ?e2
          }""" .

Reply all
Reply to author
Forward
0 new messages