PREFIX st:   <http://ns.inria.fr/sparql-template/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX dc: <http://purl.org/dc/terms/>
PREFIX fun: <http://w3id.org/sparql-generate/fn/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX obo: <http://purl.obolibrary.org/obo/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX schema: <http://schema.org/>

 
TEMPLATE <ontology/contributor.rqg>( ?contributor ) { 
  IF( ISURI(?contributor), "<a href='{?contributor}'>", "<span>" )

  IF( !BOUND(?givenName) && !BOUND(?familyName),
   IF( ISURI(?contributor) , ?contributor, "(unnamed contributor)"),
   "{IF(BOUND(?givenName), ?givenName, "")} {IF(BOUND(?familyName), ?familyName, "")}"  )

  IF( ISURI(?contributor), "</a>", "</span>" )

  TEMPLATE {
    IF( ISURI(?affiliation), " <a href='{?affiliation}'>", " <span>" )
    IF( BOUND(?name) , "({?name})" , IF( ISURI(?affiliation), "({?affiliation})", "(unnamed affiliation)"))
    IF( ISURI(?affiliation), "</a>", "</span>" )
  } WHERE {
    ?contributor schema:affiliation ?affiliation
    OPTIONAL { ?affiliation schema:name ?name }
  } .
  

} WHERE {
  OPTIONAL { ?contributor schema:givenName ?givenName }
  OPTIONAL { ?contributor schema:familyName ?familyName }
}
