DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Why AI Agents Need a Shared Enterprise Ontology
  • How Did We Go From ChatGPT to Autonomous AI Agents in Just Four Years?
  • How Has AI Impacted Code Obfuscation?
  • Voice AI Is Running on Untuned WebRTC: 20 Services To Show You Where

Trending

  • Getting Started With Milvus: Vector Search for Enterprise Java Applications
  • How Did We Go From ChatGPT to Autonomous AI Agents in Just Four Years?
  • Avoiding AI Debt as a Team
  • AI Didn't Replace Software Engineering; It Changed the Bottleneck

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Data Engineering
  3. AI/ML
  4. From Theory to Practice: Building an Enterprise Ontology With Python and Kubernetes

From Theory to Practice: Building an Enterprise Ontology With Python and Kubernetes

Build, validate, deploy, and query an enterprise e-commerce ontology using Python, RDF/OWL, SHACL, Apache Jena Fuseki, and Kubernetes.

By 
Josephine Eskaline Joyce, Ph.D
DZone Core CORE ·
Nov. 25, 26 · Analysis
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
18 Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

Moving From Ontology Concepts to Implementation

The previous article, Why AI Agents Need a Shared Ontology, explored how ontologies provide a shared semantic foundation for AI agents, enabling them to interpret business concepts, understand relationships, and operate with a consistent view of enterprise data.

However, understanding the value of ontology is just the start. The next challenge is to turn those concepts into a working implementation that can be developed, validated, queried, deployed, and maintained as part of an enterprise technology ecosystem.

An ontology is not just a list of business terms or a diagram. For it to be operational, it needs a formal representation of domain knowledge, clearly defined relationships, validation rules, a query mechanism, and an infrastructure environment (applications/services) where applications and services can access it.

This is where Python, RDF, OWL, SHACL, SPARQL, Apache Jena Fuseki, and Kubernetes come together.

From Semantic Models to Working Systems

Consider a typical e-commerce application involving customers, products, orders, and payments. These entities may exist across different databases, applications, and services, each with its own data model and terminology.

An enterprise ontology defines a common semantic model of what these entities represent and how they relate to one another. (A customer orders something; an order has products, and each product belongs to a category). But defining these relationships is not sufficient. We also need to answer practical engineering questions:

  • How do we represent business concepts and relationships using Resource Description Framework (RDF) and Web Ontology Language (OWL)?
  • How can Python be used to create, load, and query ontology data?
  • How do we enforce data quality and semantic constraints using Shapes Constraint Language (SHACL)?
  • How can applications query the knowledge graph using Protocol and RDF Query Language (SPARQL)?
  • How do we deploy and expose the ontology through a containerized service running on Kubernetes?
  • How can we incorporate ontology validation into automated testing and CI/CD pipelines?

Answering these questions transforms ontology development from a conceptual exercise to an engineering discipline.

What We Will Build

In this tutorial, we plan to build a working e-commerce ontology in Python and deploy it on our local Kubernetes cluster.

We will model customers, products, and orders using RDF and OWL first; populate the ontology with sample data; validate structure and constraints (SHACL) on it; perform SPARQL queries to get meaningful business relationships.

Once the ontology is working locally, we will deploy Apache Jena Fuseki as a SPARQL endpoint on a Kubernetes cluster created with kind (Kubernetes in Docker). We will use Podman for container image management, and Kubernetes manifests to deploy and expose the service.

Next, we will see how to run automated tests and validate ontology changes before deploying them to an application environment. The objective is not to build an enterprise knowledge platform in one tutorial. Instead, the aim is to establish a practical, reproducible foundation from which we can show how semantic modeling works with validation, querying, and cloud-native deployment.

At the end of this tutorial, a functioning ontology-backed service would be implemented that can be queried via SPARQL and extended for more complex use cases (knowledge-driven applications, semantic interoperability, and AI agents running on shared business context).

The central idea is simple: an ontology becomes valuable when it moves beyond defining what enterprise data means and becomes an operational component that applications can use.

Understanding the Reference Architecture


The architecture separates ontology development from runtime services. Python is the development and automation layer; RDF and OWL are semantic model definitions; SHACL checks data consistency; Apache Jena Fuseki stores and exposes the knowledge graph; Kubernetes provides the deployment environment.

Key Components of the Architecture

Ontology Modeling: RDF and OWL

The foundation of the platform is the ontology model. RDF stores information as triples (subject, predicate, object). OWL extends RDF-based modeling with constructs for defining classes, properties, relationships, and logical semantics.

In our e-commerce example, we define concepts such as Customer, Order, Product, and Payment, along with relationships such as placesOrder and containsProduct.

Together, these definitions establish a common semantic vocabulary that applications can use to interpret enterprise data consistently.

