Set domains and ranges
Domains can be set in two ways:
-
When editing a class in the Resource Editor you can define a
domain the class belongs to using: Drag and drop a property from the
Properties View into the Domain View.
-
When editing a property, pick a class from the Classes View and drag it onto the rdfs:domain label
on the form. Alternatively, add an empty row and type the name of the class (with auto-completion
for your convenience).
To set a range:
- Select a property so that is appears in the Resource Editor
- Pick a class from the Classes View; Drag and drop
it over the rdfs:range widget or
- Click on a down facing triangle next to the
rdfs:range widget; Select Add
empty row menu option; Type the
name of the class
Using Domains and Ranges versus Local Restrictions
Keep in mind that domains and ranges 'belong' to a property rather than a class.
And they are global. In other words, any time a property is used in a statement, the following will happen:
- the subject of the statement will be inferred to be an instance of the class in the domain of the property
- the object of the statement will be inferred to be an instance of the class in the range of the property
- if a property has more than one domain or range, the resource will be inferred to be an instance of both
It is important that properties are reused with care, especially in situations when multiple ontologies
may be merged:
- Imagine setting a domain of the name property to be the Person class
- Then having someone to reuse this property in their own context and declare that domain of the name
property is Company class
- Bringing these two ontologies together will now result in the inference that any resource with a name is
both, a Person and a Company!
If your target deployment environment will have an OWL inferencer, consider not setting any domains
and ranges and using local restrictions instead.
Likewise, if you are using SHACL then the use of domains and ranges should be limited to its
official RDFS interpretation, i.e. for the purpose of inferencing and not constraint checking.
If a class is in a domain of a property, it does not mean that its subclass is in
the domain of the property. RDFS inheritance does not work as object oriented inheritance.
If you want to ensure that subclasses are in the domain of the property, use local restrictions.
Using Domains and Ranges with Subproperties
Domain and range of a parent property should be a parent class of the domains and ranges of the child property.
Even if they are not, as soon as instance data that uses the property is added the ontology, these
inferences will be made. Consider the following example:
- Property hasFather with domain Person and range Man
- Property hasParent, hasFather is a subProperty of hasParent
- Class Person has a subClass Man
- Making a statement that Mary hasFather John will then result in the following inferences:
- Mary is a Person
- John is a Man
- Mary has parent John
- John is a Person
In this example declaring that hasParent has Person
in the domain and range, would be redundant. No new conclusions (inferences) would result from it.
It is therefore often advisable to leave domains and ranges of a parent property empty.
This is a good practice that will ensure that your ontology is consistent and easy to maintain.