<?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 foaf:  &lt;http://xmlns.com/foaf/0.1/&gt;

        PREFIX bibo:  &lt;http://purl.org/ontology/bibo/&gt;
        PREFIX core:  &lt;http://vivoweb.org/ontology/core#&gt;
        PREFIX owl:   &lt;http://www.w3.org/2002/07/owl#&gt;
        PREFIX rdfs:  &lt;http://www.w3.org/2000/01/rdf-schema#&gt;
        PREFIX vitro: &lt;http://vitro.mannlib.cornell.edu/ns/vitro/0.7#&gt;

        SELECT DISTINCT  <collated>?subclass</collated>
            ?adviseeRole
            ?advisingRel
            ?advisingRelLabel
            ?localName
            ?advisor
            ?advisorLabel
            ?degreeLabel
            ?degreeAbbr
            ?dateTimeStart
            ?dateTimeEnd

        WHERE
        {
            ?subject ?property ?adviseeRole .
            ?adviseeRole a core:AdviseeRole .
            ?adviseeRole core:relatedBy ?advisingRel .
            ?advisingRel a core:AdvisingRelationship .
            LET ( ?localName := REPLACE(STR(?advisingRel),"^.*(#)(.*)$", "$2") )
            OPTIONAL {
                <precise-subquery>?subject ?property ?adviseeRole .
                ?adviseeRole a core:AdviseeRole .
                ?adviseeRole core:relatedBy ?advisingRel .
                ?advisingRel a core:AdvisingRelationship .</precise-subquery>
                ?advisingRel rdfs:label ?advisingRelLabel .
            }
            OPTIONAL {
                <precise-subquery>?subject ?property ?adviseeRole .
                ?adviseeRole a core:AdviseeRole .
                ?adviseeRole core:relatedBy ?advisingRel .
                ?advisingRel a core:AdvisingRelationship .</precise-subquery>
                ?advisingRel core:relates ?advisorRole .
                ?advisorRole &lt;http://purl.obolibrary.org/obo/RO_0000052&gt; ?advisor .
                ?advisor a foaf:Person .
                ?advisor &lt;http://purl.obolibrary.org/obo/RO_0000053&gt; ?advisorRole .
                ?advisorRole a core:AdvisorRole .
                ?advisor rdfs:label ?advisorLabel .
            }
            OPTIONAL {
                <precise-subquery>?subject ?property ?adviseeRole .
                ?adviseeRole a core:AdviseeRole .
                ?adviseeRole core:relatedBy ?advisingRel .
                ?advisingRel a core:AdvisingRelationship .</precise-subquery>
                ?advisingRel core:degreeCandidacy ?degree .
                ?degree rdfs:label ?degreeLabel .
            }
            OPTIONAL {
                <precise-subquery>?subject ?property ?adviseeRole .
                ?adviseeRole a core:AdviseeRole .
                ?adviseeRole core:relatedBy ?advisingRel .
                ?advisingRel a core:AdvisingRelationship .</precise-subquery>
                ?advisingRel core:degreeCandidacy ?degree .
                ?degree core:abbreviation ?degreeAbbr .
            }
        <collated>
            OPTIONAL {
                <precise-subquery>?subject ?property ?adviseeRole .
                ?adviseeRole a core:AdviseeRole .
                ?adviseeRole core:relatedBy ?advisingRel .
                ?advisingRel a core:AdvisingRelationship .</precise-subquery>
                ?advisingRel vitro:mostSpecificType ?subclass .
                ?subclass rdfs:subClassOf core:AdvisingRelationship .
            }
        </collated>
            OPTIONAL {
                <precise-subquery>?subject ?property ?adviseeRole .
                ?adviseeRole a core:AdviseeRole .
                ?adviseeRole core:relatedBy ?advisingRel .
                ?advisingRel a core:AdvisingRelationship .</precise-subquery>
                ?advisingRel core:dateTimeInterval ?dateTimeInterval .
                ?dateTimeInterval core:start ?dateTimeStartValue .
                ?dateTimeStartValue core:dateTime ?dateTimeStart .
            }
            OPTIONAL {
                <precise-subquery>?subject ?property ?adviseeRole .
                ?adviseeRole a core:AdviseeRole .
                ?adviseeRole core:relatedBy ?advisingRel .
                ?advisingRel a core:AdvisingRelationship .</precise-subquery>
                ?advisingRel core:dateTimeInterval ?dateTimeInterval .
                ?dateTimeInterval core:end ?dateTimeEndValue .
                ?dateTimeEndValue core:dateTime ?dateTimeEnd .
            }

        }  ORDER BY  <collated>?subclass</collated> DESC(?dateTimeEnd)
    </query-select>

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