could you please explain me the difference between rdfs:domain and rdfs:range with an example? and when should i use domain and when range? i have read h w3c rdf primer but i did not understand the difference
3 Answers
From a simplistic point of view, the domain and range properties are there to give you insight into the way that the property links a subject to an object.
In the case of the domain property, when you link a subject to an object using a property with this associated attribute, then the subject qualifies as a type of thing specified in the domain. For example, we look at a vocabulary and we see that the domain of our property is a Project. So, simply put, as long as the subject being described using the “name” attribute is a type of project (or could be a type of project), then you should have no problem going ahead using that term to describe that thing, because most other people will interpret that if something is described using this term, then it is a project. You'll find it is not only humans but also machines (or reasoners in this case) that make the same inferences.
The range works exactly like the domain, but with this one, it applies to the object of the statement and not the subject. A word of caution; you might at times come across instances where the domain or range applies to more than one thing. In this case, it means that the subject or object (domain or range) is all of the types specified (the intersection not the union).
Short answer : A property may have many values for rdfs:domain but only one value for rdfs:range
These properties apply to properties and must be valued by classes. They are used to restrict the set of resources that may have a given property (the property's domain) and the set of valid values for a property (its range). A property may have as many values for rdfs:domain as needed, but no more than one value for rdfs:range
source : https://perso.liris.cnrs.fr/pierre-antoine.champin/2001/rdf-tutorial/node15.html
Each property in RDF may have its own attributes about the domain and the range. The domain value restricts the class of subject in triple of the extension of the property and the range value restricts the range of the property value.
source : http://www-kasm.nii.ac.jp/~koide/SWCLOS2/Manual/08DomainRange.htm
I find it easier starting with an example: let's say that we have a property happened_at
with DOMAIN and RANGE defined as follow:
DOMAIN | property | RANGE |
---|---|---|
Event Olympic Games |
happened_at |
Place Location |
Any resource that has given property happened_at is an instance of Event or Olympic Games |
The values of a property are instances of one or more classes (for example Place ) |
|
Olympic Games Beijing 2022 | Beijing | |
Class | Property | Class |
So for instance in an ontology defined in this way when I found the property happened_at
from its range I know that its value could be only Place
or Location
and from its domain, I know that the resource that has this property will be an instance of Event
or Olympic Games
.
In RDF the property P will have range and domain class C formalized as follow:
P rdfs:range C
P rdfs:domain C
You can read the full definition in the W3C recommendation here.