SWRLTab usage in Protege - owl

Everyone,
I'm used to Protégé but now, I'm trying to use SWRLTab, a Protégé plugin.
The problem is that I'm really not familiar with the SWRL rule-syntax. Let's have fun with my problem :
I've an well-known ontology, called "pizza". Let's say I've a 4cheesesPizza, subclass of Pizza.
I don't want to write the "hasTopping exactly 4 CheesyTopping" thing in the "Equivalent To" tab of Protégé BUT I want to write it in the SWRL Rule syntax. (yes I know it's stupid, but this is an example and in my real case, write a rule makes sense).
I tried something like Pizza(?p) ^ hasTopping(?p,?t) but next, I'm quite blocked. I don't know what to do.
Moreover, when I launch OWL + SWRL -> Drools , in the Inferred Axioms there's already more than 100 lines, It's unreadable.
If someone has the solution,
Thanks, Clément

What you want to do in SWRL is not possible. I.e. SWRL will need to count the number of individuals that are in a hasTopping relation with a specific individual p of type Pizza. SWRL cannot do that, but the OWL reasoner can, hence what you have specified in Protege is the correct way to do it.
As an example for SWRL syntax, assume you have classes ExpensiveTopping and ExpensivePizza you could add a rule in the SWRL tab to determine an expensive pizza:
Pizza(?p) ^ hasTopping(?p,?t) ^ ExpensiveTopping(?t) -> ExpensivePizza(?p).

Related

Does SWRL support classical negation in Protege?

I wanted to try the following rule:
(not Person)(?x) -> NonHuman(?x) which is provided here - https://github.com/protegeproject/swrlapi/wiki/SWRLLanguageFAQ#does-swrl-support-classical-negation
and i got this:
Is classical negation supported in Protege 5.5.0? If yes, how I can make the following rule to be okay?
Thanks in advance!
From https://github.com/protegeproject/swrlapi/issues/63:
Unfortunately, the SWRLAPI's parser does not support OWL class expressions in rules.
There is no timeline for their inclusion.
Fortunately, one can use the Rules view (Windows > Views > Ontology Views > Rules):
Rule: (not Person)(?x) -> NonHuman(?x) is parsed correctly and works as intended.
Actually, you do not need SWRL in this particlular case. Just write (not Person) SubClassOf NonHuman in the General class axioms section, or define NonPerson first, if you don't like GCI axioms.
Don't forget about the OWA.

What are the consequences of declaring a property subPropertyOf a DublinCore property

