expressing rules with swrl

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

expressing rules with swrl

lynsie
This post was updated on .
I am trying to create an ontology using protege 4.3 and I want to:
 First, I want to get the speedest robot using swrl rule, but i didn't find a
way to do it. I tried this but it didn't work:
Robot(?r),hasSpeed(?r,?speed)->select(?r),max(?speed)
 Secondly, express this rule: if a task cannot be executed by any robot so it needs human intervention. I tried this but it didn't work:
Task(?t),(CanBeExecutedBy exactly 0 Robot)(?t)->NeedsHumanIntervention(?t)




--
Sent from: http://protege-project.136.n4.nabble.com/Protege-User-f4659818.html
_______________________________________________
protege-user mailing list
protege-user@lists.stanford.edu
https://mailman.stanford.edu/mailman/listinfo/protege-user
Reply | Threaded
Open this post in threaded view
|

Re: expressing rules with swrl

Michael DeBellis-2
Lynsi, why are you using 4.3? That is an old version of Protege and from what I remember that version doesn't support SWRL all that well. So everything I'm going to say pertains to the latest version and going back one or two versions. I would very strongly encourage you to use the latest version. It will be hard to support you if you encounter potential bugs or other problems in such an old version. 

Regarding the oldest person that is a bit tricky  because of the Open World Assumption (OWA), certain things that would be straight forward in most DB's or programming language that use the Closed World Assumption are more complicated with the OWA.  If all you want to do is to FIND the oldest person I think that can be done with SQWRL. In fact it looks like you are trying to use SQWRL in your rule (although I would expect to find "sqwrl:" appended to sqwrl operators such as select and max). The issue is that SQWRL is strictly a query rule language and unlike SWRL you can't assert things you find with SQWRL back into your ontology. 

But to find the oldest person you could do something similar to this:

 Patient(?p) ^ hasTreatment(?p, ?t) ^ hasDrug(?t, ?d) ^ hasDose(?t, ?dose) ˚
 sqwrl:makeBag(?b, ?dose) ^ sqwrl:groupBy(?b, ?p, ?d) ˚
 sqwrl:max(?max, ?b)
 -> sqwrl:select(?p, ?d, ?max) 

which is an example from this page: https://github.com/protegeproject/swrlapi/wiki/SQWRLCollections I think it's fairly obvious how to adapt that example and find the oldest person. Remember all this will do is to print out the oldest person. If you want to actually assert something about the oldest person I think what you would need to do is to put them into a List using one of the Collection vocabularies (e.g., this: https://lov.linkeddata.es/dataset/lov/vocabs/coll ) then sort the the list by age.

Regarding your second question, using DL expressions in the current SWRL tab isn't supported so while the SWRLTab would be able to parse that rule it wouldn't execute it. There is another pane in Protege called the Rules pane which I think does support class expressions so you could try that. If you look at my short SWRL tutorial: https://symbolicshacker.blogspot.com/2017/06/swrl-process-modeling-tutorial.html  I have an example of using the Rules pane and using DL syntax to describe a behind schedule task.

But while it can be used, in actual work I never use the Rules pane. I prefer the SWRL Tab and anything that can be described in DL I've found can virtually always be described as an axiom for a defined class or in different language in a SWRL rule. 

E.g.,  for what you want I think a simple SWRL rule (defined in the SWRL tab) should work. So just to clarify, I think what you meant is if a person has at least 1 car (rather than "more than 1") then they can drive. The following rule should work for that: 

Person(?p) ^ hasCar(?p,?c) -> CanDrive(?p)  

In this case CanDrive is a class, probably a subclass of Person. I think you could also just make CanDrive a defined class with the DL: "hasCar min 1 car" and that would work as well without needing SWRL. 

If you want to make canDrive a boolean data property then the rule would be: 

Person(?p) ^ hasCar(?p,?c) -> canDrive(?p, true)    

Michael

On Thu, Jun 20, 2019 at 8:06 AM lynsie <[hidden email]> wrote:
I am trying to create an ontology using protege 4.3 and I want to:
 First, I want to get the oldest person using swrl rule, but i didn't find a
way to do it. I tried this but it didn't work:
Person(?p),hasAge(?p,?age)->select(?p),max(?age)
 Secondly, express this rule: if a person has more than 1 car so he can
drive. I tried this but it didn't work:
Person(?p),(hasCar min 1 Car)(?p)->canDrive(?p)




--
Sent from: http://protege-project.136.n4.nabble.com/Protege-User-f4659818.html
_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user

_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user
Reply | Threaded
Open this post in threaded view
|

Re: expressing rules with swrl

lynsie
Thank you so much for your reply.
Is it possible to run the rule using Pellet reasoner?



