OWL (Web Ontology Language)
A W3C standard for defining formal ontologies with rich semantics, constraints, and reasoning capabilities built on RDF, enabling automated inference and validation.
OWL (Web Ontology Language) is a W3C standard for creating formal ontologies that define classes, properties, relationships, and logical constraints. OWL extends RDF and RDFS with richer semantics, enabling automated reasoning, validation, and inference over knowledge graphs.
OWL Profiles
OWL provides three profiles with different expressiveness and computational complexity:
OWL 2 Full
- Most expressive: Complete logical power
- Undecidable: No guaranteed reasoning termination
- Use case: Research, complex domains requiring maximum expressiveness
OWL 2 DL (Description Logic)
- Decidable: Guaranteed reasoning termination
- Powerful: Most common features without computational explosion
- Use case: Enterprise ontologies, medical systems, e-commerce
OWL 2 EL (Existential Logic)
- Efficient: Polynomial-time reasoning
- Scalable: Millions of classes/properties
- Use case: Large biomedical ontologies (SNOMED CT, Gene Ontology)
OWL 2 QL (Query Logic)
- Database-friendly: Maps to SQL queries
- Efficient querying: Suitable for large data volumes
- Use case: Ontology-based data access (OBDA)
OWL 2 RL (Rule Logic)
- Rule-based: Implementable via rule engines
- Practical: Common reasoning patterns
- Use case: Business rules, lightweight reasoning
Core OWL Constructs
1. Classes
Define types of things:
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix ex: <http://example.org/> .
# Basic class definition
ex:Person a owl:Class ;
rdfs:label "Person" ;
rdfs:comment "A human being" .
# Class hierarchy
ex:Employee a owl:Class ;
rdfs:subClassOf ex:Person .
ex:Manager a owl:Class ;
rdfs:subClassOf ex:Employee .
ex:CEO a owl:Class ;
rdfs:subClassOf ex:Manager .
2. Properties
Define relationships and attributes:
# Object properties (relate individuals)
ex:worksAt a owl:ObjectProperty ;
rdfs:domain ex:Employee ; # Subject must be Employee
rdfs:range ex:Company ; # Object must be Company
rdfs:label "works at" .
# Datatype properties (relate to literals)
ex:age a owl:DatatypeProperty ;
rdfs:domain ex:Person ;
rdfs:range xsd:integer ;
rdfs:label "age" .
ex:email a owl:DatatypeProperty ;
rdfs:domain ex:Person ;
rdfs:range xsd:string ;
rdfs:label "email address" .
3. Property Characteristics
Special property types:
# Functional: Max one value per subject
ex:hasCEO a owl:ObjectProperty ;
a owl:FunctionalProperty ; # Company has exactly one CEO
rdfs:domain ex:Company ;
rdfs:range ex:CEO .
# Inverse Functional: Max one subject per value
ex:hasEmployeeID a owl:DatatypeProperty ;
a owl:InverseFunctionalProperty ; # Employee ID uniquely identifies person
rdfs:domain ex:Employee ;
rdfs:range xsd:string .
# Transitive: If A→B and B→C, then A→C
ex:manages a owl:ObjectProperty ;
a owl:TransitiveProperty ; # Manager of manager is also a manager
rdfs:domain ex:Manager ;
rdfs:range ex:Employee .
# Symmetric: If A→B then B→A
ex:colleagueOf a owl:ObjectProperty ;
a owl:SymmetricProperty ; # Colleague relationship is bidirectional
rdfs:domain ex:Employee ;
rdfs:range ex:Employee .
# Inverse properties
ex:worksAt a owl:ObjectProperty ;
owl:inverseOf ex:employs .
ex:employs a owl:ObjectProperty ;
rdfs:domain ex:Company ;
rdfs:range ex:Employee .
Class Axioms & Restrictions
Equivalence and Disjointness
# Equivalent classes (same individuals)
ex:Company owl:equivalentClass schema:Organization .
# Disjoint classes (no shared individuals)
ex:Person owl:disjointWith ex:Company .
ex:CEO owl:disjointWith ex:Intern . # Can't be both
Cardinality Restrictions
# Employee must work at exactly one company
ex:Employee a owl:Class ;
rdfs:subClassOf [
a owl:Restriction ;
owl:onProperty ex:worksAt ;
owl:cardinality 1
] .
# Manager must manage at least 1 person
ex:Manager a owl:Class ;
rdfs:subClassOf [
a owl:Restriction ;
owl:onProperty ex:manages ;
owl:minCardinality 1
] .
# CEO leads at most one company
ex:CEO a owl:Class ;
rdfs:subClassOf [
a owl:Restriction ;
owl:onProperty ex:leadsCompany ;
owl:maxCardinality 1
] .
Value Restrictions
# All employees work at companies (not other types)
ex:Employee a owl:Class ;
rdfs:subClassOf [
a owl:Restriction ;
owl:onProperty ex:worksAt ;
owl:allValuesFrom ex:Company
] .
# Managers manage at least some Employees
ex:Manager a owl:Class ;
rdfs:subClassOf [
a owl:Restriction ;
owl:onProperty ex:manages ;
owl:someValuesFrom ex:Employee
] .
# CEO leads a specific company
ex:CEO_TechCorp a owl:Class ;
rdfs:subClassOf [
a owl:Restriction ;
owl:onProperty ex:leadsCompany ;
owl:hasValue ex:TechCorp
] .
Class Expressions
Union, Intersection, Complement
# Union: Employee OR Contractor
ex:Worker a owl:Class ;
owl:unionOf (ex:Employee ex:Contractor) .
# Intersection: Engineer AND Manager
ex:EngineeringManager a owl:Class ;
owl:intersectionOf (ex:Engineer ex:Manager) .
# Complement: NOT Terminated
ex:ActiveEmployee a owl:Class ;
owl:intersectionOf (
ex:Employee
[ owl:complementOf ex:TerminatedEmployee ]
) .
Enumeration
# Define class by listing individuals
ex:FoundingTeam a owl:Class ;
owl:oneOf (ex:alice ex:bob ex:charlie) .
Reasoning and Inference
OWL reasoners automatically derive new facts:
Example: Transitive Management
Ontology:
ex:manages a owl:TransitiveProperty .
Asserted Facts:
ex:alice ex:manages ex:bob .
ex:bob ex:manages ex:charlie .
Inferred Fact:
ex:alice ex:manages ex:charlie . # Automatic inference
Example: Class Hierarchy
Ontology:
ex:CEO rdfs:subClassOf ex:Manager .
ex:Manager rdfs:subClassOf ex:Employee .
ex:Employee rdfs:subClassOf ex:Person .
Asserted Fact:
ex:alice a ex:CEO .
Inferred Facts:
ex:alice a ex:Manager .
ex:alice a ex:Employee .
ex:alice a ex:Person .
Example: Property Chains
# If someone lives in a city, and that city is in a country,
# then they live in that country
ex:livesIn a owl:ObjectProperty ;
owl:propertyChainAxiom (ex:livesInCity ex:cityInCountry) .
# Asserted
ex:alice ex:livesInCity ex:SanFrancisco .
ex:SanFrancisco ex:cityInCountry ex:USA .
# Inferred
ex:alice ex:livesIn ex:USA .
OWL in TrustGraph
Ontology RAG with OWL
TrustGraph's Ontology RAG uses OWL ontologies to guide knowledge extraction:
# Define OWL ontology
cat sensors-ontology.owl | tg-put-config-item \
--type ontology \
--key sensors \
--stdin
# Create Ontology RAG flow
tg-start-flow -n onto-rag -i onto-rag -d "Ontology-guided extraction"
# Process documents with ontology
tg-start-library-processing \
--flow-id onto-rag \
--document-id report-001 \
--collection intelligence
Benefits:
- Extracted entities conform to OWL class definitions
- Relationships respect domain/range constraints
- Reasoner validates data against ontology
- Inferred facts automatically derived
OWL Reasoners
Common reasoning engines:
- HermiT: Complete OWL 2 DL reasoner
- Pellet: OWL 2 DL with custom rules
- Fact++: Fast OWL 2 DL reasoner
- ELK: Scalable OWL 2 EL reasoner
- OWLRL: OWL 2 RL rule-based reasoning
Use Cases
- Medical Ontologies: SNOMED CT, Disease Ontology
- Biomedical Research: Gene Ontology, Protein Ontology
- E-commerce: Product taxonomies with reasoning
- Semantic Search: Query expansion via class hierarchies
- Data Validation: Ensure data conforms to constraints
- Ontology RAG: Type-safe knowledge extraction
- Regulatory Compliance: Validate against rules
OWL vs RDFS
| Feature | RDFS | OWL |
|---|---|---|
| Class hierarchy | ✅ Basic | ✅ Rich with axioms |
| Property hierarchy | ✅ Basic | ✅ With characteristics |
| Cardinality | ❌ | ✅ Min/max/exact |
| Equivalence | ❌ | ✅ Classes and properties |
| Disjointness | ❌ | ✅ |
| Reasoning | Limited | Powerful inference |
| Complexity | Simple | More complex |
Best Practices
- Start Simple: Use RDFS, add OWL only when needed
- Choose Right Profile: Match expressiveness to requirements
- Document Ontology: Clear labels and comments
- Version Control: Track ontology evolution
- Test Reasoning: Verify inferences match expectations
- Performance: More axioms = slower reasoning
- Modular Design: Split large ontologies into modules
- Standard Vocabularies: Reuse existing ontologies when possible
Limitations
- Complexity: Steep learning curve
- Performance: Reasoning can be slow for large ontologies
- Debugging: Hard to understand why reasoning fails
- Over-modeling: Easy to create overly complex ontologies
- Tool Support: Fewer tools than property graph systems
See Also
- Ontology - Formal domain specifications
- RDF - Foundation for OWL
- RDFS - RDF Schema
- SKOS - Simple Knowledge Organization System
- Ontology RAG - Schema-driven knowledge extraction
- Semantic Web - Machine-readable web vision
Examples
- •Class hierarchy: CEO rdfs:subClassOf Manager rdfs:subClassOf Employee
- •Property constraint: worksAt domain: Employee, range: Company
- •Equivalence: ex:Organization owl:equivalentClass schema:Organization