<?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 vitro: &lt;http://vitro.mannlib.cornell.edu/ns/vitro/0.7#&gt;
        PREFIX foaf: &lt;http://xmlns.com/foaf/0.1/&gt;
        PREFIX fn:   &lt;http://www.w3.org/2005/xpath-functions#&gt;

        SELECT DISTINCT <collated> ?subclass </collated>
            ?position
            ?positionTitle
            ?person ?personName
            ?dateTimeStart ?dateTimeEnd
            ?hideThis
        WHERE
        {
            ?subject ?property ?position .
            ?position a core:Position .

            OPTIONAL {
                <precise-subquery>?subject ?property ?position .
                ?position a core:Position .</precise-subquery>
                ?position core:relates ?person .
                ?person a foaf:Person .
                ?person rdfs:label ?personName .
            }
        <collated>
            OPTIONAL
            {
                <precise-subquery>?subject ?property ?position .
                ?position a core:Position .</precise-subquery>
                ?position vitro:mostSpecificType ?subclass .
                OPTIONAL
                {
                    <precise-subquery>?subject ?property ?position .
                    ?position a core:Position .
                    ?position vitro:mostSpecificType ?subclass .</precise-subquery>
                    ?subclass vitro:displayRankAnnot ?displayRank .
                }
            }
        </collated>
            OPTIONAL {
                <precise-subquery>?subject ?property ?position .
                ?position a core:Position .</precise-subquery>
                ?position rdfs:label ?positionTitle .
            }
            OPTIONAL {
                <precise-subquery>?subject ?property ?position .
                ?position a core:Position .</precise-subquery>
                ?position core:hideFromDisplay ?hideThis .
            }
            OPTIONAL {
                <precise-subquery>?subject ?property ?position .
                ?position a core:Position .</precise-subquery>
                ?position core:dateTimeInterval ?dateTimeInterval .
                ?dateTimeInterval core:start ?dateTimeStartValue .
                ?dateTimeStartValue core:dateTime ?dateTimeStart .
            }
            OPTIONAL
            {
                <precise-subquery>?subject ?property ?position .
                ?position a core:Position .</precise-subquery>
                ?position core:dateTimeInterval ?dateTimeInterval .
                ?dateTimeInterval core:end ?dateTimeEndValue .
                ?dateTimeEndValue core:dateTime ?dateTimeEnd .
            }
            # Get current positions only: end date is either null or not in the past
            FILTER ( !bound(?dateTimeEnd) || substr(str(?dateTimeEnd), 1, 4) &gt;= substr(str(now()), 1, 4) )
        <critical-data-required>
            FILTER ( bound(?person) )
        </critical-data-required>
        <collated>FILTER ( ?displayRank &lt; 500 )</collated>
        } ORDER BY <collated> ?subclass </collated> (fn:lower-case(?personName))
    </query-select>

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