|What Are Classes And Individuals?|
Next: What Are Properties?
Classes and Individuals are an important concept in RDF and ontologies. What are they, how are they used, and how are they defined? Our tutorial explains the concepts by building up a simple example.
After this tutorial, you should be able to:
Estimated time: 10 minutes
You should have already understood the following tutorial (and pre-requisites) before you begin:
In RDF, anything with a subject URI is called a resource. For example, in the following set of six simple triples (which we define in Turtle):
There are three resources with (subject) URIs:
Take a moment to see that you understand this clearly before continuing.
If you are unclear what triples in RDF are, we suggest you start with our acclaimed semantic web primer tutorial.
Classes then are simply a way of defining meaningful groups into which these resources can be placed - they are classifications.
2. Classes And Individuals
As we've said, a class is simply a way of defining groups into which resources can be meaningfully placed.
For example, we may want to define three meaningful classes into which we could place our three resources above:
In semantic web terms, any resource that we've placed into a class is called an individual of that class.
Remember the difference between a class and an individual. An individual is a resource that has been placed into the class (or, the classifying group). Individuals are not classes themselves.
We hope now you see that these are normal, everyday concepts and nothing particularly special or unique to the semantic web.
Before continuing, make sure you now understand the following three important terms:
To go further, let's see exactly how we define classes and individuals in RDF.
3. Defining Classes & Individuals In RDF
To define classes and individuals in RDF you need to use something called RDFS - or RDF Schema. There is nothing special or mysterious about RDFS - it simply gives you a standard vocabulary to tell a machine reader what your classes and individuals are in a standard way using RDF (probably why it is called RDF schema).
Because it's a W3C semantic web standard, we need to use it to define our classes and individuals.
Let's demonstrate how to define classes using RDFS, by defining the three classes we outlined above - for canines, felines and murinae (mice):
Before digging deeper, let's give our classes some helpful human friendly descriptions too:
First off, you can see on the first two lines the standard RDF and RDFS namespaces, with which you should be familiar if you have seen RDF documents before.
There is a very common - and very important - predicate stated here: rdf:type (or, if you want to expand it in full http://www.w3.org/1999/02/22-rdf-syntax-ns#type).
When used as a predicate in an RDF triple (i.e. the subject->predicate->object relationship), this formally states that the resource (with its unique subject URI) is an individual (or, member) of the class with identifier given by the object URI.
To help understand this, see if you can see for yourself the following in the RDF above:
And that's how we define our classifications using the RDFS vocabulary - by stating that our resources tutorial:canine, tutorial:feline and tutorial:murinae are individuals of the RDFS class rdfs:Class.
Note we defined a class in RDFS by defining an individual - of the RDFS class rdfs:Class. All classes in RDFS are defined by stating the resources are individuals of rdfs:Class.
Now that we've defined our three classes in RDFS, let's place the three resources we defined at the beginning of this tutorial - our dog Bengie, our cat Bonnie and mouse Benjamin - into these classes appropriately. To do this, we use the same predicate again, rdf:type, to state that they are individuals of the classes we have just defined:
As an exercise, see now if you can see how we have placed Bengie, Bonnie and Benjamin into membership of their respective appropriate classes.
Lastly, let's deal with the powerful concept of classes and subclasses in semantic web models.
Often, it is useful to define a hierarchy of classifications, from the most general classifications at the top of the hierarchy to the most specialised classifications at the bottom.
For example, whilst we have separate classes for canines, felines and murinae above, we may wish to define an over-arching general animal class - that includes canine, feline and murinae as subclasses of this (general) animal class.
How do we now define the general animal class and indicate that canine, feline and murinae are subclasses of this class? First, let's define our new general animal class, in a similar way to how we defined our canine, feline and murinae classes:
Before continuing, just double check once more than you understand how we have defined the animal class.
Now, to indicate that canine, feline and murinae are subclassifications of the our general animal class, we use the rdfs:subClassOf predicate:
And that's it - we've defined a small classification hierarchy, with the animal class at the top level, using the RDF Schema vocabulary.
If we now add all of what we've built up over the tutorial into a final document (including our individuals Bengie, Bonnie and Benjamin) we get:
Congratulations, if you have understood all that we have built up here, you have understood how to create your first ontology, using RDF Schema.
As an exercise, have a second look over the document above and see if you can identify each of its component parts (the resources, classes, individuals and subclass statements).
As an optional further exercise, just to make sure you have understood all the concepts we have discussed, see if you can identify how many resources are included in the above document and their subject URIs (the answer is 7).
4.1 A Quick Note On Reasoning And Inference
You may have heard of reasoning and inference in semantic web models. Although usually something associated with richer ontologies written in OWL, there are some simple ways in which a reasoner can infer characteristics from an RDFS ontology too (a reasoner is a semantic web reader program that understands RDFS and OWL vocabularies and how to infer information from ontologies written in these vocabularies).
There are several minor ways in which most semantic web readers can infer certain things from the RDF we have written so far in this tutorial (these are just but a few examples - they are not exhaustive).
These are simple examples of reasoning in semantic web models - something we will see a little more of in our next tutorial, on properties.
5. Enriching Your Semantics With OWL
So far, we have introduced how to define semantic classes, subclasses and individuals using RDFS. These are powerful concepts in themselves and useful for modelling the information we have for others to understand.
However, we could go further than simple classifications and subclassifications and start to describe richer properties of the classes we have defined using OWL (Web Ontology Language).
For example, in OWL we could state that some of the classes we have defined were semantically equivalent to other classes even though they had different class (subject) URIs. Or, if we know that a class we have defined is always the opposite in meaning to another class, we could state this too.
We will not explore the full richness of OWL for the purposes of this tutorial because we need to introduce the concept of properties first, but keep in mind how OWL is in a sense a more sophisticated extension of RDFS.
You have completed this lesson. You should now understand the following:
You should now be able to start the following tutorial: