Semantic SPARQL Query in a Relational Database Based on Ontology Construction

Mohamed A. G. Hazber, Ruixuan Li, Xiwu Gu, Guandong Xu, Yuhua Li

Abstract

The integration of relational databases (RDBs) into the Semantic Web is often hindered by the "impedance mismatch" between rigid table structures and flexible graph-based ontologies. This paper presents a robust framework for bridging this gap through automated mapping rules that transform RDB schemas into OWL ontologies and translate SQL relational algebra into equivalent SPARQL queries. By specifically addressing the handling of null values and complex relationships, the proposed method ensures data parity. Evaluation on the RDBLAB dataset shows that the system achieves 100% accuracy compared to original SQL queries, preventing the data loss common in naive SPARQL translations.

Introduction

The "Deep Web" contains vast amounts of data stored in legacy relational databases. While the Semantic Web aims to make this data machine-understandable via RDF and OWL, migrating massive databases to triple stores is often impractical. The primary challenge lies in translating rigid SQL logic into graph-based SPARQL queries without losing information, particularly when dealing with many-to-many relationships or null values. Previous attempts often struggled with "data evaporation," where missing values caused entire result rows to be dropped in the semantic graph.

Methodology

The authors propose a two-phase approach: Ontology Construction and Query Rewriting.

Ontology Construction

The system utilizes "Direct Mapping Rules" to convert RDB components into OWL/RDF. Tables are mapped to classes, and columns to datatype properties. Crucially, the system identifies 1:1, 1:m, and m:n relationships by analyzing Primary and Foreign Keys, mapping them to object properties. To prevent data loss, the mapping ensures that rows containing null values do not break the resulting graph structure.

The RDBLAB database schema used for ontology construction and evaluation, highlighting primary and foreign key relationships.

Query Rewriting

The core innovation is the translation of Relational Algebra—the mathematical foundation of SQL—into SPARQL. Fundamental operations like Selection (σ) and Projection (Π) are mapped to SPARQL FILTER and SELECT patterns. Joins are handled using graph patterns and the OPTIONAL keyword. By systematically utilizing OPTIONAL and BOUND operators, the authors mimic SQL's handling of missing data, ensuring semantic queries return the exact same row count as their SQL counterparts.

Evaluation and Results

The approach was evaluated using RDBLAB, a custom dataset scaled to 70,000 rows (generating over 440,000 RDF triples). The dataset was specifically designed to include "dirty" data with thousands of null values in various columns to test the robustness of the mapping rules.

Experimental results confirmed zero data loss. In tests across six complex query types (Q1-Q6), the number of rows returned by the SQL engine matched the number of tuples from the optimized SPARQL engine ($Q^o$) exactly.

Comparison of returned rows/tuples across SQL, optimized SPARQL ($Q^o$), and naive SPARQL ($Q'$) queries, demonstrating 100% parity for the proposed method.

As shown in the results, naive SPARQL queries ($Q'$)—which do not account for null values or complex join logic—lost significant amounts of data. For instance, in Q2, the naive query missed nearly 7,000 results that the proposed method successfully captured. This confirms that the proposed algebra-based translation layer maintains 100% accuracy relative to the relational source.

Conclusion

By focusing on relational algebra, the authors created a universal translation layer that bridges the gap between RDBs and the Semantic Web. While the current framework handles fundamental operations successfully, future work will focus on extending the system to handle deeply nested SQL subqueries and optimizing performance for large-scale "Big Data" scenarios involving billions of triples.

Summary updated

Abstract

Constructing an ontology from RDBs and its query through ontologies is a fundamental problem for the development of the semantic web. This paper proposes an approach to extract ontology directly from RDB in the form of OWL/RDF triples, to ensure its availability at semantic web. We automatically construct an OWL ontology from RDB schema using direct mapping rules. The mapping rules provide the basic rules for generating RDF triples from RDB data even for column contents null value, and enable semantic query engines to answer more relevant queries. Then we rewriting SPARQL query from SQL by translating SQL relational algebra into an equivalent SPARQL. The proposed method is demonstrated with examples and the effectiveness of the proposed approach is evaluated by experimental results.
BibTeX
@inproceedings{hazber2015semantic,
  author = {Mohamed A. G. Hazber and Ruixuan Li and Xiwu Gu and Guandong Xu and Yuhua Li},
  title = {{Semantic SPARQL Query in a Relational Database Based on Ontology Construction}},
  booktitle = {SKG},
  year = {2015},
  doi = {10.1109/skg.2015.14},
}
Figure