# $This file is distributed under the terms of the license in LICENSE$

@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix display: <http://vitro.mannlib.cornell.edu/ontologies/display/1.1#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix core: <http://vivoweb.org/ontology/core#> .
@prefix vivoweb: <http://vivoweb.org/ontology#> .


#### n3 for research areas ####

## associate the classes with the datagetter ##

<http://www.w3.org/2004/02/skos/core#Concept> display:hasDataGetter display:getDepartmentDataGetter .
<http://www.w3.org/2004/02/skos/core#Concept> display:hasDataGetter display:getVocabServiceDataGetter .

## define the datagetter ##

display:getDepartmentDataGetter
    a <java:edu.cornell.mannlib.vitro.webapp.utils.dataGetter.SparqlQueryDataGetter>;
    display:saveToVar "departmentsResults";
    display:query
        """
        PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
        PREFIX vivo: <http://vivoweb.org/ontology/core#>
        PREFIX foaf: <http://xmlns.com/foaf/0.1/>
        SELECT DISTINCT (str(?departmentLabel) AS ?deptLabel) ?dept
        WHERE {
            ?individualURI vivo:researchAreaOf ?person .
			?person vivo:relatedBy ?posn .
			?posn a vivo:Position .
            ?posn  vivo:relates ?dept .
            ?dept a foaf:Organization .
            ?dept rdfs:label ?departmentLabel
            OPTIONAL { ?posn vivo:dateTimeInterval ?dti
                     OPTIONAL { ?dti vivo:end ?end .
                                ?end vivo:dateTime ?endDate
                     }
            }
            FILTER ( !bound(?endDate) ||
                      substr(str(?endDate), 1, 4) >= substr(str(now()), 1, 4) )
        }
        ORDER BY ?deptLabel
        """ .

		display:getVocabServiceDataGetter
		    a <java:edu.cornell.mannlib.vitro.webapp.utils.dataGetter.SparqlQueryDataGetter>;
		    display:saveToVar "vocabularyService";
		    display:query
		        """
		        PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
		        PREFIX vivo: <http://vivoweb.org/ontology/core#>
		        SELECT DISTINCT (str(?vocabularySourceName) AS ?vocabService)
		        WHERE {
		            ?individualURI rdfs:isDefinedBy ?vocabularySource .
		            ?vocabularySource rdfs:label ?vocabularySourceName .
		        }
		        """ .

## detail page for dept research areas ##

<http://vitro.mannlib.cornell.edu/ns/default/page#AffiliatedDepartments>
    a   <http://vitro.mannlib.cornell.edu/ontologies/display/1.1#Page> ;
    <http://vitro.mannlib.cornell.edu/ontologies/display/1.1#hasDataGetter> <http://vitro.mannlib.cornell.edu/ns/default/datagetter#AffiliatedDepartmentsDG> ;
    <http://vitro.mannlib.cornell.edu/ontologies/display/1.1#requiresBodyTemplate> "individual-affiliated-dept-details.ftl" ;
    <http://vitro.mannlib.cornell.edu/ontologies/display/1.1#title> "Affiliated Departments" ;
    <http://vitro.mannlib.cornell.edu/ontologies/display/1.1#urlMapping> "/affiliatedDepartments" .

<http://vitro.mannlib.cornell.edu/ns/default/datagetter#AffiliatedDepartmentsDG>
    a   <java:edu.cornell.mannlib.vitro.webapp.utils.dataGetter.SparqlQueryDataGetter> ;
    <http://vitro.mannlib.cornell.edu/ontologies/display/1.1#query>
        """
        PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
        PREFIX vivo: <http://vivoweb.org/ontology/core#>
        PREFIX foaf: <http://xmlns.com/foaf/0.1/>
        SELECT DISTINCT (str (?prsnLabel) AS ?personLabel)
                        ?person
                        (Str(?researchAreaLabel) AS ?raLabel)
                        (str(?departmentLabel) AS ?orgLabel)
                        ?ra
                        ?org
        WHERE {
            ?orgURI vivo:relatedBy ?posn .
            ?posn a vivo:Position .
            ?orgURI rdfs:label ?departmentLabel .
            ?posn  vivo:relates ?person .
            ?person a foaf:Person .
            ?person rdfs:label ?prsnLabel .
            ?person vivo:hasResearchArea ?raURI .
            ?raURI rdfs:label ?researchAreaLabel
            BIND(?raURI AS ?ra)
            BIND(?orgURI AS ?org)

        }
        ORDER BY ?personLabel
        """ ;
        <http://vitro.mannlib.cornell.edu/ontologies/display/1.1#saveToVar>
                  "deptResearchAreas" .




