Home » Posts tagged 'linked data'
Tag Archives: linked data
The difference between Schema.org and OWL
In this blog post I describe some of the main differences between Schema.org vocabularies and OWL ontologies, the implications of these differences and the kind of steps you will need to take to translate Schema.org vocabularies to OWL ontologies.
Overall I keep this discussion at a high-level. For in-depth reviews of the differences between Schema.org and OWL I provide relevant links at the end of this post.
Key differences
There are 2 main differences between OWL and Schema.org.
- Intended purpose: The primary purpose of Schema.org is to enable sharing of structured data on the internet. The primary purpose of OWL is to enable sophisticated reasoning across the structure of your data.
- Difference in language: Due to the difference in purpose, there are substantial differences in language. The main reason being that the language for OWL can be translated into precise mathematical logic axioms, which allows for much richer inferences to be drawn. This is the reason for OWL preferring
rdfs:domain/rdfs:range
toschema:domainIncludes/schema:rangeIncludes
. The benefit of usingrdfs:domain/rdfs:range
is that they have precise defined mathematical logic meaning, whereasschema:domainIncludes/schema:rangeIncludes
do not have mathematical meaning.
What does this mean?
Using Schema.org you could draw some limited inferences. For example a reasoner can determine that the SNOMED concept http://purl.bioontology.org/ontology/SNOMEDCT/116154003
is a schema:Patient
which is a schema:Person
. But the language used in Schema.org by itself is not rich enough to detect inconsistencies. I.e., there is no way to say that schema:Person
is disjoint from schema:Product
. This allows for stating myexample:john a schema:Person
and myexample:john a schema:Product
without a reasoner being able to detect the inconsistency. Using OWL it is possible to state that schema:Person
and schema:Product
are disjoint.
Does this mean you should prefer OWL to Schema.org? No, not if your intended purpose of your ontology is to share data. Then it is best to use concepts from Schema.org and add the axioms that will provide the inferences you need. If reasoning is not your reason for wanting to use Schema.org/OWL, then just use Schema.org.
Can you translate Schema.org to OWL?
Strictly speaking, since RDF & RDFS is a subset of OWL, Schema.org is an OWL definition already, albeit one with limited reasoning capability. Any “translation” to OWL will mean adding axioms to Schema.org to increase the inferences that can be drawn from Schema.org documents. It is a pity that Schema.org does not (the current link to the OWL file is dead) provide an OWL file with the additional axioms that will enable richer reasoning.
- Add
rdfs:domain
andrdfs:range
restrictions rather than replacingschema:domainIncludes
andschema:rangeIncludes
. Replacingschema:domainIncludes
andschema:rangeIncludes
could result in search engines not finding information. - Add
owl:disjointWith
andowl:disjointObjectProperties
respectively for all classes and properties that do not share individuals. - By looking at the documentation of Schema.org it gives the impression that classes have attributes. I.e.,
schema:Person
has an attributeschema:givenName
. However, there is nothing in the definition ofschema:Person
that enforces that theschema:Person
class must have aschema:givenName
attribute. I describe here, here and here how to define “attributes” for classes in a way that can be used by OWL reasoners.
Conclusion
Schema.org is mainly for sharing structured data on the Internet. OWL is used mainly to reason over structured data to determine inconsistencies in the schema.
For in-depth discussions on the differences between Schema.org and OWL I highly recommend reading the papers by Patel-Schneider and Hernich et al.
Classification with SHACL Rules
In my previous post, Rule Execution with SHACL, we have looked at how SHACL rules can be utilized to make inferences. In this post we consider a more complex situation where SHACL rules are used to classify baked goods as vegan friendly or gluten free based on their ingredients.
Why use SHACL and not RDF/RDFS/OWL?
In my discussion I will only concentrate on the definition of vegan friendly baked goods since the translation to gluten free baked goods is similar. Gluten free baked goods are included to give a more representative example.
Essentially what we need to do is look at a baked good and determine whether it includes non-vegan friendly ingredients. If it includes no non-vegan friendly ingredients, we want to assume that it is a vegan friendly baked good. This kind of reasoning uses what is called closed world reasoning, i.e. when a fact does not follow from the data, it is assumed to be false. SHACL uses closed world reasoning and hence the reason for why it is a good fit for this problem.
RDF/RDFS/OWL uses open world reasoning, which means when a fact does not follow from data or schema, it cannot derive that the fact is necessarily false. Rather, it is both possible (1) that the fact holds but it is not captured in data (or schema), or (2) the fact does not hold. For this reason RDF/RDFS/OWL will only infer that a fact holds (or does not hold) if it explicitly stated in the data or can be derived from a combination of data and schema information. Hence, for this reason RDF/RDFS/OWL are not a good fit for this problem.
Baked Goods Data
Below are example baked goods RDF data:

