1

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

csv 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.

3
  • 2
    your second query does require all the triples being contained in a single graph, but your data is indeed contained across both graphs, thus, the empty result Commented May 28 at 11:05
  • 1
    what you could do is to put each triple pattern in a separate graph block each with a different graph name Commented May 28 at 11:06
  • @UninformedUser How does the first query return results ? Commented May 28 at 13:19

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.