--
Sent from: http://protege-project.136.n4.nabble.com/Protege-User-f4659818.html
_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user
Reply | Threaded
Open this post in threaded view
|

Re: expressing rules with swrl

Michael DeBellis-2
Your Welcome. Yes, actually I should have mentioned that, you should definitely use the Pellet reasoner, it has the best support for running SWRL rules. 

Also, one thing that I find confuses some new SWRL users are the 3 buttons at the bottom of the SWRL Tab that give options for Drools. What Drools is is a bit complicated to explain in a short message but the important thing to remember for new users is: Ignore It! All you need to do to get your SWRL rules to run is to just run the Pellet reasoner and it will execute your rules just as it will execute any DL axioms you have defined and axioms about object properties being transitive, inverses, etc. 

Also, another common question I hear is people asking how they can save the result of the SWRL rules (as well as other inferences from the Reasoner). You can do that by using the "File>Export inferred axioms as ontology" option. That option is often very useful, for example some parts of the UI only show user defined axioms and don't show information inferred by the reasoner. Doing the export option can help with that as well, what that option does is to give you an ontology where all the inferences of the reasoner (including the results of SWRL rules) are saved as if they were declared by the user. That option is also useful if you want to upload your ontology to Web Protege because as of now Web Protege doesn't support reasoners. 

Michael


On Thu, Jun 20, 2019 at 1:21 PM lynsie <[hidden email]> wrote:
Thank you so much for your reply.
Is it possible to run the rule using Pellet reasoner?



--
Sent from: http://protege-project.136.n4.nabble.com/Protege-User-f4659818.html
_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user

_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user
Reply | Threaded
Open this post in threaded view
|

Re: expressing rules with swrl

lynsie
Actually, I created the rule but it is not enabled (I can't check the box to
enable it). Could you tell me please what should I do?



--
Sent from: http://protege-project.136.n4.nabble.com/Protege-User-f4659818.html
_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user
Reply | Threaded
Open this post in threaded view
|

Re: expressing rules with swrl

Michael DeBellis-2
Can you send another message where you include your ontology as an attachment? I'll take a look and see if I can tell why it's not working. It's hard to say without seeing the actual ontology and the rule. 

Michael

On Fri, Jun 21, 2019 at 1:39 AM lynsie <[hidden email]> wrote:
Actually, I created the rule but it is not enabled (I can't check the box to
enable it). Could you tell me please what should I do?



--
Sent from: http://protege-project.136.n4.nabble.com/Protege-User-f4659818.html
_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user

_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user
Reply | Threaded
Open this post in threaded view
|

Re: expressing rules with swrl

Michael DeBellis-2
In reply to this post by lynsie
lynsie, I have a very small Car ontology that I've used in the past to demonstrate some basic concepts to new users. So I just took a look at it and realized I could add the kind of rule I think you need very easily. I've attached it. You can see the rule in the SWRL tab:

Person(?p) ^ hasCar(?p, ?c) -> canDrive(?p, true) 

Actually, the rule also has the name of the ontology as a prefix to each name. This is a minor bug that I thought was fixed in the latest version, I haven't seen it in the rules that I've written recently in other ontologies but it seems to have popped up again. In any case it doesn't matter, it makes the rules look a bit uglier but it has no effect on how they work. If you load my sample ontology and run the Pellet reasoner you should see that the individual Mary  who hasCar Car1 has the data property canDrive set to true. You will see that the data property assertion is highlighted in yellow because it was inferred by the reasoner rather than declared by the user and if you click on the "?" next to the assertion you should get a pop-up menu that explains the assertion was made as a result of the SWRL rule and the fact that Mary hasCar Car1. 

If you are still having trouble though feel free to send your ontology and I'll take a look. 

Michael


On Fri, Jun 21, 2019 at 1:39 AM lynsie <[hidden email]> wrote:
Actually, I created the rule but it is not enabled (I can't check the box to
enable it). Could you tell me please what should I do?



--
Sent from: http://protege-project.136.n4.nabble.com/Protege-User-f4659818.html
_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user

_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user