Ontology Processing: Python and RDFLib

Python provides the programming environment for working with the ontology. Using the RDFLib library, we can load RDF/OWL files, manipulate graph data, execute SPARQL queries, and automate ontology-related operations.

This lets us develop and test the ontology locally before adding infrastructure dependencies.

Data Validation: SHACL

Defining an ontology does not necessarily guarantee that all incoming data satisfies business requirements.

SHACL allows us to define validation constraints on RDF data. For example, we can say that every customer has a name and email address or that a product has a valid price.

We will use Python and pySHACL to validate sample data against these constraints before loading it into the knowledge graph.

Knowledge Graph Storage: Apache Jena Fuseki

Once the ontology and its instance data are ready, they need to be accessible to other applications.

Apache Jena Fuseki provides an RDF storage and query service that exposes SPARQL endpoints over HTTP. Applications can retrieve and update graph data via standards-based interfaces.

In our implementation, Fuseki will store the e-commerce ontology and its associated instance data, making relationships between customers, orders, and products queryable.

Application Integration: SPARQL and REST APIs

SPARQL is the standard query language for retrieving and manipulating RDF graph data.

Applications can access Fuseki directly (via a SPARQL endpoint) or through an application API built with Python and FastAPI.

For example, an application can query all products purchased by a particular customer by traversing the relationships in the ontology.

Cloud-Native Deployment: Containers and Kubernetes

Finally, we need an environment where the ontology service can be deployed and managed.

We use Podman to build container images and kind to create a local Kubernetes cluster. Apache Jena Fuseki and the Python API will run as containerized services inside Kubernetes.

Kubernetes provides service discovery, workload management, and deployment orchestration. For production use, the architecture can be extended with persistent storage, authentication, monitoring, resource controls, and high availability.

How the Components Work Together

The reference architecture follows a simple development-to-runtime workflow:

  1. Model: Define business concepts, properties, and relationships using RDF and OWL.
  2. Populate: Create sample instances representing customers, products, and orders.
  3. Validate: Apply SHACL constraints to verify the consistency and completeness of the RDF data.
  4. Store: Load the validated RDF graph into Apache Jena Fuseki.
  5. Query: Execute SPARQL queries to retrieve business entities and relationships.
  6. Deploy: Run Fuseki and the Python application services on Kubernetes.

It is important to distinguish between an ontology and a knowledge graph. Ontologies define the semantic structure and meaning of a domain; knowledge graphs combine those definitions with actual entities and their relationships.

In this implementation, the ontology and sample data are represented as RDF graphs and loaded into Fuseki, where they can be queried together.

Designing the E-Commerce Ontology

The first step in implementing an enterprise ontology is to define the business domain and identify the concepts and relationships that need to be represented.

In this tutorial, we’ll use an e-commerce domain consisting of customers, orders, products, and payments. Although these concepts are familiar in traditional application development, ontology modeling approaches them differently.

We don’t design database tables and foreign keys; we define semantic classes, properties, and relationships that describe what business entities mean and how they are connected.

E-commerce ontology

Identifying Domain Concepts

We start by listing the entities involved in an e-commerce transaction.

A customer places an order, an order contains products, and payments are associated with orders. These relationships form the foundation of our ontology.

In more advanced models, we can introduce an OrderItem class to store individual order lines, including purchased quantities and prices.

The objective is to create a reusable semantic model rather than copying the structure of an existing database.

Identifying domain concepts

Defining Classes and Properties

Once the domain concepts are identified, we define them as OWL classes.

Defining classes and properties

Object properties establish relationships between individuals. For example, placesOrder connects a customer to an order, while containsProduct connects an order to a product.

Object properties

Datatype properties describe literal attributes such as customer names, email addresses, product prices, and order dates.

Datatype properties

Using these constructs, we establish the vocabulary needed to represent and query e-commerce information consistently.

Establishing Relationships and Constraints

Ontology modeling also means defining the intended semantics of relationships. For example, the placesOrder property can have Customer as its domain and Order as its range. These declarations support semantic interpretation and inference.

However, OWL is not a conventional database constraint engine. Domain and range declarations are used for reasoning, and OWL cardinality restrictions do not automatically reject incomplete data.

For operational data-quality requirements, we will introduce SHACL in the validation section.

Choosing Namespaces and IRIs

Every class, property, and individual in an RDF ontology is identified by an Internationalized Resource Identifier (IRI).

For this tutorial, we will use a consistent namespace such as:

http://example.com/ecommerce/

This allows us to define identifiers such as:

  • http://example.com/ecommerce/Customer
  • http://example.com/ecommerce/Product
  • http://example.com/ecommerce/placesOrder

For production ontologies, these identifiers should use a domain controlled by the organization and follow a stable naming convention.

