'How to define the triplets a SPARQL query consider during its execution? (creating self-contained examples)
Prologue
In SQL, it is possible to define the data a SELECT statement consider during its execution. I call these type of examples "self-contained examples" because they create the data the query runs on. The following are two examples of such queries.
The following query creates a "temporary table" with data using WITH. The data is then queried with a SELECT statement.
WITH foo AS (
(SELECT 1 AS c1, 10 AS c2, 100 AS c3)
UNION ALL
(SELECT 2 AS c1, 20 AS c2, 200 AS c3)
UNION ALL
(SELECT 3 AS c1, 30 AS c2, 300 AS c3)
)
SELECT * FROM foo;
c1 | c2 | c3
----+----+-----
1 | 10 | 100
2 | 20 | 200
3 | 30 | 300
The following query creates a temporary table and then inserts the data. The data is then queried with a SELECT statement.
CREATE TEMPORARY TABLE foo (
c1 INT,
c2 INT,
c3 INT
);
INSERT INTO foo VALUES
(1, 10, 100),
(2, 20, 200),
(3, 30, 300);
SELECT * FROM foo;
c1 | c2 | c3
----+----+-----
1 | 10 | 100
2 | 20 | 200
3 | 30 | 300
The question
I want to do something similar with SPARQL. I want my query to define/create the triplets the query runs on.
I've tried using VALUES. I thought the following did the job.
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX : <http://example.org/book/>
PREFIX ns: <http://example.org/ns#>
SELECT ?a ?b ?c {}
VALUES (?a ?b ?c) {
(:book1 dc:title "SPARQL Tutorial")
(:book1 ns:price 42)
(:book2 dc:title "The Semantic Web")
(:book2 ns:price 23)
}
a,b,c
http://example.org/book/book1,http://purl.org/dc/elements/1.1/title,SPARQL Tutorial
http://example.org/book/book1,http://example.org/ns#price,42
http://example.org/book/book2,http://purl.org/dc/elements/1.1/title,The Semantic Web
http://example.org/book/book2,http://example.org/ns#price,23
However, when I try to filter the results, no rows are returned. Link to the query in WDQS.
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX : <http://example.org/book/>
PREFIX ns: <http://example.org/ns#>
SELECT ?a ?b ?c {
?a dc:title "The Semantic Web".
}
VALUES (?a ?b ?c) {
(:book1 dc:title "SPARQL Tutorial")
(:book1 ns:price 42)
(:book2 dc:title "The Semantic Web")
(:book2 ns:price 23)
}
a,b,c
My question is: What alternatives do I have for creating such type of examples (they define the triplets the query runs on) in SPARQL?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
