Hi Andy,
thanks for your answer. I knew about UNDEF, but the fact is I don't have
control over the data (as I said, I'm trying to fit this into TARQL,
which takes a csv and adds a VALUE block to a CONSTRUCT template, to
convert to RDF). I'll see what the authors of the tool say about the
option to recognise some special value as UNDEF, although, even so, one
would still have the problem of how to filter out non-empty values that
shouldn't produce a mapping (e.g., I'm dealing with a file where '###'
in a column of numbers means empty).
By the way, my current workaround is to produce triples with surname set
at '', and then to pass the resulting dataset to the Jena 'sparql'
command line, together with another CONSTRUCT that filters out those
values. It works, but it's a bit more cumbersome and not ideal for large
data sets.
Marco.
On 26/02/2017 16:54, Andy Seaborne wrote:
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