When creating an OWL ontology, what are the consequences of declaring :
ex:myHasPart a owl:ObjectProperty .
ex:myHasPart owl:subPropertyOf <http://purl.org/dc/terms/hasPart> .
In OWL 1 : I read from http://bloody-byte.net/rdf/dc_owl2dl/ that it implies that ex:myHasPart will be an AnnotationProperty. Can it be both an ObjectProperty and an AnnotationProperty ?
In OWL 2 : What would be the consequences/entailments ?
How can I choose in Protégé to work in OWL1 or OWL2 ?
Additionnally, what are the consequences in terms of OWL-DL vs. OWL-Full ? would my ontology still be at the OWL-DL level ?
Is it a good practice to declare subProperties of dcterms like this ? I think I need a general explanation on this.
What could be the alternative to link ex:myHasPart with dcterms:hasPart ? rdfs:seeAlso ? skos:broadMatch ?
From the two triples you write, we can just say that if you have a triple <x> ex:myHasPart <y>, then we can infer <x> dc:hasPart <y> (in both OWL 1 and OWL 2, using either direct semantics or RDF-based semantics).
But the complete consequences of the axioms can only be fully estimated by knowing what else is in your ontology. If you only have those two triples, your ontology is not in OWL (1/2) DL. But reasoners won't care, they'll usually assume that dc:hasPart is an object property too, and things will be just fine. Also, if you have an additional statement saying:
dc:hasPart a owl:AnnotationProperty .
then the ontology is not valid OWL DL, nor OWL 2 DL, no matter what else you have in it (an IRI can only be denoting at most one type of property, annotation, datatype, or object). It is still usable in many OWL tools that will not care (like Protégé, for instance). Reasoners probably don't care either, as long as you don't use the properties in bizarre ways, e.g., with both literals and non literals.
To answer specifically to your questions:
In OWL 1 : I read from http://bloody-byte.net/rdf/dc_owl2dl/ that it implies that ex:myHasPart will be an AnnotationProperty. Can it be both an ObjectProperty and an AnnotationProperty ?
No, the two triples imply that ex:myHasPart is an owl:ObjectProperty. In an OWL 2 ontology, a property cannot be object and annotation at the same time. In an OWL 2 Full ontology, they can (an OWL 2 Full ontology is just an RDF graph). In OWL 1, an OWL DL ontology cannot have an object property that is an annotation property at the same time, while an OWL Full ontology can.
In OWL 2 : What would be the consequences/entailments ?
Pretty much the same thing as in OWL 1, but it depends what semantics you are using: Direct Semantics or RDF-based semantics? The direct semantics only applies to OWL 2 ontologies, not to OWL 2 Full ontologies, so you would have to, at least, declare your ontology <yourOnto> a owl:Ontology and declare the term dc:hasPart as an owl:objectProperty. Reasoners can be more tolerant. In any case, there is not going to be anything bad happening, unless you are messing up with the rest of the ontology.
How can I choose in Protégé to work in OWL1 or OWL2 ?
You can choose a version of Protégé that does not support OWL 2 (if you can still manage to find one). Otherwise, any version after 4.0 uses OWL 2. But from a syntactic point of view, there is no reason to restrict to OWL 1. The reasoning is done independently from the editor in Protégé, so whether you have OWL 1 or OWL 2 reasoning depends on which plugin you have. However, OWL reasoners that do not support OWL 2 are simply obsolete, there is not much sensible reasons to still use them.
Additionnally, what are the consequences in terms of OWL-DL vs. OWL-Full ? would my ontology still be at the OWL-DL level ?
I think I already explained this.
Is it a good practice to declare subProperties of dcterms like this ? I think I need a general explanation on this.
I do not see any reason why it would be considered good practice, but I don't see a reason to actively prevent people from doing so.
What could be the alternative to link ex:myHasPart with dcterms:hasPart ? rdfs:seeAlso ? skos:broadMatch ?
Your suggestions seem valid to me. But do you really need to make that link explicit?

What is the main difference between instances and sub-classes?

This question is about Ontologies , I am implementing an ontology about potential physical attacks on wireless sensors as devices.
I created class Modification_Attack meaning attacks which modify in the sensor itself. I created Programming_Modification as an instance of this class, is this logical, is it better a sub-class or neither an instance nor a sub-class?
What is the main difference between instances and sub-classes?
This question isn't really unique to OWL ontologies; it comes up in object-oriented programming, and in set theory in mathematics. A class is a collection of its members. E.g.,
Person ≡ { person1, person2, … }
Suppose you have another class:
TallPerson ≡ { person63, person102, … }
A class A is a subclass of the class B if every element of A is also an element of B:
(A &subseteq; B) ≡ (x &in; A &rightarrow; x &in; B)
So, for instance, if every member of TallPerson is also a member of Person, then TallPerson is a subclass of Person.
I created class Modification_Attack meaning attacks which modify in
the sensor itself.I created Programming_Modification as an instance of
this class , is this logical , is it better a sub-class or neither an
instance nor a sub-class?
This is a choice that you need to make. It really depends on the context and how you intend to use the ontology. If you're observing attacks in the wild and trying to categorize them, you probably want a subclass, but you'll want to have instances of Programming_Modification. That is, you'll want something like:
Programming_Modification ≡ { attack24, attack89, … }
But if you've got some other kind of use case, where you you want to talk about Programming_Modification as a single entity, then it might make more sense for it to be an individual.
I have been thinking through the same issue. And I think the same thing can be both an instance and a subclass depending on whether you plan to use it conceptually or not, which can be simplified to whether you would describe it using the or a.
For example, I am working on a materials ontology, where the main class is Material. A particular type of material is Steel. If I say the steel then steel an instance of Material. If I say a steel then Steel is a subclass of Material. Further, steel is an instance of Steel. And it would be more appropriate to also give it some kind of meaningful identifier like steel-1.
It all seems to come down whether you are using a term as a conceptual class or as a name for some instance of that class. In your case, I think it would probably be more appropriate to say Programming_Modification is a subclass as you could probably have many of such modifications which you would refer to as the first Programming_Modification or the second Programming_Modification . Would love to see what you came up with though if you have a solution.

