PREFIX foaf: PREFIX dct: PREFIX schema: PREFIX xsd: PREFIX geo: CONSTRUCT { GRAPH ?graph { ?graph dct:title ?lastName ; foaf:primaryTopic ?employee ; foaf:topic ?postalAddress . ?employee a schema:Person ; schema:identifier ?employeeID ; dct:title ?lastName ; dct:description ?title ; schema:givenName ?firstName ; schema:familyName ?lastName ; schema:jobTitle ?title ; schema:honorificPrefix ?titleOfCourtesy ; schema:birthDate ?birthDate; # ?hireDate schema:address ?postalAddress ; schema:telephone ?homePhone ; schema:telephone ?extension ; schema:description ?notes ; schema:sponsor ?reportsToEmployee ; geo:lat ?lat ; geo:long ?long ; foaf:img ?photo . ?postalAddress a schema:PostalAddress ; foaf:page ?graph ; schema:addressCountry ?country ; schema:addressLocality ?city ; schema:postalCode ?postalCode ; schema:streetAddress ?address ; schema:addressRegion ?region . } } WHERE { ?employee_row <#employeeID> ?employeeID ; <#lastName> ?lastName ; <#firstName> ?firstName ; <#title> ?title ; <#titleOfCourtesy> ?titleOfCourtesy ; <#birthDate> ?birthDateString ; <#hireDate> ?hireDateString ; <#address> ?address ; <#city> ?city ; <#postalCode> ?postalCode ; <#country> ?country ; <#homePhone> ?homePhone ; <#extension> ?extension ; <#photoHash> ?photoHash ; <#notes> ?notes ; <#lat> ?lat_string ; <#long> ?long_string . OPTIONAL { ?employee_row <#region> ?region } OPTIONAL { ?employee_row <#reportsTo> ?reportsTo BIND(uri(concat(str($base), "employees/", encode_for_uri(?reportsTo), "/#this")) AS ?reportsToEmployee) # cannot use ?container since it's undefined in the OPTIONAL scope } BIND(uri(concat(str($base), "employees/")) AS ?container) BIND(uri(concat(str(?container), encode_for_uri(?employeeID), "/")) AS ?graph) BIND(uri(concat(str(?graph), "#this")) AS ?employee) BIND(uri(concat(str(?graph), "#address")) AS ?postalAddress) BIND(xsd:float(?lat_string) AS ?lat) BIND(xsd:float(?long_string) AS ?long) BIND(strdt(substr(?birthDateString, 1, 10), xsd:date) AS ?birthDate) BIND(strdt(substr(?hireDateString, 1, 10), xsd:date) AS ?hireDate) BIND(uri(concat(str($base), "uploads/", encode_for_uri(?photoHash))) AS ?photo) }