Skip to content

Classes

Classes are the foundation of an OWL ontology. They define categories of things in your domain.

:Animal a owl:Class .
:Person a owl:Class .
:Organization a owl:Class .

rdfs:subClassOf creates parent-child relationships. This is what drives subsumption queries.

:Mammal a owl:Class ; rdfs:subClassOf :Animal .
:Dog a owl:Class ; rdfs:subClassOf :Mammal .
:Cat a owl:Class ; rdfs:subClassOf :Mammal .
:GoldenRetriever a owl:Class ; rdfs:subClassOf :Dog .

The hierarchy is transitive: GoldenRetriever is a subclass of Dog, Mammal, and Animal. When data is inserted as GoldenRetriever, the materializer adds all ancestor types automatically.

Disjoint classes cannot share instances. If you declare Dog disjoint with Cat, a node cannot be both.

:Dog owl:disjointWith :Cat .

The materializer checks disjointness after all inference rules are applied. If a mutation would result in a node having two disjoint types, the entire mutation is rejected.

Equivalent classes are treated as synonyms. Asserting one implies the other.

:Canine owl:equivalentClass :Dog .

OWLGraph supports class expressions for more complex definitions:

:WorkingDog a owl:Class ;
owl:equivalentClass [
a owl:Class ;
owl:intersectionOf ( :Dog :ServiceAnimal )
] .
:Pet a owl:Class ;
owl:equivalentClass [
a owl:Class ;
owl:unionOf ( :Dog :Cat :Bird )
] .
:NonMammal a owl:Class ;
owl:equivalentClass [
a owl:Class ;
owl:complementOf :Mammal
] .
# Anything that has at least one hasOwner relationship
:OwnedAnimal a owl:Class ;
owl:equivalentClass [
a owl:Restriction ;
owl:onProperty :hasOwner ;
owl:someValuesFrom :Person
] .
  • Keep hierarchies shallow — deep hierarchies (10+ levels) increase materialization cost per write
  • Use disjointness — it catches data quality issues at write time instead of query time
  • Name classes clearly — class names become Dgraph types and GraphQL types
  • Avoid cycles — OWLGraph rejects circular subclass declarations