@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix vitro:   <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#> .
@prefix xsd:     <http://www.w3.org/2001/XMLSchema#> .
@prefix ts_:    <https://litvinovg.pro/text_structures#> .
@prefix display: <http://vitro.mannlib.cornell.edu/ontologies/display/1.1#> .

 
<https://iph.ras.ru/relationships#rubric> display:hasDataGetter display:getArticlesWithRubricDataGetter .

<https://iph.ras.ru/relationships#rubric> display:hasDataGetter display:getArticlesWithChildRubricDataGetter .

<https://iph.ras.ru/relationships#rubric> display:hasDataGetter display:getChildRubricsDataGetter .

<https://iph.ras.ru/relationships#rubric> display:hasDataGetter display:getExcerptsWithRubricDataGetter .

<https://iph.ras.ru/relationships#rubric> display:hasDataGetter display:getExcerptsWithRubricsChildsDataGetter .

display:getArticlesWithChildRubricDataGetter
    a <java:edu.cornell.mannlib.vitro.webapp.utils.dataGetter.SparqlQueryDataGetter>;
    display:saveToVar "childArticles";
    display:query
        """
        PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
        PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
        PREFIX ts_: <https://litvinovg.pro/text_structures#> 
        PREFIX pr: <https://iph.ras.ru/relationships#>
        SELECT DISTINCT ?childArticleID ?childArticleName
        WHERE {
          ?rubric (pr:hasParent)+ ?individualURI .
          ?excerpt pr:belongsTo ?rubric .
          ?excerpt rdf:type ts_:elenphExcerpt .
          ?childArticleID ts_:hasTOC ?toc .
          ?toc (ts_:hasTOCItem/ts_:pointsTo)+/ts_:hasText ?excerpt .
          ?childArticleID rdfs:label ?childArticleName .
          ?childArticleID rdf:type ts_:elenphArticle .
        } ORDER BY ?childArticleName
        """ .


display:getArticlesWithRubricDataGetter
    a <java:edu.cornell.mannlib.vitro.webapp.utils.dataGetter.SparqlQueryDataGetter>;
    display:saveToVar "articles";
    display:query
        """
        PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
        PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
        PREFIX ts_: <https://litvinovg.pro/text_structures#> 
        PREFIX pr: <https://iph.ras.ru/relationships#>
        SELECT DISTINCT ?articleID ?articleName
        WHERE {
          ?excerpt pr:belongsTo ?individualURI .
          ?excerpt rdf:type ts_:elenphExcerpt .
          ?articleID  ts_:hasTOC ?toc .
          ?toc (ts_:hasTOCItem/ts_:pointsTo)+/ts_:hasText ?excerpt .
          ?articleID rdfs:label ?articleName .
          ?articleID rdf:type ts_:elenphArticle .
        } ORDER BY ?articleName
        """ .

display:getChildRubricsDataGetter
    a <java:edu.cornell.mannlib.vitro.webapp.utils.dataGetter.SparqlQueryDataGetter>;
    display:saveToVar "childRubrics";
    display:query
        """
        PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
        PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
        PREFIX ts_: <https://litvinovg.pro/text_structures#> 
        PREFIX pr: <https://iph.ras.ru/relationships#>
        SELECT DISTINCT ?rubricID ?rubricName
        WHERE {
          ?rubricID pr:hasParent ?individualURI . 
          ?rubricID pr:rubricOrder ?order .
          ?rubricID rdfs:label ?rubricName .
          ?rubricID rdf:type pr:rubric .
        } ORDER BY ?order
        """ .

display:getExcerptsWithRubricsChildsDataGetter
    a <java:edu.cornell.mannlib.vitro.webapp.utils.dataGetter.SparqlQueryDataGetter>;
    display:saveToVar "childExcerpts";
    display:query
        """
        PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
        PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
        PREFIX ts_: <https://litvinovg.pro/text_structures#> 
        PREFIX pr: <https://iph.ras.ru/relationships#>
        SELECT DISTINCT ?childExcerptID ?childExcerptName
        WHERE {
          ?tmpChildRubrics (pr:hasParent)+ ?individualURI . 
          ?childExcerptID pr:belongsTo ?tmpChildRubrics .
          ?childExcerptID rdfs:label ?childExcerptName .
          ?childExcerptID rdf:type ts_:elenphExcerpt .
        } ORDER BY ?childExcerptName
        """ .

display:getExcerptsWithRubricDataGetter
    a <java:edu.cornell.mannlib.vitro.webapp.utils.dataGetter.SparqlQueryDataGetter>;
    display:saveToVar "excerpts";
    display:query
        """
        PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
        PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
        PREFIX ts_: <https://litvinovg.pro/text_structures#> 
        PREFIX pr: <https://iph.ras.ru/relationships#>
        SELECT DISTINCT ?excerptID ?excerptName
        WHERE {
          ?excerptID pr:belongsTo ?individualURI .
          ?excerptID rdfs:label ?excerptName .
          ?excerptID rdf:type ts_:elenphExcerpt .
        } ORDER BY ?excerptName
        """ .


