How to represent conditional sentences in OWL ontology? - owl

For example,
If weather permits, I will go hiking.
Classes:
Weather
Hiking
Individual:
I
Properties:
permit
go

You could say that if there is a weather condition at time t which is sunny where you are, then there will be a hiking event at the same time involving you. A example of the kind of data you may have is:
ex:2017-02-23 a wc:WeatherCondition;
t:time "2017-02-23"^^xsd:date;
p:place ex:theAlps;
wc:cloudiness wc:sunny .
ex:i p:located [
a p:LocationAtTime;
p:location ex:theAlpes;
t:time "2017-02-23"^^xsd:date .
] .
ex:hiking2017-02-23 a ae:HikingEvent;
t:time "2017-02-23"^^xsd:date;
ae:participant ex:i .
You would like a rule like:
?wc a wc:WeatherCondition;
t:time ?t;
p:place ?p;
wc:cloudiness wc:sunny .
ex:i p:located [
a p:LocationAtTime;
p:location ?p;
t:time ?t .
] .
implies:
[] a ae:HikingEvent;
p:location ?p;
t:time ?t .
I don't think this is doable in OWL. However, you could use a rule engine for this. Nonetheless, I am not sure that this kind of use case where the data is highly contextual and dynamic is best covered by semantic web standards.

Related

Multiple paths and existential quantification in SHACL rules (should I use sh:oneOrMorePath perhaps?)

I would like to understand how to handle multiple paths and existential quantification in SHACL rules. Let me exemplify my problem with a sample ontology.
The ontology includes the classes "Approve", "Legal", "Result", "Man", and "Machine", all disjoint. It has two properties "has-theme" and "come-from" and the following individuals:
:a rdf:type :Approve ;
:has-theme :r1,:r2 .
:r1 rdf:type :Result ;
:come-from :m1 .
:r2 rdf:type :Result ;
:come-from :m2 .
:m1 rdf:type :Man .
:m2 rdf:type :Machine .
Therefore: the Approve action ":a" has two themes: ":r1" and ":r2". The former comes from the Man ":m1", the latter comes from the Machine ":m2".
I want to write a SHACL rule stating that "Every Approve action having among its themes at least a Result that comes from a Man is Legal".
I tried this, that do NOT classify ":a" as Legal (but it should):
:testRule rdf:type sh:NodeShape;
sh:rule [rdf:type sh:TripleRule;
sh:condition :conditionTest;
sh:subject sh:this;
sh:predicate rdf:type;
sh:object ontology:Legal
];
sh:targetClass ontology:Approve.
:conditionTest
rdf:type sh:NodeShape;
sh:property
[
#IF the theme of the Approve action is a Result come from a Man
sh:path (ontology:has-theme ontology:come-from);
sh:class ontology:Man
].
The problem is that ":a" has two themes, one coming from a Man and the other from a Machine.
Then I read on the Web about sh:oneOrMorePath and I tried the following variants within sh:property:
sh:oneOrMorePath (ontology:has-theme ontology:come-from);
sh:path ([sh:oneOrMorePath ontology:has-theme] ontology:come-from);
sh:path (ontology:has-theme [sh:oneOrMorePath ontology:come-from]);
Nothing to do, these variants don't work either.
On the other hand, if I remove the triple ":r2 :come-from :m2" or the triple ":a :has-theme :r2"
it works, as there is no more in the ontology a branch leading from ":a" to a non-Man.
Could any of you be so kind to help me?
Thank you!
Livio
Your requirements states "having among its themes at least a Result that comes from a Man" which sounds like an existential constraint to me. So you cannot really use sh:class here, but you may rather want to use a qualified value constraint.
I have not tried it, but something like this may work:
:conditionTest
rdf:type sh:NodeShape ;
sh:property [
sh:path (ontology:has-theme ontology:come-from) ;
sh:qualifiedMinCount 1 ;
sh:qualifiedValueShape [
sh:class ontology:Man ;
]
] .
This should mean that at least one of the values of the path has-theme/come-from must conform to the qualified value shape, which means that it must be an instance of Man.
See https://www.w3.org/TR/shacl/#QualifiedValueShapeConstraintComponent for the specification of QVCs in SHACL.
If you can use SHACL-SPARQL and import the dash namespace, you could also simply write dash:hasValueWithClass ontology:Man, see http://datashapes.org/constraints.html#HasValueWithClassConstraintComponent

Embedding a path in the parameter of sh:lessThan