Using Property Chains to get inferred Knowledge in an OWL Ontology(Protege)

I have modelled the following in my Ontology:
Club employs some Player, Player hasNationality some Nationality, Player hasNationalStatus value National_Player, Country is equivalent to Nationality.
I want the Ontology to infer that:
If a Player hasNationality some Nationality and, Player hasNationalStatus value National_Player then, Country(Same as the nationality the player has) employs Player.
As an example:
{Steven_Gerrard} hasNationality value England and, {Steven_Gerrard} hasNationalStatus value National_Player therefore, {England} employs [Steven_Gerrard}.
Is there a possible way to add this knowledge to Protege?
Thanks.
Edit:
Error Messages:
Error 42 Logged at Tue Apr 01 20:49:24 BST 2014
OWLReasonerRuntimeException: Non-simple object property 'http://www.semanticweb.org/u1cjd/ontologies/2014/1/untitled-ontology-2#employs' is used as a simple one
and
Error 43 Logged at Tue Apr 01 20:49:24 BST 2014
ReasonerInternalException: tRole.cpp:243: assertion 'Ancestor.empty() && Descendant.empty()' fails
This is possible, and it's actually very similar to the technique I mentioned in an answer to your previous question, Adding statements of knowledge to an OWL Ontology in Protege), and the structure of this answer is almost identical to my answer to a recent answers.semanticweb.com question, OWL property inference from blank node - modelling.
You just need to use some rolification and a property chain axiom. The point to note is that the existing data has the form of the upper arrows, and the desired information is in the lower arrows.
It's not enough to give employs the subproperty hasNationality-1, because you want to ensure that the player has a particular national status. This is where you need rolification. You want employs to have a subproperty chain of hasNationality-1 &bullet; p, where p is a special property that only relates players with national status to themselves. You can do that with rolification. Just declare a new object property RNationalPlayers and assert the axioms
hasNationalStatus value National_Player EquivalentTo R_NationalPlayer some Self
inverse(hasNationality) o R_NationalPlayer subPropertyOf employs
In the description logic syntax, these would be something like:
=hasNationalStatus.National_Player ≡ ∃RNationalPlayer.Self
hasNationality-1 &bullet; RNationalPlayer &sqsubseteq; employs
This will work in some reasoners, but unfortunately, this does bring us out of OWL 2 DL and into OWL full. This was discussed in some detail in the comments on this answer. As the error message in the updated question indicates, employs is now a non-simple property, and used in a place where only simple properties should be used. See 11.1 Property Hierarchy and Simple Object Property Expressions for more about what makes a property simple or not, and 11.2 The Restrictions on the Axiom Closure for more about properties can appear where.
However, it sounds like you're using a reasoner that supports SWRL rules, in which case you could simply add the rule:
hasNationality(?player,?country) &wedge; hasNationalStatus(?player,National_Player) &rightarrow; employs(?country,?player)

Assigning a value to a property based on a SWRL rule (Protege 4.3 with Pellet as reasoner)

