Wednesday, June 7, 2017

SWRL Process Modeling Tutorial

Please Note that this blog is no longer active.  For my new blog please go to: https://www.michaeldebellis.com/blog     I have published a new version of the classic Protege/OWL Pizza tutorial that includes SWRL, SHACL, and SPARQL introductions:  https://www.michaeldebellis.com/post/new-protege-pizza-tutorial and the original SWRL process model can be found here:  https://www.michaeldebellis.com/post/swrl_tutorial 

The following is a tutorial for using the Semantic Web Rule Language (SWRL) with the Protege ontology editor.  I chose the process modeling domain because I think it is something many people can relate to.  Also, it's a simple example that highlights some of the powerful mathematical capabilities that are a result of the set theoretic foundation of OWL and SWRL. At least that was my hope.

Here is the PDF of the tutorial: SWRL Process Modeling Tutorial

The initial ontology to start the tutorial is here: SWRLProcessTutorialStart-V2.owl

The final version of the ontology, with an example waterfall model is here: SWRLProcessTutorialFinal.owl

Thanks to all the people on the Protege user support list for answering my endless stream of questions, special thanks to Martin O'Connor.

If you have questions or comments about the tutorial feel free to email me: mdebellissf@gmail.com

Also, the following document has nothing to do with SWRL but it is something I think many new comers to working with Protege and OWL might find useful. OWL (the language underneath Protege) is based on logic and set theory. For those who don't know or are rusty on those concepts here is a PDF that is a good overview of the basics. Don't be misled by the cover page, this is from a book on Mathematical Methods in Linguistics but this is just the first chapter which is a nice overview of logic and set theory:  Partee, et. al. Basic Concepts of Set Theory