Connected to this question (and its previous ones):
Using sh:maxExclusive to compare (the values of) two datatype properties
I created a small ontology with three classes: DataSubject, MemberState, and Minor. There are two datatype properties: has-age and has-minimalage. The former is from DataSubject(s) to integers, the latter is from MemberState(s) to integers. Then there is an object property has-member-state from DataSubject(s) to MemberState(s).
Now we have the following individuals:
ontology:John
rdf:type ontology:DataSubject ;
ontology:has-age "20"^^xsd:positiveInteger ;
ontology:has-member-state ontology:Spain ;
.
ontology:Spain
rdf:type ontology:MemberState ;
ontology:has-minimalage "16"^^xsd:positiveInteger ;
.
And I want to write a SHACL rule saying that each DataSubject whose age is less than the minimal age of his member state is also an individual of the class Minor.
In light of the replies I got to my other questions, I tried:
sh:rule [
rdf:type sh:TripleRule ;
sh:condition [
sh:property [
sh:path ontology:has-age ;
sh:lessThan (ontology:has-member-state ontology:has-minimalage)
] ;
] ;
sh:subject sh:this ;
sh:predicate rdf:type;
sh:object ontology:Minor ;
] ;
Which does not work: it classifies John as Minor, but 20 is not less than 16. Of course I tried many other variants, e.g., "sh:lessThan[sh:node[sh:path (ontology:has-member-state ontology:has-minimalage)];];", many of which do not probably make any sense, but none of them work.
Can someone suggest me how to embed a path in the parameter of sh:lessThan?
I am sorry if I start being annoying with all these questions :-( I am new to SHACL and SPARQL but I am really trying my best to learn them out of all what I can find on the Web.
Thanks
Livio
The official spec is (hopefully) pretty clear that the values must be IRIs, i.e. only direct properties are permitted. You can however try to revert the logic and use a path at the property shape. Otherwise, fall back to SPARQL.

Redundant axiom in Protege's Pizza ontology

Something just caught my eye in the Protege's
Pizza example ontology.
With regards to the owl:equivalentClass axiom of the class :VegetarianTopping
(amongst others.) It is defined like this (for the relevant bits):
:VegetarianTopping
rdf:type owl:Class ;
owl:equivalentClass [
owl:intersectionOf (
:PizzaTopping
[
rdf:type owl:Class ;
owl:unionOf (
:CheeseTopping
:FruitTopping
:HerbSpiceTopping
:NutTopping
:SauceTopping
:VegetableTopping
)
]
) ;
rdf:type owl:Class
] .
The rdf:comment for it is the following:
An example of a covering axiom. VegetarianTopping is equivalent to the union
of all toppings in the given axiom. VegetarianToppings can only be Cheese or
Vegetable or....etc.
All the :*Topping classes in the owl:unionOf above are defined as
sub-classes of :PizzaTopping, for instance:
:CheeseTopping
rdf:type owl:Class ;
rdfs:subClassOf :PizzaTopping .
It then looks to me that the part owl:intersectionOf ( :PizzaTopping ... ) is
redundant as all of the classes in the ... already meet that requirement. So
I would rather have given the following:
:VegetarianTopping
rdf:type owl:Class ;
owl:equivalentClass [
owl:unionOf (
:CheeseTopping
:FruitTopping
:HerbSpiceTopping
:NutTopping
:SauceTopping
:VegetableTopping
) ;
rdf:type owl:Class
] .
I guess I am missing something here? If not, is there any reason why
it has been defined like that?
The Protégé tutorial leads you step by step towards using the Protégé tool. It does not tell you how to build a practical application for your pizza business. Moreover, having redundent knowledge is not necessarily a bad thing. Avoiding redundency in knowledge representation may be difficult.
If you say "a vegetarian topping is a topping that consists of either cheese topping, fruit topping, herb spice topping, nut topping, sauce topping (sauces should be vegetarian of course), and vegetable topping", then you are redundent. You should say "a vegetarian topping is something that consits of either etc.". Saying that it is a topping, in addition to the other things, does not harm your knowledge, because it is true!
Adding true knowledge that is redundent may have cost in different ways (size of the ontology, efficiency, understandability, on so forth), but from a knowledge representation point of view, and for most reasoners, it is not a problem. Now, in the specific case of the Pizza ontology and this particular example, I don't know why they added the extra PizzaTopping class, but I suspect it is because of how the Protégé tutorial is designed, leading you gradually to more complicated concepts. There is nothing to worry about.

Json-ld not being converted to RDF as expected

I've converting some JSON-ld to RDF however it doesn't seem to produce RDF with the subject as I'd expect.
So, my JSON-ld looks like this:
{
"#context":{
"personid":"http://schema.org/id",
"hasUpdateType":"http://schema.org/updateType"
},
"#type":"http://schema.org/Person",
"personid":"123456",
"hasUpdateType":{
"#type":"updateType",
"updateType":"Full"
}
}
And the RDF that is produced is
_:b0 <http://schema.org/id> "123456" .
_:b0 <http://schema.org/updateType> _:b1 .
_:b0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> .
However I was expecting something like (syntax not correct, just trying to show roughly):
person hasUpdatetype Full
Is my json-ld wrong?
To make the conversion from json-ld to rdf, I'm using the toRDF() from this library https://github.com/digitalbazaar/jsonld.js
Any help would be appreciated.
Thanks.
You need to use #id (or an alias) to define the subject of the node object. You could potentially defined "persondid" as #id in the context.
You defined "hasUpdateTime" to expand to "schema:updateTime", so the expanded RDF should use "http://schema.org/updateType" as the predicate. If you want the value to be a single URI associated with "Full", use type coercion on "hasUpdateType". Something like the following may be closer to what you want.
{
"#context":{
"#base": "http://example.com/",
"personid":"#id",
"hasUpdateType": {"#id": "http://schema.org/updateType", "#type": "#id"}
},
"#type":"http://schema.org/Person",
"personid":"123456",
"hasUpdateType":"Full"
}
This would give you the following triples:
<http://example.com/123456> <http://schema.org/updateType> <http://example.com/Full> .
<http://example.com/123456> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> .

SQL Like in OWL API for data properties

In OWL API, classes may have data properties. For e.g. a class may have a date property hasCommonName "Something". In OWL API, is there any facility like the SQL like which allows querying for classes that hasCommonName containing the word "Some", just like SQL like behave
You can use regular expressions to identify the things you need. Consider the following knowledge base:
DataProperty: hasCommonName
Individual: foo
Facts:
hasCommonName "Something"
You can retrieve the individual foo by using the following class expression: hasCommonName some string[pattern "Some.*"]. The string[pattern "Some.*"] specifies the pattern to be matched. Warning, currently not supported by all reasoners (works for Hermit 1.3.7)
You need to look at some SPARQL tutorials. You can write something like this:
SELECT * WHERE
{
?pizza rdfs:subClassof [
owl:onProperty :hasTopping;
owl:someValuesFrom :TomatoTopping ] .
}
Basically, you need to define the correct predicate based on your restriction.

Resources