I've been following the user support list for Protege for quite a while now and I've noticed that some problems seem to come up frequently. This is the first of what I plan to be a series of posts about little tricks, common problems, and resolutions that I think will be useful for many new users of OWL, SWRL, and Protege.
The first one deals with a common issue with SWRL rules displayed in the Protege SWRLTab. Often the rules will be displayed with the name of the ontology (or "autogen0") as a prefix to every terminal in the rule.
For example, in a simple car ontology that I created to demonstrate some concepts to a new user I had a SWRL rule to define that a Person canDrive if they have a car:
Person(?p) ^ hasCar(?p, ?c) -> canDrive(?p, true)
However, after running the reasoner, the rule then looked like this:
untitled-ontology-165:Person(?p) ^ untitled-ontology-165:hasCar(?p, ?c) -> untitled-ontology-165:canDrive(?p, true)
In all cases this is not a serious problem. The prefix does not effect the reasoning and one can even edit the rules without using the prefix and they will just be added in automatically. However, the prefixes look confusing and somewhat negate one of the main goals of rules which is that they should be intuitive descriptions of business logic.
Note: I've had some recent experience with some SWRL rules in ontologies where the following solution doesn't work. So this is something to try but unfortunately it is not guaranteed to always solve the problem. If anyone finds additional solutions please contact me or leave a comment.
The solution is simple but it requires something that I try to avoid like the plague which is to edit your OWL file with a text editor rather than with Protege. I typically use Notepad++ on Windows. Notepad++ does additional things such as highlight XML based on the structure of the document and balance parentheses and brackets. You should either use Notepad or some similar very simple text editor. You don't want to use something like MS Word or any other WYSIWYG word processor because of course those don't edit plain text, they look for (and may insert if they don't find it) statements in markup languages like RTF which will of course destroy your OWL file.
Also, you should make sure to turn off all the "smart" options on your text editor. The first time I edited an OWL file manually I used the default text editor on a Mac and the default for that editor was to replace all quotes with "smart quotes" which made the OWL file impossible to parse.
Open your OWL file in the text editor and look for a mapping statement like this:
xmlns:untitled-ontology-165="http://www.semanticweb.org/michaeldebellis/ontologies/2019/3/untitled-ontology-165#"
In my experience Protege often inserts a statement like this for you in an ontology even though you don't need it. The statement should be near the top of your file. You can just remove that statement and then save your file. Note: make sure that your saved file still has a ".owl" file extension. When I used Notepad just now it saved my file as a text file and I had to edit the extension to make it an OWL file again.
After the change when I loaded the edited ontology and ran the reasoner the rule now looks as I would expect it to:
Person(?p) ^ hasCar(?p, ?c) -> canDrive(?p, true)
The unwanted prefixes have been removed. Thanks to Martin O'Connor for helping me figure this out a long time ago. The archived email post with Marin's answer can be found here: Archived Post from Protege List.
Comments