Semantic Web Querying

Introduction

Using Ontologies as Datastore and representing Data in Ontologies is one thing but at some point some might want to ask specific Questions about the Data and retrieve a result. I found after some research that this is not as simple as it might sound.

If anything here is not correct, please help me to improve and leave a comment.

Q1
Which stones are in a Silver Bucket?
Q2
How Many Stones are there weighting more than 20?

SQL

SQL is specialised to query data from the relational model. There are a lot of extensions and various different implementations.

From the described Bucket.owl Ontology the SQL Schema should look more or less like the following.

CREATE TABLE buckets(
    id INT PRIMARY KEY
,    material VARCHAR(40)
,     engraving VARCHAR(40) ARRAY[20]
);
 
CREATE TABLE stones(
    id INT PRIMARY KEY
,    weight INT NOT NULL
,    datefound DATETIME NOT NULL
,    in_bucket INT REFERENCES buckets(id)
);
Q1
SELECT s.*
FROM stones s JOIN buckets b ON b.id = s.id
WHERE b.material = 'Silver';
Q2
SELECT COUNT(*) 
FROM stones s
WHERE s.weight > 20;

SPARQL

Sparql is a query language for RDF. It has thus only limited Knowledge of the special semantics in OWL [2].

Q1
PREFIX buck: <http://www.yoshtec.com/ontology/test/Bucket#>
PREFIX xsd:    <http://www.w3.org/2001/XMLSchema#> 

SELECT  ?x 
WHERE { ?x buck:weight ?size 
     FILTER( ?size < "20"^^xsd:int )
    }
Q2

I have no Idea how to express this query in Sparql itself.

SWRL

SWRL is not really a query language, it is a Rule language! However it can be extended to handle the execution of queries. Protege has an extension Ontology which does just that: SQWRL. It consists mainly of a collection of buildin-Functions that resemble the Query features.

But there are extreme Drawbacks: currently the only Engine capable of processing the extensions is Jess [1]. But it is not general avialable under an open source license, so it might hinder people using it.

Q1
Bucket(?b)  ∧ Contains(?b, ?s)  ∧ Stone(?s)  ∧ Material(?b, ?m)  ∧ swrlb:equal(?m, "Silver") → sqwrl:select(?s)
Q2
Stone(?s)  ∧  weight(?s, ?w)  ∧  swrlb:greaterThan(?w, 20) → sqwrl:count(?s)

Further Reading

Bibliography
2. Evren Sirin and Bijan Parsia: SPARQL-DL: SPARQL Query for OWL-DL http://pellet.owldl.com/papers/sirin07sparqldl.pdf
Add a New Comment
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License