One SPARQL select query returns graph name while another does not return any data for the given example data.
Below is the example data for the two queries. There are two named graphs - Main and DefaultValues. The data describes objects and their properties. DefaultValues graph stores default values for the properties.
Data
PREFIX ex: <http://example/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
INSERT DATA {
GRAPH ex:Main {
ex:ID1 a ex:Object .
ex:ID1 rdfs:label "p1" .
ex:ID1 ex:height 1.5 .
ex:ID2 a ex:Object .
ex:ID2 rdfs:label "p2" .
ex:ID2 ex:description "p2 data" .
}
GRAPH ex:DefaultValues {
ex:ID1 ex:description "" .
ex:ID2 ex:height 0.0 .
}
}
Query 1
PREFIX ex: <http://example/>
SELECT ?id ?p ?o ?g
FROM NAMED ex:Main
FROM NAMED ex:DefaultValues
WHERE {
VALUES ?id { ex:ID1 ex:ID2 }
GRAPH ?g { ?id ?p ?o . }
}
Results of Query 1
Query 2
PREFIX ex: <http://example/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?id ?name ?height ?description ?g
FROM NAMED ex:Main
FROM NAMED ex:DefaultValues
WHERE {
VALUES ?id { ex:ID1 ex:ID2 }
GRAPH ?g {
?id rdfs:label ?name .
?id ex:height ?height .
?id ex:description ?description .
}
}
Query 1 and Query 2 look same in the WHERE clause, I'm not able to understand why Query 2 isn't returning any data or how Query 1 does return the data along with the graph.
Ultimately, my goal is to know the graph in which the property exists. For example, height, description for ID1, ID2.