15 comments:

  1. Replies
    1. You're welcome. Just FYI, I don't post on this blog anymore. See here: https://www.michaeldebellis.com/blog for my current blog. Note that I have a whole new expanded version of the Pizza tutorial that includes sections on SPARQL, SHACL, and SWRL: https://www.michaeldebellis.com/post/new-protege-pizza-tutorial

      Delete
  2. OMG, I have an actual user! Thank you! Seriously, I'm glad you found it useful. Feel free to email me or comment if you have questions or feedback.

    ReplyDelete
  3. Thank you @Michael DeBellis for this useful materials I followed step by step as you advised me in Protege mailing list.
    I have questions about how we can express the logic of processes e.g., if we have process x, process y,and process z. process y should be completed before starting process z, and process x should be finished to start process y.
    how we can express that in protege to show it as templates. So when show the process y it is showing also that there are other processes x and z connected with it.

    Thanks you again.

    ReplyDelete
    Replies
    1. Husain, That is an excellent question and I wish I had a better answer for you. It is definitely possible to do this. One of the reasons I used process modeling as an example is that I think one could create a very useful process model ontology with Protege and SWRL. For example, if you look here: https://github.com/protegeproject/swrlapi/wiki/ModellingTime and here: https://www.w3.org/Submission/SWRL/ You will find an incredibly rich collection of operators for reasoning about time and durations. Do two durations overlap, etc. One could write SWRL rules to express various constraints about processes in general or about specific processes or methodologies.

      But exactly how to do it, I'm not sure. There are several alternative ways and issues to be worked out. For example, one approach I used when I built a system for the USAF called the Knowledge Based Software Assistant was to have classes represent a methodology model. Where I worked we had a whole methodology that said "when you build system X first do a, b, c" So I made everything in the methodology a class and because in the language I was working in (a logic programming language called Refine) there was a rich meta-model I could create a lot of connections between the classes. Then when I instantiated a model (i.e., used the methodology classes as a template for an actual project) it was very elegant, you just filled in a few parameters and made instances of each class and they all had the appropriate links and constraints. But meta-modeling isn't as well supported in OWL.

      Sorry, I'm going on at length because what you are asking is a very interesting problem that I've thought about but the real answer is I don't have a specific solution worked out for how to do this in OWL. I think the tools are definitely there but I haven't given it enough thought to work out a complete answer.

      Delete
  4. Thank You Michael,
    in the second paragraph, you pointed to exactly the issue that I trying to solve [ Creating a template for the operations based on the resources available], it is rely interesting to share your knowledge about modeling.

    Thank you again for the links, but for the usage of SWRL rules, is it enough to create my restrictions (process y should be completed before starting process z, and process x should be finished to start process y) and to represent the sequences of the processes ?
    Best!

    ReplyDelete
    Replies
    1. In the basic model I have in the tutorial you can represent sequential processes just by creating the appropriate objects and using the rules that you write. Look at the object Iteration1 for an example. You need to specify the startTask for a SequentialProcess and then you need to specify an order. So each task needs to have it's hasNextProcess attribute specified. That give you the order and then from there the rules you write (should be S1 and S2 if you accept the default names) will compute the durationFromStart for each process and when you get to the last process in the sequence it's durationFromStart is the duration of the entire Process (the SequentialProcess that has all those tasks as subProcesses). That at least gives you the duration for a sequential process. But other kinds of constraints or reasoning about overlaps, etc. need to be defined with additional rules or DL statements.

      BTW, another approach would be to use the full power of the Collections ontology: http://lov.okfn.org/dataset/lov/vocabs/coll I originally started using this ontology but I thought it was too complicated for an intro tutorial. The collection ontology allows you to have the same task exist in different parts of the model because you aren't putting the properties like nextItem on the task itself (which binds it to just one specific part of the model) but rather you are creating a container and you are putting the nextItem information on the container that holds the task so the task can be held in multiple containers and in each case have pointers to different next tasks.

      Hope that makes sense.

      Delete
    2. One other thought I had regarding process modeling: there is a researcher at USC who is a friend of mine named Walt Scacchi. Walt has done some very interesting work on process modeling along with one of his graduate students a guy named Pei Wei Mi. I looked for some of their papers but they've written a ton and most of them are fairly dated. But if you are interested I would recommend doing a search. I did find this book which looks like it might be worth getting:

      http://onlinelibrary.wiley.com/doi/10.1002/1099-1670(200006/09)5:2/3%3C183::AID-SPIP115%3E3.0.CO;2-D/abstract

      Delete
    3. Thank you very much for an interesting discussion !

      What if we do not specigy the property "hasNextProcess", but we specify "hasOutputResource" of each Task and "hasInputResource"?

      Can we somehow achieve the same result, i.e build the whole process of tasks by a query?

      Delete
    4. I'm not sure I completely understand the change you are proposing but I think it could be done. One thing I've come to appreciate is that SPARQL has a lot of power that SWRL doesn't so SPARQL might be a better way to build a true process ontology. E.g., you aren't hindered by the Open World Assumption in SPARQL. Also, FYI, I have a new blog with some additional tips for Protege and OWL, this site isn't active. You might want to check this out: https://www.michaeldebellis.com/post/best-practices-for-new-protege-users

      Delete
  5. Thank Michael,
    the http://lov.okfn.org/dataset/lov/vocabs/foaf
    it is really a nice work, but as you saying it quite complicated.
    I start my ontology from scratch. to represent the operations, the processes, and the tasks in constructions domain. so what I mean here by operation or process are on site or construction site works, which are need to model in the ontology. So I have different operations that need to be in sequences. Moreover I have different processes, which are under each operation that also need to be in sequences.
    I think the example for the SW processes is more close to what I want to develop. But in the same time I need to create a patterns for these different works on the site.
    Thus, If i chose any operation or process (e.g operation1) the ontology or the model gives me the suitable pattern through the GUI to perform Operation1.

    I hope that make sense...

    Best!

    ReplyDelete
  6. Hi,

    Thanks for this tutorial, is very useful.

    ReplyDelete
  7. Excellent tutorial!! I did not get inference from the SWRL rules initially until I realized the "Data Property Assertions" in reason configuration was not turned on. Just want to mention it here in case others encounter the same issue.

    ReplyDelete
    Replies
    1. Thanks very much for your comment. That's a good point, if I get a chance I will update the tutorial. It's something I see on the Protege user mailing list all the time. People expect the reasoner to infer things but the defaults are set to be fairly limiting as far as what the Reasoner tries to do. In case anyone is having the same issue, after you start the reasoner go to Reasoner>Configure That will bring up a check box menu. For this tutorial you can just check all the boxes because the ontology is small. In fact that is what I usually do, I check all the boxes and I only start to uncheck them if I get a really large ontology where it's taking a long time every time I run the reasoner.

      Delete