I don't have AllegroGraph at hand but AFAIK it supports multiple order conditions:
select ?name ?person {
?person <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://mydomain.com/person> .
optional {?person <http://mydomain.com/name> ?name . }
} order by (!bound(?name)) asc(str(?name))
First condition sorts based on whether ?name
is bound or not and if this condition does not find a difference, the second condition is used. Note the use of str()
to convert rdf:XMLLiteral
to a datatype for which comparison is supported.
(You may also want to add .
at the end of each row in your ntriples data.)