<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- $This file is distributed under the terms of the license in LICENSE$ -->

<!-- See guidelines at https://wiki.duraspace.org/x/eYXVAw -->

<list-view-config>
    <query-select>
        PREFIX rdfs:  &lt;http://www.w3.org/2000/01/rdf-schema#&gt;
        PREFIX core:  &lt;http://vivoweb.org/ontology/core#&gt;
        PREFIX foaf:  &lt;http://xmlns.com/foaf/0.1/&gt;
        PREFIX vitro: &lt;http://vitro.mannlib.cornell.edu/ns/vitro/0.7#&gt;
        PREFIX vcard:  &lt;http://www.w3.org/2006/vcard/ns#&gt;
        PREFIX fn:   &lt;http://www.w3.org/2005/xpath-functions#&gt;

        SELECT DISTINCT ?subclass
            ?authorship
            ?author ?authorName
        WHERE {
            ?subject ?property ?authorship .
            ?authorship a core:Authorship .
            OPTIONAL {
                <precise-subquery>?subject ?property ?authorship .
                ?authorship a core:Authorship .</precise-subquery>
                ?authorship core:rank ?rank .
            }
            OPTIONAL {
                <precise-subquery>?subject ?property ?authorship .
                ?authorship a core:Authorship .</precise-subquery>
                ?authorship core:relates ?author .
                ?author a foaf:Agent .
                ?author rdfs:label ?authorName .
                OPTIONAL {
                    <precise-subquery>?subject ?property ?authorship .
                    ?authorship a core:Authorship .
                    ?authorship core:relates ?author .
                    ?author a foaf:Agent .</precise-subquery>
                    ?author vitro:mostSpecificType ?subclass .
                    ?subclass rdfs:subClassOf foaf:Agent .
                }
            }
            OPTIONAL {
                <precise-subquery>?subject ?property ?authorship .
                ?authorship a core:Authorship .</precise-subquery>
                ?authorship core:relates ?author .
                ?author a vcard:Kind .
                ?author vcard:hasName ?vName .
                ?vName vcard:familyName ?lastName .
                OPTIONAL {
                    <precise-subquery>?subject ?property ?authorship .
                    ?authorship a core:Authorship .
                    ?authorship core:relates ?author .
                    ?author a vcard:Kind .
                    ?author vcard:hasName ?vName .</precise-subquery>
                    ?vName vcard:givenName ?firstName .
                }
                OPTIONAL {
                    <precise-subquery>?subject ?property ?authorship .
                    ?authorship a core:Authorship .
                    ?authorship core:relates ?author .
                    ?author a vcard:Kind .
                    ?author vcard:hasName ?vName .</precise-subquery>
                    ?vName core:middleName ?middleName .
                }
                bind ( COALESCE(?firstName, "") As ?firstName1) .
                bind ( COALESCE(?middleName, "") As ?middleName1) .
                bind ( COALESCE(?lastName, "") As ?lastName1) .
                bind (concat(str(?lastName1),", ",str(?firstName1)," ",str(?middleName1)) as ?authorName) .

                OPTIONAL {
                    <precise-subquery>?subject ?property ?authorship .
                    ?authorship a core:Authorship .
                    ?authorship core:relates ?author .
                    ?author a vcard:Kind .</precise-subquery>
                    ?author vitro:mostSpecificType ?subclass .
                    ?subclass rdfs:subClassOf vcard:Kind .
                }
            }
        <critical-data-required>
            FILTER ( bound(?author) )
        </critical-data-required>
        } ORDER BY <collated> ?subclass </collated> ?rank (fn:lower-case(?authorName))
    </query-select>

    <template>propStatement-informationResourceInAuthorship.ftl</template>
</list-view-config>
