Zak,

Using ?surname in the OPTIONAL-BIND does do not what you want. You'll want the VALUES block before the OPTIONAL but even then the problem is that the OPTIONAL matches graph pattern (an empty one) so ?surname is not set in the OPTIONAL.

Ideally, put UNDEF in the values.

    Andy

PREFIX ex: <http://www.example.com/data#>
CONSTRUCT {
  ?id ex:has-name ?name; ex:has-surname ?mySurname
}
WHERE
{
  VALUES (?id ?name ?surname)
  {
    ( ex:1 "John" "Smith" )
    ( ex:2 "Zak" "Mc Kracken" )
    ( ex:3 "Ben" UNDEF )
    ( ex:4 "Alice" "Wonderland" )
    ( ex:5 "Mickey" UNDEF )
  }
}

or use IF and make one branch an eval error:

PREFIX ex: <http://www.example.com/data#>
CONSTRUCT {
  ?id ex:has-name ?name; ex:has-surname ?mySurname
}
WHERE
{
  VALUES (?id ?name ?surname)
  {
    ( ex:1 "John" "Smith" )
    ( ex:2 "Zak" "Mc Kracken" )
    ( ex:3 "Ben" "" )
    ( ex:4 "Alice" "Wonderland" )
    ( ex:5 "Mickey" "" )
  }
  BIND ( IF ( ?surname!='' , ?surname, 1/0) AS ?mySurname ).
}


On 26/02/17 12:42, Zak Mc Kracken wrote:
Hi all, I was hoping to make this to work with Fuseki 2.3.0:

PREFIX ex: <http://www.example.com/data#>
CONSTRUCT {
  ?id ex:has-name ?name; ex:has-surname ?mySurname
}
WHERE
{
  OPTIONAL { BIND ( ?surname AS ?mySurname ).  FILTER ( ?surname != ''
) }
  #BIND ( ?surname AS ?mySurname )

  VALUES (?id ?name ?surname)
  {
    ( ex:1 "John" "Smith" )
    ( ex:2 "Zak" "Mc Kracken" )
    ( ex:3 "Ben" "" )
    ( ex:4 "Alice" "Wonderland" )
    ( ex:5 "Mickey" "" )
  }
}
i.e., I've a list of rows to build some RDF from, where certain field
values are empty or should be ignored. The result should produce triples
with name+surname, when surname is valid, only name, when it is invalid.
I always get back triples with name only, even when I use the
non-optional binding. So, how can I get this result, when using VALUES?

The longer story is that the problem have arisen from tests I was doing
with the very nice tool TARQL (https://github.com/tarql/tarql,
https://github.com/tarql/tarql/issues/55)

Thanks in advance,
Marco


Reply via email to