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:

  • Understand what a resource is in semantic web terms.
  • Understand that a class is a way of meaningfully grouping these resources.
  • Distinguish between a class and an individual of a class.
  • Understand what a subclass of a class is.
  • How to define all of these in RDF using the RDF Schema (RDFS) vocabulary.

Estimated time: 10 minutes

You should have already understood the following tutorial (and pre-requisites) before you begin:

RDF classes and individuals concept

1. Resources

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):

@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
@prefix thing: <http://www.linkeddatatools.com/thing#>
@prefix dcterms: <http://purl.org/dc/terms/>

thing:bengie rdfs:label "Our dog, called Bengie".
thing:bengie dcterms:description "A friendly member of the canine species".

thing:bonnie rdfs:label "Our cat, called Bonnie".
thing:bonnie dcterms:description "A friendly member of the feline species".

thing:benjamin rdfs:label "Our mouse, called Benjamin".
thing:benjamin dcterms:description "A friendly member of the murinae species".

There are three resources with (subject) URIs:

  • http://www.linkeddatatools.com/thing#bengie describing our dog, called Bengie
  • http://www.linkeddatatools.com/thing#bonnie describing our cat, called Bonnie
  • http://www.linkeddatatools.com/thing#benjamin describing our mouse, called Benjamin

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:

  • A canine class, a class for all members of the canine species, into which we could place our dog Bengie.
  • A feline class, a class for all members of the feline species, into which we could place our cat Bonnie.
  • A murinae class, a class for all members of the murinae species (the formal biological classification for mice), into which we could place our mouse, Benjamin.

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:

  • A resource is anything that is given a unique subject URI.
  • A class (or, classification) is a meaningful way of grouping resources.
  • An individual of a class is a resource that has been placed into that class (also sometimes called an instance of the class).

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):

@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
@prefix tutorial: <http://www.linkeddatatools.com/tutorial#>

tutorial:canine rdf:type rdfs:Class .
tutorial:feline rdf:type rdfs:Class .
tutorial:murinae rdf:type rdfs:Class .

Before digging deeper, let's give our classes some helpful human friendly descriptions too:

@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
@prefix tutorial: <http://www.linkeddatatools.com/tutorial#>

tutorial:canine rdf:type rdfs:Class .
tutorial:canine rdfs:label "A classification of all members of the canine species" .

tutorial:feline rdf:type rdfs:Class .
tutorial:feline rdfs:label "A classification of all members of the feline species" .

tutorial:murinae rdf:type rdfs:Class .
tutorial:murinae rdfs:label "A classification of all members of the murinae species" .

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:

  • Resource http://www.linkeddatatools.com/tutorial#canine is an individual of the class rdfs:Class.
  • Resource http://www.linkeddatatools.com/tutorial#feline is an individual of the class rdfs:Class.
  • Resource http://www.linkeddatatools.com/tutorial#murinae is an individual of the class rdfs:Class.

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:

@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
@prefix tutorial: <http://www.linkeddatatools.com/tutorial#>
@prefix thing: <http://www.linkeddatatools.com/thing#>

tutorial:canine rdf:type rdfs:Class .
tutorial:canine rdfs:label "A classification of all members of the canine species" .

tutorial:feline rdf:type rdfs:Class .
tutorial:feline rdfs:label "A classification of all members of the feline species" .

tutorial:murinae rdf:type rdfs:Class .
tutorial:murinae rdfs:label "A classification of all members of the murinae species" .

thing:bengie rdfs:label "Our dog, called Bengie".
thing:bengie dcterms:description "A friendly member of the canine species".
thing:bengie rdf:type tutorial:canine .

thing:bonnie rdfs:label "Our cat, called Bonnie".
thing:bonnie dcterms:description "A friendly member of the feline species".
thing:bonnie rdf:type tutorial:feline .

thing:benjamin rdfs:label "Our mouse, called Benjamin".
thing:benjamin dcterms:description "A friendly member of the murinae species".
thing:benjamin rdf:type tutorial:murinae.

As an exercise, see now if you can see how we have placed Bengie, Bonnie and Benjamin into membership of their respective appropriate classes.

