On 02/05/11 21:28, Deepak Konidena wrote:
Hi,
When I try to use fn:concat and afn:strJoin in the following fashion:
PREFIX fn:<http://www.w3.org/2005/xpath-functions#>
PREFIX afn:<http://jena.hpl.hp.com/ARQ/function#>
select ?ALLTEXT ?d ?e ?h ?j ?k ?l where{
?a rdf:type foaf:Person ; ?b ?c .
?c rdf:type core:Position .
optional { ?c core:hrJobTitle ?d . } .
optional { ?c core:involvedOrganizationName ?e . } .
optional { ?c core:positionForPerson ?f . ?f rdfs:label ?h .}
optional { ?c core:positionInOrganization ?i . ?i rdfs:label ?j .}
optional { ?c core:titleOrRole ?k .}
optional { ?c rdfs:label ?l . }
LET (?ALLTEXT := fn:concat(?k, " ", ?l )) .
LET (?ALLTEXT := afn:strJoin(?k, " ", ?l ))
}
The variable ALLTEXT gets populated only when both ?k and ?l are not empty.
When one
Of them is empty, ALLTEXT is showing an empty result.
By not empty, I take it you mean unbound.
How would I modify this behavior? Ideally, you would expect fn:concat to
concatenate even empty results.
Am I doing anything wrong here?
The behaviour is correct and nothing to do with fn:concat.
For any strict function:
function(unbound) -> error
because the arguments are evaluated before the function is called, and
eval(?x) -> error for unbound ?x
An error in LET will leave it unbound.
Try:
SELECT * { LET ( ?A := 1/0 ) }
You may wish to use COALESCE:
BIND (COALESCE(?k, "") as ?k2)
to give a default value to ?k as ?k2. Only new variables are legal in
BIND but it is SPARQL 1.1.
Thanks,
Deepak Konidena.
Andy