Skip to content
SDB
Knowledge Graphs

Chapter 03 · intermediate · 25 min

Ontologies and RDFS/OWL

Defining the vocabulary and meaning of your knowledge graph

Subhendu Datta BhowmikAI Tutorials

What Is an Ontology?

An ontology is a formal specification of a domain's vocabulary — the classes (types of things), properties (relationships), and the rules governing them. If the knowledge graph is the data, the ontology is the schema that gives that data meaning.

Think of an ontology as a shared dictionary for your domain. Without it, "Person" in one dataset might mean something different from "Person" in another. With a shared ontology, machines can understand and interoperate across datasets.

The Two Levels of a Knowledge Graph

LayerNameContent
T-BoxTerminological BoxClasses, properties, axioms (the schema)
A-BoxAssertional BoxIndividual instances and their relationships (the data)

The T-Box defines what kinds of things exist. The A-Box says what things actually exist.

Knowledge graph7 nodes · 7 edges

Nodes

  • owl:Thingclass

    The root class — every individual is a Thing

  • foaf:Agentclass

    An agent (person or organization)

  • foaf:Personclass

    A human person

  • ex:Employeeclass

    A person employed by an organization

  • org:Organizationclass

    An organization or company

  • aliceinstance

    Instance of foaf:Person and ex:Employee

  • Acme Corpinstance

    Instance of org:Organization

Edges

  • Agentrdfs:subClassOfThing
  • Personrdfs:subClassOfAgent
  • Employeerdfs:subClassOfPerson
  • Organizationrdfs:subClassOfThing
  • alice_instrdf:typeEmployee
  • acme_instrdf:typeOrganization
  • alice_instworksForacme_inst
Class hierarchy (T-Box) shown as rectangles, instance data (A-Box) shown as circles with dashed type edges. Click nodes to explore.

RDFS: RDF Schema

RDFS (RDF Schema) is the simplest ontology language. It provides:

  • rdfs:Class — declares a class
  • rdfs:subClassOf — declares class inheritance
  • rdf:Property — declares a property
  • rdfs:domain — specifies which class a property applies to
  • rdfs:range — specifies which class/datatype a property's values must be
  • rdfs:label / rdfs:comment — human-readable names and descriptions

RDFS is intentionally simple. For more expressive power, you need OWL.

An RDFS schema for a simple organization domainturtle
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xsd:  <http://www.w3.org/2001/XMLSchema#> .
@prefix ex:   <http://example.org/schema/> .

# Class definitions
ex:Agent     a rdfs:Class ;
    rdfs:label "Agent" .

ex:Person    a rdfs:Class ;
    rdfs:subClassOf ex:Agent ;
    rdfs:label "Person" ;
    rdfs:comment "A human individual." .

ex:Employee  a rdfs:Class ;
    rdfs:subClassOf ex:Person ;
    rdfs:label "Employee" .

ex:Organization  a rdfs:Class ;
    rdfs:subClassOf ex:Agent ;
    rdfs:label "Organization" .

# Property definitions
ex:name  a rdf:Property ;
    rdfs:domain ex:Agent ;
    rdfs:range  xsd:string ;
    rdfs:label  "name" .

ex:age  a rdf:Property ;
    rdfs:domain ex:Person ;
    rdfs:range  xsd:integer ;
    rdfs:label  "age" .

ex:worksFor  a rdf:Property ;
    rdfs:domain ex:Employee ;
    rdfs:range  ex:Organization ;
    rdfs:label  "works for" .

OWL: Web Ontology Language

OWL (Web Ontology Language) adds much richer expressiveness on top of RDFS:

OWL ConstructMeaning
owl:equivalentClassTwo classes have the same members
owl:disjointWithNo instance can be in both classes
owl:inverseOfA property is the inverse of another
owl:TransitivePropertyIf A→B→C then A→C
owl:FunctionalPropertyEach subject has at most one value
owl:cardinalityExact number of values required

OWL is the basis for reasoning — an OWL reasoner can automatically infer new facts from existing ones (covered in Chapter 7).

Well-Known Ontologies

You don't have to write ontologies from scratch. Many reusable vocabularies exist:

  • FOAF (Friend of a Friend) — for people and social networks
  • Schema.org — Google's vocabulary for web content; covers products, events, reviews, etc.
  • Dublin Core — for metadata like title, creator, date
  • PROV-O — for provenance and data lineage
  • Gene Ontology — for biological processes, functions, and components
OWL axioms — expressing richer semanticsturtle
@prefix owl:  <http://www.w3.org/2002/07/owl#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix ex:   <http://example.org/schema/> .

# Inverse properties
ex:worksFor   owl:inverseOf  ex:employs .

# Transitive property
ex:locatedIn  a owl:TransitiveProperty .
# → if London locatedIn England, England locatedIn UK
#   then London locatedIn UK (inferred)

# Functional property — a person has exactly one birth date
ex:birthDate  a owl:FunctionalProperty .

# Disjoint classes — nothing can be both a Person and an Organization
ex:Person  owl:disjointWith  ex:Organization .

# Equivalent classes — ex:Employee ≡ schema:Employee
ex:Employee  owl:equivalentClass  <https://schema.org/Employee> .

# Cardinality restriction — a Company must have at least 1 employee
ex:Company  rdfs:subClassOf [
    a owl:Restriction ;
    owl:onProperty ex:employs ;
    owl:minCardinality 1
] .

Knowledge check

Which RDFS construct is used to declare that one class is a specialization of another (inheritance)?

Summary

In this chapter you learned:

  1. An ontology defines the T-Box (schema) for your knowledge graph — classes, properties, and axioms
  2. RDFS provides simple class hierarchies and property constraints
  3. OWL adds richer semantics: inverse properties, transitivity, cardinality, disjoint classes
  4. The Open World Assumption means missing facts are unknown, not false

Next, we'll learn how to query a knowledge graph using SPARQL.

Knowledge Graphs