Modeling the Ontology With Protégé

We will use Protégé to create and inspect the ontology visually. Protégé provides an interface for defining OWL classes, object properties, datatype properties, and individuals. It also allows us to inspect the class hierarchy and verify how the different elements are connected.

Once the model is defined, we will export it in Turtle format and use Python RDFLib for further processing.

This separation lets domain modeling be done visually while ontology validation, querying, and deployment remain automated. 

Exporting the Ontology

After completing the model, we save the ontology as ecommerce-combined.ttl.

Turtle serializes RDF in a human-readable way so that the ontology is suitable for source control, code reviews, automated testing, and CI/CD. The exported file becomes the starting point for the next stage, where we will populate the ontology with sample e-commerce data and query the resulting knowledge graph.

Once we are done with the model, we save the ontology as ecommerce-combined.ttl.

Implementing the Ontology With Python

With the e-commerce ontology modeled in WebProtégé, the next step is to make it accessible programmatically using Python and RDFLib.

RDFLib provides the capabilities to load, manipulate, serialize, and query RDF graphs. This allows us to work with ontology definitions and instance data locally without requiring a graph database or Kubernetes infrastructure.

Setting Up the Project

The implementation is organized into separate directories for ontology definitions, sample data, SHACL validation rules, Python scripts, automated tests, and Kubernetes deployment manifests.

The complete project, including dependencies and setup instructions, is available on GitHub: Enterprise E-Commerce Ontology — GitHub Repository.

The repository's README provides step-by-step instructions for running the implementation locally and deploying it to Kubernetes.

Loading and Processing the Ontology

We first export the ontology from WebProtégé in Turtle format and save it as ontology/ecommerce-combined.ttl.

With RDFLib, the exported graph can be inspected and processed. The implementation also splits ontology definitions from instance data into two files:

  • ontology/ecommerce.ttl – Defines ontology classes and properties.
  • ontology/sample-data.ttl – Contains sample entities and their relationships.

This separation allows us to keep the semantic model and the data represented by that model distinct.

Querying the Knowledge Graph Locally

Once the ontology and sample data are loaded, we can run SPARQL queries using RDFLib to traverse business relationships. For example, we can identify products associated with customer orders by following the placesOrder and containsProduct relationships.

The repository includes scripts/query_local.py, which shows how to query the ontology directly from Turtle files.

Shell
 
python scripts/query_local.py ontology/ecommerce.ttl   ontology/sample-data.ttl


This verifies that the ontology is not merely a collection of definitions but a queryable semantic graph representing actual business relationships.

At this stage, we have a working local knowledge graph that can be inspected and queried using Python, without introducing Apache Jena Fuseki or Kubernetes.

The complete implementation, Python scripts, sample data, and execution instructions are available in the GitHub README.

Validating the Ontology With SHACL

RDF and OWL specify the structure and semantics of an ontology but do not enforce all data-quality constraints that enterprise applications need (e.g., uniqueness). For example, OWL can describe a customer class and its properties, but it does not necessarily reject a customer record that is missing an email address.

This is where Shapes Constraint Language (SHACL) becomes important. In our e-commerce implementation, SHACL shapes specify validation requirements for customers, products, and orders:

  • CustomerShape: Validates customer names and email addresses.
  • ProductShape: Validates product names and prices.
  • OrderShape: Validates relationships between orders and customers.

We use Python with pySHACL to validate the RDF graph against these shapes.

Python
 
python scripts/validate.py


The validation process returns a conformance result and reports constraint violations when the data fails validation. The project's validation script also returns a nonzero exit status on failure. This is an important operational control because invalid RDF data can be detected before being published to the knowledge graph. The complete SHACL definitions and validation implementation are available in the GitHub repository.

From a Working Prototype to an Enterprise Ontology Platform

While the above implementation provides a functional foundation, operating an ontology at enterprise scale brings other considerations. The challenge moves from creating a semantic model to making sure it’s governed, secure, scalable, and reusable as business requirements change over time.

Ontology Versioning and Change Management

Enterprise ontologies are constantly being updated as new business concepts, relationships and applications are introduced.

Ontology definitions, SHACL shapes and other artifacts should be version controlled with changes reviewed and tested before release. Changes to classes, properties, or IRIs should also be evaluated for impact on existing SPARQL queries and consuming applications. Stable IRIs, documented deprecation policies, and compatibility checks are needed to keep semantic consistency across versions.

Governance and Ownership

An enterprise ontology needs clearly defined ownership.

Domain experts should own the meaning of business concepts, while ontology engineers maintain the semantic model and platform teams manage the supporting infrastructure.

A light governance process should set standards for naming conventions, namespace management, ontology extensions, and approval of changes. This prevents different teams from introducing conflicting definitions of the same business concepts.