CarExample.owl (23K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: expressing rules with swrl

lynsie
Actually, all the swrl rules are enabled now except the one which starts with
"sqwrl:". Is it because that Pellet reasoner cannot support sqwrl?



--
Sent from: http://protege-project.136.n4.nabble.com/Protege-User-f4659818.html
_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user
Reply | Threaded
Open this post in threaded view
|

Re: expressing rules with swrl

Michael DeBellis-2
No, Pellet supports sqwrl. You need to run the sqwrl queries in the SQWRL Tab not the SWRL Tab. If you don't see the SQWRL Tab then go to Windows>Tabs and select it, you should see one then. In the SQWRL Tab hit the big Run button at the bottom and that should run your queries. It will create a new tab in the bottom pane with the results of the query. Make sure to run the reasoner on the latest version of the ontology before you run the SQWRL query. 


On Fri, Jun 21, 2019 at 8:49 AM lynsie <[hidden email]> wrote:
Actually, all the swrl rules are enabled now except the one which starts with
"sqwrl:". Is it because that Pellet reasoner cannot support sqwrl?



--
Sent from: http://protege-project.136.n4.nabble.com/Protege-User-f4659818.html
_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user

_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user
Reply | Threaded
Open this post in threaded view
|

Re: expressing rules with swrl

lynsie
I got it, thank you so much.
I have one more question: is there a way to save the result obtained in the
ontology (I want to make inferences on the oldest person)



--
Sent from: http://protege-project.136.n4.nabble.com/Protege-User-f4659818.html
_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user
Reply | Threaded
Open this post in threaded view
|

Re: expressing rules with swrl

Lorenz Buehmann
In reply to this post by Michael DeBellis-2
@Michael

No, Pellet supports sqwrl.
you meant does not support SQWRL, right? I mean, it's just a query extension for SWRL but not part of any standard nor supported by Pellet. Moreover, none of the custom predicates of the SWRL API are supported by Pellet, so any rule using those predicates will only lead to results in the SWRL Tab, but not in any other view of Protege.
You need to run the sqwrl queries in the SQWRL Tab not the SWRL Tab. If you don't see the SQWRL Tab then go to Windows>Tabs and select it, you should see one then. In the SQWRL Tab hit the big Run button at the bottom and that should run your queries. It will create a new tab in the bottom pane with the results of the query. Make sure to run the reasoner on the latest version of the ontology before you run the SQWRL query. 


On Fri, Jun 21, 2019 at 8:49 AM lynsie <[hidden email]> wrote:
Actually, all the swrl rules are enabled now except the one which starts with
"sqwrl:". Is it because that Pellet reasoner cannot support sqwrl?



--
Sent from: http://protege-project.136.n4.nabble.com/Protege-User-f4659818.html
_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user

_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user
-- 
Lorenz Bühmann
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center

_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user
Reply | Threaded
Open this post in threaded view
|

Re: expressing rules with swrl

Lorenz Buehmann
In reply to this post by Michael DeBellis-2


Thank you so much for your reply. 
Is it possible to run the rule using Pellet reasoner?

There is a difference between an SWRL rule and a SQWRL query. You can't export those inferences which will only show up in the SQWRL Tab.

Pellet can't handle anything beyond standard SWRL, and SQWRL as well as many other built-in predicates of the SWRL API extensions are not part of SWRL. Moreover and most importantly, those SQWRL queries are indeed non-monotonic once you use things like grouping, min, max, whatever, so it would be impossiblöe to use this in deductive monotonic reasoning like it's done for SWLR and OWL.

Unless SWRL Tab has some export feature, you won't be able to export the results (copy and paste might lead to CSV maybe?)




--
Sent from: http://protege-project.136.n4.nabble.com/Protege-User-f4659818.html
_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user

-- 
Lorenz Bühmann
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center

_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user
Reply | Threaded
Open this post in threaded view
|

Re: expressing rules with swrl

Igor Toujilov-2
In reply to this post by lynsie
You can find an OWL example on how to find the oldest person(s) at [1]. This is a fresh example on partially closing the world with the linked list, and calculating the aggregation property over the list.  In this case the aggregation property is the earliest date of birth. The oldest person(s) and their date of birth are inferred in standard OWL+SWLR, and can be used is other inferences.
The drawback is the list maintenance, which is hard to do manually. In my MELO project on SourceForge I am developing an automated tool: a command-line utility to generate the aggregation ontology. This tool should create the list automatically. But it is not ready yet.

Cheers,
Igor

[1] https://sourceforge.net/p/meloproject/code/ci/master/tree/OWL/examples/oldest_person.owl


> Sent: Friday, June 21, 2019 at 9:22 PM
> From: "lynsie" <[hidden email]>
> To: [hidden email]
> Subject: Re: [protege-user] expressing rules with swrl
>
> I got it, thank you so much.
> I have one more question: is there a way to save the result obtained in the
> ontology (I want to make inferences on the oldest person)
>
>
>
> --
> Sent from: http://protege-project.136.n4.nabble.com/Protege-User-f4659818.html
> _______________________________________________
> protege-user mailing list
> [hidden email]
> https://mailman.stanford.edu/mailman/listinfo/protege-user
>
_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user