Bakery RDF data
A couple of points are important w.r.t. the RDF data:
- Note that we define both
VeganFriendly
andNonVeganFriendly
ingredients to be able to identify ingredients completely. Importantly we state thatVeganFriendly
andNonVeganFriendly
are disjoint so that we cannot inadvertently state that an ingredient is bothVeganFriendly
andNonVeganFriendly
. - We state that
AppleTartA
–AppleTartD
are of typeBakedGood
so that when we specify our rules, we can state that the rules are applicable only to instances of typeBakedGood
. - We enforce the domain and range for
bakery:hasIngredient
which results in whenever we saybakery:a bakery:hasIngredient bakery:b
, the reasoner can infer thatbakery:a
is of typebakery:BakedGood
andbakery:b
is of typebakery:Ingredient
.
Baked Good Rules
Now we define the shape of a baked good:

BakedGood shape
We state that bakery:BakedGood a rdfs:Class
which is important to be able to apply rules to instances of bakery:BakedGood
. We also state that bakery:BakedGood a sh:NodeShape
which allows us to add shape and rule information to bakery:BakedGood
. Note that our bakery:BakedGood
shape state that a baked good has at least one property called bakery:hasIngredient
with range bakery:Ingredient
.
We now add a bakery:NonVeganFriendly
shape

NonVeganFriendly shape
which we will use in the rule definition of bakery:BakedGood
:

VeganBakedGood and NonVeganBakedGood rules
We add two rules, one for identifying a bakery:VeganBakedGood
and one for a bakery:NonVeganBakedGood
. Note that these rules are of type sh:TripleRule
, which will infer the existence of a new triple if the rule is triggered. The first rule states that the subject of this triple is sh:this, which refers to instances of our bakery:BakedGood
class. The predicate is rdf:type
and the object is bakery:VeganBakedGood
. So if this rule is triggered it will infer that an instance of bakery:BakedGood
is also an instance of type bakery:VeganBakedGood
.
Both rules have two conditions which instances must adhere to before these rules will trigger. These rules will only apply to instances of bakery:BakedGood
according to the first condition. The second condition of the rule for bakery:VeganBakedGood
checks for bakery:hasIngredient
properties of the shape bakery:NonVeganFriendly
. This ensures that the range of bakery:hasIngredient
is of type bakery:NonVeganFriendly
. If bakery:hasIngredient
has a maximum count of 0, it will infer that this instance of bakery:BakedGood
is of type bakery:VeganBakedGood
. The rule for bakery:NonVeganBakedGood
will also check for bakery:hasIngredient
properties of the shape bakery:NonVeganFriendly
, but with minimum count of 1 for which it will then infer that this instance is of type bakery:NonVeganBakedGood
.
Jena SHACL Rule Execution Code
The Jena SHACL implementation provides command line scripts (/bin/shaclinfer.sh
or /bin/shaclinfer.bat
) which takes as arguments a data file and a shape file which can be used to do rule execution. However, for this specific example you have to write your own Java code. The reason being that the scripts creates a default model that has no reasoning support. In this section I provide the SHACL Jena code needed to do the classification of baked goods.

Shacl rule execution
Running the Code
Running the code will cause an inferences.ttl
file to be written out to
$Project/src/main/resources/
. It contains the following output:

Classification of baked goods
Conclusion
In this post I gave a brief overview of how SHACL can be used to do classification based on some property. This code example is available at shacl tutorial. This post was inspired by a question on Stack Overflow.
If you have any questions regarding SHACL or the semantic web, please leave a comment and I will try to help where I can.
Rule Execution with SHACL
In my previous post, Using Jena and SHACL to validate RDF Data, I have looked at how RDF data can be validated using SHACL. A closely related concern to that of constraints checking, is rule execution, for which SHACL can also be used.
A SHACL Rule Example
We will again use an example from the SHACL specification. Assume we have the a file rectangles.ttl
that contains the following data:

rectangles.ttl
Assuming we want to infer that when the height and width of a rectangle are equal, the rectangle represents a square, the following SHACL rule specification can be used (which we will store in rectangleRules.ttl
):

rectangleRules.ttl
A Code Example using Jena
Naturally you will need to add SHACL to your Maven pom dependencies. Then the following code will execute your SHACL rules:

SHACL rule execution using Jena
Running the Code
Running the code will cause an inferences.ttl
file to be written out to $Project/src/main/resources/
. It contains the following output:

inference.ttl
Note that ex:InvalidRectangle
has been ignored because it does not adhere to sh:condition ex:Rectangle
, since it does not have ex:height
and ex:width
properties. Also, ex:NonSquareRectangle
is a rectangle, not a square.
Conclusion
In this post I gave a brief overview of how SHACL can be used to implement rules on RDF data. This code example is available at shacl tutorial.