In a next step we want to characterize toys with attribute-value pairs, e.g. say that the fire engine is red. In this case we define property types (OntoStudio: "attributes") which may have strings as values. (In the next section we defined property types which have self defiend classes as range.)

Defining some more instances of toys:

ex#rubberDuckie : ex#Toy .

turtle: ex#rubberDuckie rdf:type ex#Toy .

ex#rubberDuckie [ ex#hasColor -> "yellow" ] .

ex#stuffedAnimal : ex#Toy .

turtle: ex#stuffedAnimal rdf:type ex#Toy .

ex#stuffedAnimal [ ex#hasColor -> "pinkish" ] .

Defining some subclasses of the class toy:

ex#Pet :: ex#Toy .

turtle: ex#Pet rdfs:subClassOf ex#Toy .

ex#Instrument :: ex#Toy .

turtle: ex#Instrument rdfs:subClassOf ex#Toy .

ex#FireEngine :: ex#Toy .

turtle: ex#FireEngine rdfs:subClassOf ex#Toy .

We probably also want to define on the schema level that toys may be desribed by color and size:

Defining some instances of specific toys like pets, instruments etc.:

This schema definition is passed down to all subclasses of the class toy, i.e. to pets, FireEngines etc. (In OntoStudio such inherited property definitions are displayed greyed; they can be used but not changed by a sublass.)

Query for big toys:

@{ bigToysQuery } ?-
?X : ex#Toy and ?X [ ex#hasSize -> "big" ] .

Note that this query yields results which are already given in the fact base. Beside exploiting the subclass hierarchy (which is realized by simple built in rules) no handy crafted rules are required.

Now we can easily define the class BigToys via a classification rule:
bigToyClassificationQuery

@{ bigToyClassificationQuery } ?-
?X : ex#BigToy .

@{ bigToyClassificationRule }
?X : ex#BigToy :-
?X : ex#Toy and ?X [ ex#hasSize -> "big" ] .