allegrograph - Sparql - Concatenation fails if any one variable is not bound -


hi using allegrograph , sparql query retrieve results. sample data reproduces issue. consider below data person has first, middle , last names.

<http://mydomain.com/person1> <http://mydomain.com/firstname> "john"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#xmlliteral> <http://mydomain.com/person1> <http://mydomain.com/middlename> "paul"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#xmlliteral> <http://mydomain.com/person1> <http://mydomain.com/lastname> "jai"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#xmlliteral> <http://mydomain.com/person1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://mydomain.com/person>  <http://mydomain.com/person6> <http://mydomain.com/middlename> "mannan"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#xmlliteral> <http://mydomain.com/person6> <http://mydomain.com/lastname> "sathish"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#xmlliteral> <http://mydomain.com/person6> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://mydomain.com/person> 

now need compute persons name combining 3 names. names optional , person may not have of first, middle , last names.

query tried

select ?person ?name ?firstname ?middlename ?lastname  {   ?person rdf:type  <http://mydomain.com/person>.     optional {?person <http://mydomain.com/firstname> ?firstname}.     optional {?person <http://mydomain.com/middlename> ?middlename}.     optional {?person <http://mydomain.com/lastname> ?lastname}.         bind (concat(str(?firstname),str(?middlename),str(?lastname)) ?name). }  

but result set not contain name person6 (mannan sathish) since first name not present. please let me know if can ignore firstname if it's not bound.

result set

if variable not bound str(...) cause error on evaluation , whole bind fails.

coalesce can used give default values expressions.

bind ( coalesce(?firstname, "") ?firstname1) bind ( coalesce(?middlename, "") ?middlename1) bind ( coalesce(?lastname, "") ?lastname1) bind (concat(str(?firstname1),str(?middlename1),str(?lastname1)) ?name 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -