Classes

A class is a type of thing that we want to represent. An object that belongs to a class is an instance of the class. For example, we can assign the type of 'Laptop' to the RDF resource 'MacBookAir'.

A class hierarchy defines the relationships between the different classes. For example, a laptop is a specific type of computer, and so the Laptop would be a sub-class of the Computer class. Similarly, the Computer class would be the super-class of the Laptop class.

A sub-class is usually more specialized than its super-class, and will inherit many of the properties of the super-class. Similarly, it will also inherit any of the properties of its super-class's super-class (its 'grandparent'). In RDFS, each class can have multiple super-classes and/or sub-classes.

Classes can also be used to impose restrictions on RDF documents. For example, if our class hierarchy was correctly implemented, the statement 'The price of the MacBookAir is IntelCeleron2Duo' would not be allowed.

<rdf:Description rdf:ID="ComputerType">
  <rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Class" />
<rdf:Description>

<rdf:Description rdf:ID="Manufacturer">
  <rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Class" />
  <rdf:subClassOf rdf:resource="ComputerType" />
</rdf:Description>


<?xml version="1.1" ?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
         xmlns:rdfs"="http://www.w3.org/2000/01/rdf-schema#"
         xml:base="http://www.mycomputer.org/photo#">

  <rdfs:Class rdf:ID="ComputerType" />

  <rdfs:Class rdf:ID="Manufacturer">
    <rdfs:subClassOf rdf:resource="#ComputerType" />
  </rdfs:Class>
</rdf:RDF>

To create an instance of a class in RDF, we could say

<Manufacturer rdf:ID="Apple" />

Code adapted from Agency and the Semantic Web by Walton (2007), p33-34.