My question is related to SWRL rules and actually was already asked by another user (see Ontology property definition in Protégé-OWL / SWRL). Still, after following the instructions on how to get it to work, I was not successful.
In my ontology I have to work with some complex temporal facts (related to time intervals etc.), therefore I import the Time Ontology. Before tackling the real problem, I'm consider a simple example, testing how to assign a value to a data property based on a SWRL rule. The simple example deals with a class Person. There also is a class BirthYear (subclass of the Instant class from the Time Ontology). The object property bornInYear, with domain Person and range BirthYear relates a Person with the year of his/her birth. I would like to calculate the age of the person in the current year, therefore I formulate this SWRL rule:
Person(?p) ∧ bornInYear(?p, ?birthYear) ∧ subtract(?age, 2014, ?birthYear)
&rightarrow; age(?p, ?age)
After creating an individual of class Person and asserting that his/her BirthYear has the value "1977", I would expect Pellet to calculate that this person's age is 37. This does not happen. Any idea why? Is the SWRL rule correct? (In order to know if the value 37 is asserted to the data property age, I look at the "Property assertions" view of the individual p. I also make sure, that in the reasoner preferences the check box 'Object Property Assertions" is checked.) My example ontology reads as follows:
Prefix(SWRLexample:=<http://www.semanticweb.org/ontologies/2014/1/SWRLexample#>)
Prefix(xsd:=<http://www.w3.org/2001/XMLSchema#>)
Prefix(swrlb:=<http://www.w3.org/2003/11/swrlb#>)
Prefix(owl:=<http://www.w3.org/2002/07/owl#>)
Prefix(:=<http://www.semanticweb.org/ontologies/2014/1/untitled-ontology-101#>)
Prefix(time:=<http://www.w3.org/2006/time#>)
Prefix(xml:=<http://www.w3.org/XML/1998/namespace>)
Prefix(rdf:=<http://www.w3.org/1999/02/22-rdf-syntax-ns#>)
Prefix(swrl:=<http://www.w3.org/2003/11/swrl#>)
Prefix(rdfs:=<http://www.w3.org/2000/01/rdf-schema#>)
Ontology(<http://www.semanticweb.org/ontologies/2014/1/SWRLexample>
Import(<http://www.w3.org/2006/time>)
Declaration(Class(SWRLexample:BirthYear))
SubClassOf(SWRLexample:BirthYear time:Instant)
Declaration(Class(SWRLexample:Person))
Declaration(ObjectProperty(SWRLexample:bornInYear))
ObjectPropertyDomain(SWRLexample:bornInYear SWRLexample:Person)
ObjectPropertyRange(SWRLexample:bornInYear SWRLexample:BirthYear)
Declaration(DataProperty(SWRLexample:age))
AnnotationAssertion(rdfs:comment SWRLexample:age "Age of a person in years")
DataPropertyDomain(SWRLexample:age SWRLexample:Person)
DataPropertyRange(SWRLexample:age xsd:int)
Declaration(NamedIndividual(SWRLexample:birthYear1))
ClassAssertion(SWRLexample:BirthYear SWRLexample:birthYear1)
DataPropertyAssertion(time:year SWRLexample:birthYear1 "1977"^^xsd:gYear)
Declaration(NamedIndividual(SWRLexample:p1))
ClassAssertion(SWRLexample:Person SWRLexample:p1)
ObjectPropertyAssertion(SWRLexample:bornInYear SWRLexample:p1 SWRLexample:birthYear1)
DLSafeRule(Body(ClassAtom(SWRLexample:Person Variable(<urn:swrl#p>)) ObjectPropertyAtom(SWRLexample:bornInYear Variable(<urn:swrl#p>) Variable(<urn:swrl#birthYear>)) BuiltInAtom(swrlb:subtract Variable(<urn:swrl#age>) "2014"^^xsd:integer Variable(<urn:swrl#birthYear>)))Head(DataPropertyAtom(SWRLexample:age Variable(<urn:swrl#p>) Variable(<urn:swrl#age>))))
)
There are a few problems (but I'm glad that that other answer was a useful starting point):
age is a data property, so you not only need to make sure that "the check box 'Object Property Assertions' is checked," but also 'Data Property Assertions', since it's a datatype assertion that you're looking for.
BornInYear is an object property, so ?birthYear in bornInYear(?p, ?birthYear) must be an individual. However, swrlb:subtract's arguments must be numeric literals. To use swrlb:subtract, you'll need to get the integer value of the year in the rule and perform the arithmetic on that. You should be able to do that without too much trouble, although I'm not sure if you'll still be able to use the value "1977"^^xsd:gYear. SWRL does define some functions working with dates and times, though (see 8.5. Built-Ins for Date, Time and Duration). Not all the reasoners support that, though (e.g., I don't think Pellet does). However, the value of the year property does need to be an xsd:gYear.
Here are the successive steps :
Go to metadata tab
Import temporal ontology, prefix it as temporal.
Go to SWRL tab
Write rule as follows :
Person(?x) ^ hasDOB(?x, ?dob) ^ temporal:duration(?age, "now", ?dob, temporal:Years) -> hasAge(?x, ?age)
where Person is a class
hasDOB,hasAge are object properties

Resources