SQL Like in OWL API for data properties - owl

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.

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.

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> .

Reflexive property in protege

This is my ontology created with protege 5 .
If i make cl1 and cl2 disjoint, then the ontology is being inconsistent , but if i uncheck is_friend_of reflexive , the ontology is not inconsistent any more . whats wrong with my ontology ?
I want only cl1 class individuals have is_friend_of property.
Reflexivity of :is_friend_of is essential for inconsistency.
Take a look at Reasoner > Inconsistent ontology explanation :
I'll try to translate this explanation into (poor) English:
Since :is_friend_of is reflexive, then :c2_inst :is_friend_of :c2_inst.
Since the domain of :is_friend_of is :cl1, then c2_inst rdf:type :cl1.
Also, c2_inst rdf:type :cl2.
But :cl1 and :cl2 are disjoint — contradiction.
In fact, the domain of every reflexive property is owl:Thing.
As a workaround, you could uncheck reflexivity of is_friend_of and define :cl1 in this way:
Class: cl1
EquivalentTo:
is_friend_of some owl:Thing,
is_friend_of some Self

How to represent conditional sentences in OWL ontology?

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.

Resources