Semantic Web Primer e-Book

NEW! Semantic Web Primer e-Book (First Edition)

Includes all our primer tutorials. Plus two exclusive new tutorials on RDF syntaxes, and NoSQL databases found only in the e-Book.

4. Subclasses

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:

@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
@prefix tutorial: <http://www.linkeddatatools.com/tutorial#>

tutorial:animal rdf:type rdfs:Class .
tutorial:animal rdfs:label "A classification of all members of the animal kingdom" .

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:

@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
@prefix tutorial: <http://www.linkeddatatools.com/classes#>

tutorial:animal rdf:type rdfs:Class .
tutorial:animal rdfs:label "A classification of all members of the animal kingdom" .

tutorial:canine rdf:type rdfs:Class .
tutorial:canine rdfs:label "A classification of all members of the canine species" .
tutorial:canine rdfs:subClassOf tutorial:animal .

tutorial:feline rdf:type rdfs:Class .
tutorial:feline rdfs:label "A classification of all members of the feline species" .
tutorial:feline rdfs:subClassOf tutorial:animal .

tutorial:murinae rdf:type rdfs:Class .
tutorial:murinae rdfs:label "A classification of all members of the murinae species" .
tutorial:murinae rdfs:subClassOf tutorial:animal .

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:

@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
@prefix tutorial: <http://www.linkeddatatools.com/classes#>
@prefix thing: <http://www.linkeddatatools.com/thing#>

tutorial:animal rdf:type rdfs:Class .
tutorial:animal rdfs:label "A classification of all members of the animal kingdom" .

tutorial:canine rdf:type rdfs:Class .
tutorial:canine rdfs:label "A classification of all members of the canine species" .
tutorial:canine rdfs:subClassOf tutorial:animal .

tutorial:feline rdf:type rdfs:Class .
tutorial:feline rdfs:label "A classification of all members of the feline species" .
tutorial:feline rdfs:subClassOf tutorial:animal .

tutorial:murinae rdf:type rdfs:Class .
tutorial:murinae rdfs:label "A classification of all members of the murinae species" .
tutorial:murinae rdfs:subClassOf ldt:animal .

thing:bengie rdfs:label "Our dog, called Bengie".
thing:bengie dcterms:description "A friendly member of the canine species".
thing:bengie rdf:type tutorial:canine .

thing:bonnie rdfs:label "Our cat, called Bonnie".
thing:bonnie dcterms:description "A friendly member of the feline species".
thing:bonnie rdf:type tutorial:feline .

thing:benjamin rdfs:label "Our mouse, called Benjamin".
thing:benjamin dcterms:description "A friendly member of the murinae species".
thing:benjamin rdf:type tutorial:murinae.

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).

  • If we omitted all the class definitions from our ontology, the fact that we have defined some individuals of our canine, and feline and murinae classes means that a semantic web reader could still infer that tutorial:canine, tutorial:feline and tutorial:muranae were classes.
  • If we omitted the tutorial:animal class definition from the ontology we have just created, but left the statement that canine, feline and murinae were all subclasses of the tutorial:animal class, a semantic web reader could still infer that tutorial:animal was a class, despite us not explicitly defining it in our ontology.

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.

Semantic Web Primer e-Book

NEW! Semantic Web Primer e-Book (First Edition)

Includes all our primer tutorials. Plus two exclusive new tutorials on RDF syntaxes, and NoSQL databases found only in the e-Book.

You have completed this lesson. You should now understand the following:

  • What a resource, class, subclass and individual is, and be able to distinguish between them.
  • Understand how to define them using RDF Schema.
  • A little of reasoning over RDF Schema classes.
  • That OWL is, in a sense, a more sophisticated extension of RDF Schema.

You should now be able to start the following tutorial:

 

Comments  

 
#2 2015-06-10 16:34
Easy to read - thanks!
Quote
 
 
#1 2015-06-07 05:59
Thanks, good tutorial
Quote
 

Add comment

Security code
Refresh

Community

Register to download software from our site and interact with other users as you learn semantic web.