Abstract
Graph-based data models allow for flexible data representation. In particular, semantic data based on RDF and OWL fuels use cases ranging from general knowledge graphs to domain specific knowledge in various technological or scientific domains. The flexibility of such approaches, however, makes programming with semantic data tedious and error-prone. In particular the logics-based data descriptions employed by OWL are problematic for existing error-detecting techniques, such as type systems. In this paper, we present DOTSpa, an advanced integration of semantic data into programming. We embed description logics, the logical foundations of OWL, into the type checking process of a statically typed programming language and provide typed data access through an embedding of the query language SPARQL. In addition, we demonstrate a concrete implementation of the approach, by extending the Scala programming language. We qualitatively compare programs using our approach to equivalent programs using a state-of-the-art library, in terms of how both frameworks aid users in the handling of typical failure scenarios.
Introduction
Programming with semantic data (RDF/OWL) is notoriously "stringy" and error-prone. Most developers rely on libraries like Apache Jena or banana-rdf, where SPARQL queries are treated as opaque strings. If you misspell a property, query for a "Person" that is logically disjoint from an "Organization," or pass the wrong type of URI to a function, the compiler won't save you.
The core challenge is that OWL is based on Description Logics (DL), which follow an "Open World Assumption" and have complex subtyping (subsumption) rules. Traditional object-oriented type systems struggle to map these dynamic, logic-based relationships into static class hierarchies without massive amounts of boilerplate or "blind" casting. This paper introduces DOTSpa, a framework that deeply integrates semantic web data into the type system of statically typed programming languages. By embedding an ontology reasoner directly into the compiler, the authors enable "ScaSpa" (a Scala implementation) to catch complex logic errors and unsatisfiable queries at compile time.
Methodology: The DOTSpa Framework
The authors propose a two-part solution:
- DOTSpa (Formalism): An extension of the Dependent Object Types (DOT) calculus—the theoretical foundation of Scala—that incorporates DL concept expressions as first-class types.
- ScaSpa (Implementation): A concrete Scala compiler plugin.
Instead of mapping an entire massive ontology to Scala classes, ScaSpa infers types for variables within SPARQL queries based on the ontology's axioms. During the "Typer" phase of compilation, ScaSpa calls an external ontology reasoner (HermiT) to validate subtyping relationships and query satisfiability.
As shown in the figure above, the system handles both schematic information (TBox) and assertional data (ABox). For instance, it can reason that Person and Organization are disjoint (⊥), or that an Employee must be a Person who worksFor an Organization.
Evaluation and Results
The paper uses the Lehigh University Benchmark (LUBM), a standard synthetic ontology describing a university setting. They use LUBM axioms to demonstrate how ScaSpa handles complex inferences—for example, proving that a ResearchAssistant is a subtype of Employee even if not explicitly stated in the code.
A qualitative comparison between ScaSpa and the state-of-the-art banana-rdf library across five failure scenarios revealed significant advantages:
- Query Satisfiability (E-SAT): ScaSpa catches logically impossible queries (e.g., querying for something that is both a Person and an Organization) at compile time.
- Concept Subtyping (E-SUB): ScaSpa ensures type safety across function boundaries; for example, preventing a
Personfrom being passed where anOrganizationis expected. - Property Access (E-ACCESS): ScaSpa uses "role projections" (like
chair.headOf) that are checked against the ontology. - Syntax (E-SYNTAX): SPARQL syntax errors are caught at compile time, whereas they cause runtime exceptions in traditional libraries.
Discussion and Future Work
The "aha moment" of this work is realizing that explicit class mapping is unnecessary. By bringing the "reasoner" (the logic engine) into the "compiler" (the type checker), the two worlds of Semantic Web and Software Engineering finally speak the same language.
However, some limitations remain. While the compiler is smart, IDEs currently lack autocomplete for DL concepts or SPARQL variables. Additionally, because DL types are erased to a common base type at runtime, standard Scala method overloading for different DL types is not currently supported. Future work includes improving performance for massive ontologies and refining type inference for complex SPARQL features like MINUS.
Summary updated