URNs are not resolved in queries with UNION { SERVICE { } }
The following SPARQL query works as expected. (This is running against a database created by my local branch of gnome-photos)
SELECT ?urn
{
{
SELECT ?urn
{
SERVICE <dbus:org.freedesktop.Tracker3.Miner.Files>
{
?urn a nmm:Photo .
}
}
}
UNION
{
SELECT ?urn
{
?urn a nfo:DataContainer
}
}
}
The results are like...
urn:bnode:ad8da8da-5921-4ad7-947f-16924ed5cc03
http://tracker.api.gnome.org/ontology/v3/nfo#image-category-screenshot
urn:uuid:64d5e767-e416-4041-bf84-47bd323acfe0
Initially I had the UNION the other way around, like this:
SELECT ?urn
{
{
SELECT ?urn
{
?urn a nfo:DataContainer
}
}
UNION
{
SELECT ?urn
{
SERVICE <dbus:org.freedesktop.Tracker3.Miner.Files>
{
?urn a nmm:Photo .
}
}
}
}
This produced bad results like this:
urn:uuid:0e7204fc-b2ef-4e8c-aa4a-5048a51b5aa1
(null)
(null)
Looking at the SQL query for the second case, we can see the problem:
SELECT (SELECT Uri FROM Resource WHERE ID = "v_urn" )
FROM (SELECT "v_urn"
FROM ((SELECT "v_urn"
FROM (SELECT "nfo:DataContainer1"."ID" AS "v_urn"
FROM (SELECT * FROM "unionGraph_nfo:DataContainer" ) AS "nfo:DataContainer1")))
UNION ALL
SELECT "v_urn"
FROM ((SELECT "v_urn"
FROM (SELECT col0 AS "v_urn"
FROM tracker_service
WHERE service="dbus:org.freedesktop.Tracker3.Miner.Files" AND
query="SELECT ?urn { ?urn a nmm:Photo . }" AND silent=0 ) ) ) )
ORDER BY (SELECT Uri FROM Resource WHERE ID = "v_urn" ) '
The initial SELECT query is trying to resolve URIs in the local database which were fetched from the remote database, resulting in (null)
values.