Semantically Reflected Programs

Eduard Kamburjan, Vidar Norstein Klungre, Yuanwei Qu, Rudolf Schlatte, Egor V. Kostylev, Martin Giese, Einar Broch Johnsen

TL;DR

This paper introduces SMOL, a programming language that bridges the gap between dynamic code execution and static domain knowledge. By "lifting" program states into a knowledge graph and providing a "semantic reflection" layer, it allows programs to query and reason about their own execution state using standard Semantic Web technologies like SPARQL and OWL.

What Problem Does This Paper Address?

There is a long-standing "dichotomy" in computer science:

  1. Structural Knowledge: Best represented by ontologies and knowledge graphs (KGs), which excel at describing complex relationships and rules within a domain (e.g., "What geological conditions trigger oil formation?").
  2. Behavioral Knowledge: Best represented by programming languages, which describe how a system evolves over time (e.g., "Simulate 1,000 years of sediment deposition").

Currently, these two worlds are often siloed. A program might have a complex internal state, but it "doesn't know" how that state relates to high-level domain concepts unless the programmer manually writes tedious mapping code. The authors aim to unify these by letting the program "see" its own state through the lens of a domain ontology.

Methods

The authors present SMOL (Semantic Micro Object Language), a small object-oriented language designed with two core features:

  • Semantic Lifting: This is the process of automatically translating the program's runtime state (objects, fields, and even the call stack) into an RDF knowledge graph. Crucially, programmers can control this lifting using modifiers:
  • hidden: Excludes a field from the graph to save memory.
  • domain: Moves a field's data directly into the "domain" part of the graph.
  • links: Explicitly connects a program object to a concept in a domain ontology based on logical conditions.
  • Semantic Reflection: This allows the program to query its own lifted state during execution. It introduces three new expressions:
  • access(sparql, ...): Runs a SPARQL query against the program's state.
  • member(owl_concept): Returns all objects that belong to a specific OWL class.
  • validate(shacl_shape): Checks if the current state conforms to a specific data constraint.

To ensure this doesn't lead to runtime crashes, the authors developed a static type system that can check if a SPARQL query's results are compatible with the program's variable types before the code even runs.

Datasets

As this is a programming language design paper, it does not use traditional training datasets. Instead, the authors evaluate SMOL through several real-world case studies:

  • Geological Modeling: A simulator for petroleum geoscience that uses a complex ontology (GeoCore) to identify "triggering layers" for geological processes.
  • Digital Twins: Applications in smart buildings and greenhouses where the program adapts its behavior based on an "asset model" (a knowledge graph of the physical environment).

Key Insights and Ideas

  • Separation of Concerns: The program handles the how (the simulation logic), while the ontology handles the what (the complex definitions of domain concepts). This prevents domain logic from being "hard-coded" into the software.
  • Virtualization is Key: Materializing a full RDF graph at every step of a program would be incredibly slow. The authors implement a "pull-based" virtualization where triples are only generated when a query actually asks for them.
  • The "Aha!" Moment: By using links and access, a programmer can write a loop that says "for every object that the domain expert defines as a 'CookingTrigger', run the cook() method," without the programmer ever needing to know the exact technical criteria for what a "CookingTrigger" is.
Figure 1: The interaction between static modeling (ontologies) and dynamic modeling (programs).

Key Results

  • Formal Proofs: The authors provide a full formalization of the SMOL semantics and prove Type Safety. This means a well-typed SMOL program will never "get stuck" due to a semantic query returning the wrong kind of data.
  • Performance: In the geological case study, the SMOL-based simulator was able to reproduce complex results (previously done manually by geologists) for the Ekofisk formation in under 10 minutes.
  • Open Source: The language implementation, including the interpreter and the type checker, is available on GitHub.

Limitations and Future Work

  • Reasoning Overhead: While virtualization helps, performing complex OWL reasoning at runtime is still computationally expensive.
  • Dynamic Queries: The current type system works for static queries. If a program builds a SPARQL query string dynamically at runtime, the current system cannot guarantee type safety.
  • Garbage Collection: There is a subtle "race" between the garbage collector (which deletes unreferenced objects) and semantic reflection (which might still want to query those objects). The authors currently solve this by disabling automatic garbage collection in favor of manual memory management (destroy).

For a look at how this looks in practice, Figure 2 shows the SMOL code used to model geological layers, including the links clauses that connect code to the domain ontology.

Figure 2: SMOL code for geological layers, showing the use of semantic modifiers.

Summary updated

BibTeX
@article{kamburjan2026semantically,
  author = {Eduard Kamburjan and Vidar Norstein Klungre and Yuanwei Qu and Rudolf Schlatte and Egor V. Kostylev and Martin Giese and Einar Broch Johnsen},
  title = {{Semantically Reflected Programs}},
  journal = {TGDK},
  year = {2026},
  doi = {10.4230/tgdk.4.1.3},
}
Figure