Security and Access Control

As ontologies become shared enterprise assets, access to their data and query interfaces must be controlled.

In production environments, SPARQL endpoints and APIs should be protected through authentication, authorization, encrypted communication, and network policies. Access controls may need to distinguish between users who can query the graph and those authorized to modify ontology definitions or instance data. Sensitive business information should also be governed according to organizational data-classification and privacy requirements.

Scalability, Persistence, and Reliability

The local Kubernetes deployment demonstrates how ontology services can be containerized and managed, but production environments require additional operational safeguards.

Persistent storage is essential for preserving RDF datasets across pod restarts and rescheduling. Backup and recovery procedures, resource monitoring, and capacity planning become important as graph size and query traffic increase. The storage architecture should be selected based on expected data volume, query complexity, concurrency, and availability requirements.

CI/CD and Deployment Promotion

Ontology development can be done using the same controlled delivery practices as application development.

 A CI/CD pipeline can check RDF syntax, SHACL checks, ontology tests, and incompatible schema changes before pushing updates to development, testing, and production environments. Separating ontology definitions from environment-specific configurations also makes deployments more predictable and reproducible.

Reusing the Ontology Across Applications and AI Agents

One of the most important benefits of an enterprise ontology is that it can be used as a shared semantic foundation for many applications. Instead of having different interpretations for customers, products, and orders, applications can use common ontology definitions and query interfaces.

The same foundation can be used for analytics platforms, knowledge-driven applications, and AI agents that need to discover and interpret business relationships. However, a shared ontology does not guarantee interoperability. Applications must adopt its vocabulary, identifiers, and data contracts consistently.

The table below summarizes the key differences between the prototype developed in this tutorial and the capabilities typically expected in an enterprise ontology platform.

Capability
Working Prototype
Enterprise Platform

Ontology Management

RDF/OWL files maintained in Git

Versioning, lifecycle management, and change governance

Validation

SHACL validation and local tests

Automated validation and quality gates

Governance

Developer-managed definitions

Domain ownership and approval processes

Security

Local access to endpoints

Authentication, authorization, and auditing

Storage

Local RDF dataset

Persistent storage, backups, and recovery

Deployment

Local Kubernetes cluster

Controlled CI/CD and environment promotion

Integration

Sample SPARQL queries and APIs

Shared semantic contracts across applications and AI agents


The key transition from prototype to enterprise platform is therefore not simply scaling the knowledge graph. It is establishing the governance, engineering practices, and operational controls needed to maintain a trustworthy semantic foundation across the organization.

Evolving Toward an Enterprise Knowledge Platform

The e-commerce ontology implemented in this tutorial shows how semantic models can be developed, validated, deployed, and queried using open standards and cloud native technologies.

But the same architecture can be scaled up from a single application to a shared enterprise knowledge platform.

Enterprise Knowledge Platform

As shown in the above figure, enterprise architecture adds governance, validation automation, persistent graph storage, access controls, and reusable semantic services on top of the foundational ontology implementation.

These capabilities enable several extensions:

  • AI agents: Agents can leverage ontology-backed services to find business entities, navigate relationships, and retrieve structured contextual information.
  • Semantic retrieval: Knowledge graph queries can complement vector-based retrieval and RAG (retrieval augmented generation): explicit relationships and structured business context.
  • Cross-system interoperability: Applications in different business domains can reuse shared vocabulary, identifiers, and semantic mappings to exchange information consistently.

Instead of each application interpreting business entities differently, the ontology becomes a reusable semantic layer between enterprise systems, applications, and AI-driven services.

This is the move from a standalone knowledge graph implementation to a governed enterprise knowledge platform which can support multiple applications and AI agents.

Conclusion

Building an enterprise ontology is not just about classes and relationships — it’s also about making business knowledge accessible, consistent and reusable across applications.

In this tutorial, we moved from ontology concepts to a working implementation (Python, RDF/OWL, SHACL, Apache Jena Fuseki and Kubernetes). We modeled an e-commerce domain, validated its data, queried relationships using SPARQL, and deployed the knowledge graph as a cloud native service.

This is just the starting point – this same foundation can be used to build a governed enterprise knowledge platform with semantic interoperability, knowledge-driven applications and AI agents that share business context.

The future of enterprise AI isn't just about smarter models; it's about giving them a shared understanding of the world they operate in.

AI Ontology (information science)

Opinions expressed by DZone contributors are their own.

Related

  • Why AI Agents Need a Shared Enterprise Ontology
  • How Did We Go From ChatGPT to Autonomous AI Agents in Just Four Years?
  • How Has AI Impacted Code Obfuscation?
  • Voice AI Is Running on Untuned WebRTC: 20 Services To Show You Where

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook