A.Sim
A.Sim

Reputation: 89

How to use two VALUES patterns in the same SPARQL query alternately

How can I modify the code below so as the machine to select the suitable VALUES pattern depending on ?description value? Is a modification like this possible???

PREFIX e: <http://learningsparql.com/ns/expenses#> 

SELECT ?description ?date ?amount
WHERE
{
  ?meal e:description ?description ;
        e:date ?date ;
        e:amount ?amount .

   VALUES ( ?description ?date) {
             ("lunch" "2011-10-15" ) 
             ("dinner" "2011-10-16" )
      } 

   VALUES ( ?description ?amount) {
         ("breakfast" "2") 
         ("brunch" "5" )
  }       

}

Thank you in advance...

Upvotes: 0

Views: 51

Answers (1)

Antoine Zimmermann
Antoine Zimmermann

Reputation: 5515

Perhaps you could do something like:

PREFIX e: <http://learningsparql.com/ns/expenses#> 

SELECT ?description ?date ?amount
WHERE
{
  ?meal e:description ?description ;
        e:date ?date ;
        e:amount ?amount .

   VALUES ( ?description ?date         ?amount ) {
          ( "lunch"      "2011-10-15"  UNDEF ) 
          ( "dinner"     "2011-10-16"  UNDEF )
          ( "breakfast"  UNDEF         "2" ) 
          ( "brunch"     UNDEF         "5" )
   }       
}

UNDEF means that the variable is unbound.

Upvotes: 1

Related Questions