@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://litvinovg.pro/text_structures#elenphArticle> display:hasDataGetter display:getArticleExcerptsContentDataGetter .

<https://litvinovg.pro/text_structures#elenphArticle> display:hasDataGetter display:getArticleExcerptPathsDataGetter .

<https://litvinovg.pro/text_structures#elenphArticle> display:hasDataGetter display:getArticleWorksDataGetter .

<https://litvinovg.pro/text_structures#elenphArticle> display:hasDataGetter display:getArticleBibliographyDataGetter .

<https://litvinovg.pro/text_structures#elenphArticle> display:hasDataGetter display:getArticleAuthorsDataGetter .

<https://litvinovg.pro/text_structures#elenphArticle> display:hasDataGetter display:getArticleRubricsDataGetter .

display:getArticleExcerptsContentDataGetter
    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 ts_:  <https://litvinovg.pro/text_structures#> 
        SELECT ?elenphExcerpt ?property ?value
        WHERE {
              ?individualURI ts_:hasTOC ?toc .
              ?toc (ts_:hasTOCItem/ts_:pointsTo)+/ts_:hasText ?elenphExcerpt .
              ?elenphExcerpt ?property ?value .
        } ORDER BY ?elenphExcerpt
        """ .

display:getArticleExcerptPathsDataGetter
    a <java:edu.cornell.mannlib.vitro.webapp.utils.dataGetter.SparqlQueryDataGetter>;
    display:saveToVar "paths";
    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#> 
		SELECT (GROUP_CONCAT(substr(concat("000",str(?outline)),strlen(str(?outline))); SEPARATOR = ".") AS ?path ) ?tocElement ?elenphExcerpt
        WHERE { 
              ?individualURI ts_:hasTOC ?toc .
              ?toc ts_:hasTOCItem/(ts_:pointsTo/ts_:hasTOCItem)* ?tmpTOCItem .
              ?tmpTOCItem rdf:type ts_:TOCItem .
              ?tmpTOCItem ts_:pointsTo/(ts_:hasTOCItem/ts_:pointsTo)* ?tocElement .
              ?tmpTOCItem ts_:itemNumber ?outline .
              OPTIONAL {
                       ?tocElement ts_:hasText ?elenphExcerpt .
              }
              {
  	            SELECT ?elenphArticle ?tocElement
                WHERE {
    	              ?individualURI ts_:hasTOC ?toc .
                      ?toc (ts_:hasTOCItem/ts_:pointsTo)+ ?tocElement . 	
                      ?tocElement rdf:type ts_:TOCLevel .
                      ?individualURI rdf:type ts_:elenphArticle .
                }
              }
        } GROUP BY ?tocElement ?elenphExcerpt ORDER BY ?path
        """ .

display:getArticleBibliographyDataGetter
    a <java:edu.cornell.mannlib.vitro.webapp.utils.dataGetter.SparqlQueryDataGetter>;
    display:saveToVar "bibliography";
    display:query
        """
		PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
        PREFIX ts_:  <https://litvinovg.pro/text_structures#> 
        PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
        SELECT DISTINCT ?bibliography
        WHERE {
              ?individualURI ts_:hasTOC ?toc .
              ?toc (ts_:hasTOCItem/ts_:pointsTo)+/ts_:hasText ?elenphExcerpt .
              ?elenphExcerpt ts_:bibliography ?bibliography .
        } ORDER BY ?bibliography
        """ .

display:getArticleWorksDataGetter
    a <java:edu.cornell.mannlib.vitro.webapp.utils.dataGetter.SparqlQueryDataGetter>;
    display:saveToVar "works";
    display:query
        """
		PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
        PREFIX ts_:  <https://litvinovg.pro/text_structures#> 
        PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
        SELECT DISTINCT ?works
        WHERE {
              ?individualURI ts_:hasTOC ?toc .
              ?toc (ts_:hasTOCItem/ts_:pointsTo)+/ts_:hasText ?elenphExcerpt .
              ?elenphExcerpt ts_:works ?works .
        } ORDER BY ?works
        """ .

display:getArticleAuthorsDataGetter
    a <java:edu.cornell.mannlib.vitro.webapp.utils.dataGetter.SparqlQueryDataGetter>;
    display:saveToVar "authors";
    display:query
        """
		PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
		PREFIX ts_:  <https://litvinovg.pro/text_structures#> 
		PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
				SELECT DISTINCT ?author
				WHERE {
				      ?individualURI ts_:hasTOC ?toc .
                      ?toc (ts_:hasTOCItem/ts_:pointsTo)+/ts_:hasText ?elenphExcerpt .
				      ?elenphExcerpt ts_:author ?author .
		} ORDER BY ?author
        """ .

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


