SWRL: Variables to represent classes (rule to get instance of parent class or subclass) - owl

I have the following setting:
an owl-ontology (accessed via owlready with this class hierarchy:
owl:Thing
├── ClassA1
└── ClassB1
└── ClassB2
└── ClassB3
└── ClassB4
one instance of each class, say A1, B1 , etc.
a property prop1 which relates A1 to B4: prop1(A1, B4)
I want a SWRL-rule which, given prop1(A1, B4), relates A1 to B3 and B2 via prop1.
I imagine there must be something like this (partially invented syntax):
ClassA(?a), prop1(?a, ?i1), rdfs:type(?i1, ?c),
direct_subclass(?c ,?d), rdfs:type(?i2, ?d), not rdfs:type(?i2, ClassB1) -> prop(?a, ?i2)
However, I did not find anything about "variables representing classes" in SWRL (cf direct_subclass(?c, ?d) or rdfs:type(?i2, ?d)).
How can I formulate my rule?

Related

How to infer an object property based on data properties?

I'm a protégé newbie and did the pizza tutorial and read the 101 documentation. I'm trying to model a ontology like the following picture:
I have a person who has a style. The style can be a style_active or style_passive.
This style is determined by a index of two data properties:
ind_passive and ind_active, the bigger value should infer the style.
I had to create two individuals: style_active and style_passive, because they must be individuals to be assigned to the object property has_style.
How to infer the value of has_style object property based on ind_passive and ind_active data properties? Using a reasoner?
Is something wrong with this model?
I suceed in calculate the value of style object property based on two swrl rules. It does not work with a reasoner like HermiT (default in Protégé 5.5), but works in SWRLTab, that uses Drools.
The rules I used:
Name: Passive
Rule: Person(?p) ^ ind_passive(?p, ?ip) ^ ind_active(?p, ?ia) ^ swrlb:greaterThan(?ip, ?ia) -> has_style(?p, style_passive)
Name: Active
Rule: Person(?p) ^ ind_passive(?p, ?ip) ^ ind_active(?p, ?ia) ^ swrlb:greaterThan(?ia, ?ip) -> has_style(?p, style_active)
The reasoner Hermit could not be enabled after using this rules, because it does not supports "built-in atoms", like swrlb:greaterThan.

Inconsistent classification of individuals in Protege 4.3

I have been studying Protege and I have a question. I added an individual with name aaa in ontology "people.owl" which I downloaded from the internet.
I set type assertion as:
sheep and hasCC value 200,
where hasCC is data property.
Then, in class animal I created two classes: hhh and lll.
I set hhh as equivalent and there wrote:
animal and (hasCC some decimal[>= 150])
For lll I set:
animal and (hasCC some decimal[< 250])
When I run HermiT reasoner I see that the individual aaa is classified in both lll and hhh classes.
But when I set lll and hhh classes to be disjoint and run the reasoner the classes are not classified in the class "Nothing" as, for example, the class "mad_cow". I get a message:
"Your ontology is inconsistent which means that the OWL reasoner will no longer be able to provide any useful information about the ontology." After clicking the button "Explain" I get:
Could you say, why lll and hhh classes cannot be classified as Nothing?
What should I correct to let lll and hhh classes to be classified as Nothing?
Thank you!
"Your ontology is inconsistent which means that the OWL reasoner will no longer be able to provide any useful information about the ontology."
Isn't this saying it all already? You complain that the reasoner is not doing something but the reasoner explicitly tells you that it is not able to provide any useful information! Make your ontology consistent, then you can expect something from the reasoner.
In any case, you cannot expect a class that contains an instance (here the classes hhh and lll both must contain instance aaa) to be equivalent to Nothing. Nothing precisely means "the class that does not have any instance".

Plantuml class diagram with multiple children: Any way to bifurcate the arrow?

My attempt:
Animal <|-- Cat
Animal <|-- Dog
Result:
┌────────┐
│ Animal │
└────────┘
Δ Δ
│ │
┌──┴──┐┌──┴──┐
│ Cat ││ Dog │
└─────┘└─────┘
That is not how a class diagram is supposed to look like.
This is:
┌────────┐
│ Animal │
└────────┘
Δ
┌──┴───┐
┌──┴──┐┌──┴──┐
│ Cat ││ Dog │
└─────┘└─────┘
As suggested, I asked if this is possible on the PlantUML forum.
You can do something like this:
#startuml
class Animal
together {
class Dog
class Cat
}
Animal <|-- Cat
Dog -- (Animal, Cat)
#enduml
There's skinparam groupInheritance 2 which will serve your purpose, although it doesn't work with skinparam linetype ortho as one might expect. Alas, GraphViz is the rendering engine, so that has limitations.
#startuml
skinparam style strictuml
hide empty members
skinparam groupInheritance 2
class Animal
class Cat extends Animal
class Dog extends Animal
#enduml
An interesting thing to do in plantUML but "this is not how class diagram is supposed to look like" is not correct (to my knowledge, at least).
The notation is clear for inheritance/generalization but whether you join the lines before the arrow or have separate lines with separate arrows is a matter of visual preference/making it easier to understand:
Try to sketch the image on top of that wiki you linked with distinct arrow from each child to it's parent, it will be much more messy
Scroll down a bit on wiki to https://en.wikipedia.org/wiki/Class_diagram#Generalization/Inheritance

Reclassifying instances asserted using SWRLJessTab Protege

I am using Protege 3.4 and I built my ontology and extended it with SWRL rules using SWRL and sqwrl built ins . The rules classifies instances of a class of the ontology ; the RHS is class assertion of an instance .It works successfully but when I change the values of the causes in the LHS no reclassification is done the instance is asserted to the same class
Why does this happen ? How to reclassify instances ?
ex:
SWRL rules:
1. Message(?m) hasInterest(?m,?i) hasCategory(?m,?c) sqwrl:makeset(?s1,?i) sqwrl:makeset(?s2,?c) sqwrl:intersection(?s3,?s1,?s2) sqwrl:size(?n,?s3) swrlb:greaterThan(?n,0) -> Ham(?m)
Message(?m) hasInterest(?m,?i) hasCategory(?m,?c) sqwrl:makeset(?s1,?i) sqwrl:makeset(?s2,?c) sqwrl:difference(?s3,?s1,?s2) sqwrl:size(?n,?s3) swrlb:greaterThan(?n,0) -> Spam(?m)
So once the message instance is classified as ham for example , whenever I change the values of i or c it will always be ham .

swrlx:makeOWLThing is creating only one individual

Using Protege and SWRL tab, I have the ontology mentioned hereinafter. It is composed of the Class Test and the class Shadow, where Test has three individuals t1, t2, t3. I was trying to define an SWRL rule that creates an individual of Shadow class for each existing individual of Test, the rule is
Test(?x) ^ swrlx:makeOWLThing(?new, ?x) -> Shadow(?new)
QUESTIONS:
Only one individual of Shadow, named fred is created, instead of three (corresponding to t1, t2, t3).
How to control the naming of the resulting individual which is always named fred?
Prefix(:=<http://www.semanticweb.org/hilal/ontologies/2016/5/untitled- ontology-58#>)
Prefix(owl:=<http://www.w3.org/2002/07/owl#>)
Prefix(rdf:=<http://www.w3.org/1999/02/22-rdf-syntax-ns#>)
Prefix(xml:=<http://www.w3.org/XML/1998/namespace>)
Prefix(xsd:=<http://www.w3.org/2001/XMLSchema#>)
Prefix(rdfs:=<http://www.w3.org/2000/01/rdf-schema#>)
Ontology(<http://www.semanticweb.org/hilal/ontologies/2016/5/untitled- ontology-58>
Declaration(Class(:Shadow))
Declaration(Class(:Test))
Declaration(NamedIndividual(:t1))
Declaration(NamedIndividual(:t2))
Declaration(NamedIndividual(:t3))
Declaration(AnnotationProperty(<http://swrl.stanford.edu/ontologies/3.3/swrla.owl#isRuleEnabled>))
############################
# Named Individuals
############################
# Individual: :t1 (:t1)
ClassAssertion(:Test :t1)
# Individual: :t2 (:t2)
ClassAssertion(:Test :t2)
# Individual: :t3 (:t3)
ClassAssertion(:Test :t3)
DLSafeRule(Annotation(<http://swrl.stanford.edu/ontologies/3.3/swrla.owl#isRuleEnabled> "true"^^xsd:boolean) Annotation(rdfs:comment ""^^xsd:string) Annotation(rdfs:label "S1"^^xsd:string) Body(BuiltInAtom(<http://swrl.stanford.edu/ontologies/built-ins/3.3/swrlx.owl#makeOWLThing> Variable(<new>) Variable(<x>)) ClassAtom(:Test Variable(<x>)))Head(ClassAtom(:Shadow Variable(<new>))))
)
SWRL rules cannot create new individuals, as far as I understand the DL Safe conditions.
In the comments, you linked to an article describing the semantics of that extension:
One of the the first built-ins I implemented provided the ability to create new individuals in a controlled manner. There is a detailed explanation in [2], but basically a built-in called swrlx:makeOWLThing creates a new individual and binds it to its first unbound argument; a new individual is created for each unique pattern of the remaining arguments.
Now, let's take a look at your rule as written in the question:
Test(?x) ^ swrlx:makeOWLThing(?new, ?x) -> Shadow(?new)
If the atoms are processed from left to right, then ?x should be bound when makeOWLThing is encountered, but ?new isn't. That means that you should get a new individuals bound to the variable ?new, and for each value of ?x you should get a different value of ?new. That's what it sounds like you want. However, in the code you posted, I see this:
DLSafeRule(
Annotation(<http://swrl.stanford.edu/ontologies/3.3/swrla.owl#isRuleEnabled> "true"^^xsd:boolean)
Annotation(rdfs:comment ""^^xsd:string)
Annotation(rdfs:label "S1"^^xsd:string)
Body(
BuiltInAtom(<http://swrl.stanford.edu/ontologies/built-ins/3.3/swrlx.owl#makeOWLThing>
Variable(<new>)
Variable(<x>))
ClassAtom(:Test Variable(<x>)))
Head(
ClassAtom(:Shadow Variable(<new>))))
)
I'm not certain, but if that's processed from left to right as well, the makeOWLThing(?new,?x) appears first, in which case ?x would be unbound when the new individual is created, so you'd only get one new individual.

Resources