@prefix : <http://data.sparna.fr/ontologies/sparnatural-config-datasources#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@base <http://data.sparna.fr/ontologies/sparnatural-config-datasources#> .

<http://data.sparna.fr/ontologies/sparnatural-config-datasources> rdf:type owl:Ontology ;
                                                                   owl:imports <http://data.sparna.fr/ontologies/sparnatural-config-core> .

#################################################################
#    Annotation properties
#################################################################

###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#childrenPath
:childrenPath rdf:type owl:AnnotationProperty ;
              rdfs:comment "The SPARQL property path where the children of resources can be read. This must be a valid SPARQL property path without any prefix, e.g. <http://schema.org> (including brackets)."@en ;
              rdfs:label "children path"@en .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#childrenProperty
:childrenProperty rdf:type owl:AnnotationProperty ;
                  rdfs:comment "The URI of a property where the children of resources can be read. This should point to a URI."@en ;
                  rdfs:label "children property"@en .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#datasource
:datasource rdf:type owl:AnnotationProperty ;
            rdfs:comment "The datasource from which a property with value selection should fetch its data."@en ;
            rdfs:label "datasource"@en ;
            rdfs:range :Datasource .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#labelPath
:labelPath rdf:type owl:AnnotationProperty ;
           rdfs:comment "The SPARQL property path where the label of resources can be read. This must be a valid SPARQL property path without any prefix, e.g. <http://schema.org> (including brackets)."@en ;
           rdfs:label "label path"@en ;
           rdfs:range xsd:string ;
           rdfs:domain :SparqlDatasource .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#labelProperty
:labelProperty rdf:type owl:AnnotationProperty ;
               rdfs:comment "The URI of a property where the label of resources can be read. This should point to a URI."@en ;
               rdfs:label "label property"@en ;
               rdfs:domain :SparqlDatasource .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#noSort
:noSort rdf:type owl:AnnotationProperty ;
        rdfs:comment "Set this to true to disable client-side javascript sorting for a datasource. If set to true, the order of elements will be the one returned by the SPARQL query."@en ;
        rdfs:label "no sort"@en ;
        rdfs:range xsd:boolean ;
        rdfs:domain :SparqlDatasource .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#treeChildrenDatasource
:treeChildrenDatasource rdf:type owl:AnnotationProperty ;
                        rdfs:comment "A reference to the datasource with which a tree widget will populate the children of a node in the tree."@en ;
                        rdfs:label "tree children datasource"@en ;
                        rdfs:subPropertyOf :datasource .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#treeRootsDatasource
:treeRootsDatasource rdf:type owl:AnnotationProperty ;
                     rdfs:comment "A reference to the datasource with which a tree widget will populate its root (first-level) nodes."@en ;
                     rdfs:label "tree roots datasource"@en ;
                     rdfs:subPropertyOf :datasource .


#################################################################
#    Object Properties
#################################################################

###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#queryTemplate
:queryTemplate rdf:type owl:ObjectProperty ;
               rdfs:domain :SparqlDatasource ;
               rdfs:range :SPARQLQuery ;
               rdfs:comment """The SPARQL query template to be used in a SPARQL datasource.

The SPARQL template holds a SPARQL query string in which the placeholders $domain, $property, $range will be replaced by their corresponding values before executing the query.

For autocomplete field, the additionnal placeholders $key and $lang will also be replaced by their corresponding values before executing the query

The placeholder $labelPath will be replaced by the value indicated in the SparqlDatasource in the labelPath (for a full SPARQL property path) or labelProperty (for a single property URI)."""@en ;
               rdfs:label "query template"@en .


#################################################################
#    Data properties
#################################################################

###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#queryString
:queryString rdf:type owl:DatatypeProperty ;
             rdfs:domain [ rdf:type owl:Class ;
                           owl:unionOf ( :SPARQLQuery
                                         :SparqlDatasource
                                       )
                         ] ;
             rdfs:range xsd:string ;
             rdfs:comment "The query string of a SPARQLQuery, or directly on a SPARQLDatasource"@en ;
             rdfs:label "query string"@en .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#sparqlEndpointUrl
:sparqlEndpointUrl rdf:type owl:DatatypeProperty ;
                   rdfs:domain :SparqlDatasource ;
                   rdfs:range xsd:anyURI ;
                   rdfs:comment "A SPARQL endpoint URL to which the query should be sent."@en ;
                   rdfs:label "SPARQL endpoint URL"@en .


#################################################################
#    Classes
#################################################################

###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#Datasource
:Datasource rdf:type owl:Class ;
            rdfs:comment "A source of data to populate Sparnatural widgets (list, search fields, trees, etc.)"@en ;
            rdfs:label "Datasource"@en .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#SPARQLQuery
:SPARQLQuery rdf:type owl:Class ;
             rdfs:comment "A SPARQL query, holding its query string"@en ;
             rdfs:label "SPARQL Query"@en .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#SparqlDatasource
:SparqlDatasource rdf:type owl:Class ;
                  rdfs:subClassOf :Datasource ;
                  rdfs:comment "A source of data for a Sparnatural widget implemented as a SPARQL query."@en ;
                  rdfs:label "SPARQL datasource"@en .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#SparqlListDatasource
:SparqlListDatasource rdf:type owl:Class ;
                      rdfs:subClassOf :SparqlDatasource ;
                      rdfs:comment """A datasource to populate a list widget, implemented as a SPARQL query.

The SPARQL query MUST return 2 variables : ?label and either ?uri or ?value (if returning a literal). It can return other variables as well.

The following variables, if present in the SPARQL query, are automatically bound in the query :
  - $domain: bound to the URI of the subject class of the criteria
  - $property: bound to the URI or property path of the property of the criteria
  - $range: bound to the URI of the object class of the criteria
  - $lang: bound to the default language of Sparnatural
  - $type: bound to the typePredicate parameter of Sparnatural, rdf:type by default"""@en ;
                      rdfs:label "SPARQL list datasource"@en .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#SparqlSearchDatasource
:SparqlSearchDatasource rdf:type owl:Class ;
                        rdfs:subClassOf :SparqlDatasource ;
                        rdfs:comment """A datasource to populate an autocomplete search widget, implemented as a SPARQL query.

The SPARQL query MUST return 2 variables : ?label and either ?uri or ?value (if returning a literal). It can return other variables as well;

The following variables, if present in the SPARQL query, are automatically bound in the query :
  - $domain: bound to the URI of the subject class of the criteria
  - $property: bound to the URI or property path of the property of the criteria
  - $range: bound to the URI of the object class of the criteria
  - $lang: bound to the default language of Sparnatural
  - $key: the characters entered by the user in the search field
  - $type: bound to the typePredicate parameter of Sparnatural, rdf:type by default"""@en ;
                        rdfs:label "SPARQL search datasource"@en .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#SparqlTreeChildrenDatasource
:SparqlTreeChildrenDatasource rdf:type owl:Class ;
                              rdfs:subClassOf :SparqlDatasource ;
                              rdfs:comment """A datasource to populate the children of a node of a tree widget, when unfolded, implemented as a SPARQL query.

The query MUST return the following variables:
  - ?uri
  - ?label
  - ?hasChildren: a boolean indicating if the node has some children

In addition the query CAN return the following variables:
  - ?count: the number of times this entity is used as the value of the criteria"""@en ;
                              rdfs:label "SPARQL tree datasource for children of a node"@en .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#SparqlTreeRootDatasource
:SparqlTreeRootDatasource rdf:type owl:Class ;
                          rdfs:subClassOf :SparqlDatasource ;
                          rdfs:comment "A datasource to populate the root of a tree widget, implemented as a SPARQL query."@en ;
                          rdfs:label "SPARQL tree datasource for the roots of the tree"@en .


#################################################################
#    Individuals
#################################################################

###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#list_URI_alpha
:list_URI_alpha rdf:type owl:NamedIndividual ,
                         :SparqlListDatasource ;
                :queryTemplate :query_list_URI_alpha ;
                rdfs:comment "A datasource that returns a list of entities with their URI as a label ordered alphabetically based on the URI string."@en .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#list_URI_count
:list_URI_count rdf:type owl:NamedIndividual ,
                         :SparqlListDatasource ;
                :queryTemplate :query_list_URI_count ;
                :noSort "true"^^xsd:boolean ;
                rdfs:comment """A datasource that returns a list of entities with their URI as a label ordered by the descending number of times the entity is used as a value.

This is typically the default behavior for a list without a datasource specified."""@en .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#list_URI_or_literal_alpha
:list_URI_or_literal_alpha rdf:type owl:NamedIndividual ,
                                    :SparqlListDatasource ;
                           :queryTemplate :query_list_URI_or_literal_alpha ;
                           rdfs:comment "A datasource that returns a list of URI or Literals, ordered alphabetically based on their string representation. It can work indifferently with URIs or Literal values."@en .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#list_URI_or_literal_alpha_with_count
:list_URI_or_literal_alpha_with_count rdf:type owl:NamedIndividual ,
                                               :SparqlListDatasource ;
                                      :queryTemplate :query_list_URI_or_literal_alpha_with_count ;
                                      rdfs:comment "A datasource that returns a list of URIs or Literals, ordered alphabetically based on their string representation, with their number of occurrences in parenthesis."@en .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#list_URI_or_literal_count
:list_URI_or_literal_count rdf:type owl:NamedIndividual ,
                                    :SparqlListDatasource ;
                           :queryTemplate :query_list_URI_or_literal_count ;
                           rdfs:comment "A datasource that returns a list of URI or Literals, ordered on their descending number of occurrences. It can work indifferently with URIs or Literal values."@en .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#list_dctermstitle_alpha
:list_dctermstitle_alpha rdf:type owl:NamedIndividual ,
                                  :SparqlListDatasource ;
                         :queryTemplate :query_list_label_alpha ;
                         :labelProperty <http://purl.org/dc/terms/title> ;
                         rdfs:comment "A datasource that returns a list of entities with their dcterms:title ordered alphabetically based on this property."@en .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#list_dctermstitle_alpha_with_count
:list_dctermstitle_alpha_with_count rdf:type owl:NamedIndividual ,
                                             :SparqlListDatasource ;
                                    :queryTemplate :query_list_label_alpha_with_count ;
                                    rdfs:comment "A datasource that returns a list of entities with their dcterms:title and the number of occurrences of the entity in parenthesis, ordered alphabetically based on this property."@en .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#list_dctermstitle_count
:list_dctermstitle_count rdf:type owl:NamedIndividual ,
                                  :SparqlListDatasource ;
                         :queryTemplate :query_list_label_count ;
                         :labelProperty <http://purl.org/dc/terms/title> ;
                         :noSort "true"^^xsd:boolean ;
                         rdfs:comment "A datasource that returns a list of entities with their dcterms:title ordered by the descending number of times the entity is used as a value."@en .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#list_foafname_alpha
:list_foafname_alpha rdf:type owl:NamedIndividual ,
                              :SparqlListDatasource ;
                     :queryTemplate :query_list_label_alpha ;
                     :labelProperty <http://xmlns.com/foaf/0.1/name> ;
                     rdfs:comment "A datasource that returns a list of entities with their foaf:name ordered alphabetically based on this property."@en .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#list_foafname_alpha_with_count
:list_foafname_alpha_with_count rdf:type owl:NamedIndividual ,
                                         :SparqlListDatasource ;
                                :queryTemplate :query_list_label_alpha_with_count ;
                                :labelProperty <http://xmlns.com/foaf/0.1/name> ;
                                rdfs:comment "A datasource that returns a list of entities with their foaf:name and the number of occurrences of the entity in parenthesis, ordered alphabetically based on this property."@en .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#list_foafname_count
:list_foafname_count rdf:type owl:NamedIndividual ,
                              :SparqlListDatasource ;
                     :queryTemplate :query_list_label_count ;
                     :labelProperty <http://xmlns.com/foaf/0.1/name> ;
                     :noSort "true"^^xsd:boolean ;
                     rdfs:comment "A datasource that returns a list of entities with their foaf:name ordered by the descending number of times the entity is used as a value."@en .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#list_rdfslabel_alpha
:list_rdfslabel_alpha rdf:type owl:NamedIndividual ,
                               :SparqlListDatasource ;
                      :queryTemplate :query_list_label_alpha ;
                      :labelProperty rdfs:label ;
                      rdfs:comment "A datasource that returns a list of entities with their rdfs:label ordered alphabetically based on this property."@en .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#list_rdfslabel_alpha_with_count
:list_rdfslabel_alpha_with_count rdf:type owl:NamedIndividual ,
                                          :SparqlListDatasource ;
                                 :queryTemplate :query_list_label_alpha_with_count ;
                                 :labelProperty rdfs:label ;
                                 rdfs:comment "A datasource that returns a list of entities with their rdfs:label and the number of occurrences of the entity in parenthesis, ordered alphabetically based on this property."@en .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#list_rdfslabel_count
:list_rdfslabel_count rdf:type owl:NamedIndividual ,
                               :SparqlListDatasource ;
                      :queryTemplate :query_list_label_count ;
                      :labelProperty rdfs:label ;
                      :noSort "true"^^xsd:boolean ;
                      rdfs:comment "A datasource that returns a list of entities with their rdfs:label ordered by the descending number of times the entity is used as a value."@en .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#list_schemaname_alpha
:list_schemaname_alpha rdf:type owl:NamedIndividual ,
                                :SparqlListDatasource ;
                       :queryTemplate :query_list_label_alpha ;
                       :labelProperty <http://schema.org/name> ;
                       rdfs:comment "A datasource that returns a list of entities with their schema:name ordered alphabetically based on this property."@en .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#list_schemaname_alpha_with_count
:list_schemaname_alpha_with_count rdf:type owl:NamedIndividual ,
                                           :SparqlListDatasource ;
                                  :queryTemplate :query_list_label_alpha_with_count ;
                                  rdfs:comment "A datasource that returns a list of entities with their schema:name and the number of occurrences of the entity in parenthesis, ordered alphabetically based on this property."@en .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#list_schemaname_count
:list_schemaname_count rdf:type owl:NamedIndividual ,
                                :SparqlListDatasource ;
                       :queryTemplate :query_list_label_count ;
                       :labelProperty <http://schema.org/name> ;
                       :noSort "true"^^xsd:boolean ;
                       rdfs:comment "A datasource that returns a list of entities with their schema:name ordered by the descending number of times the entity is used as a value."@en .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#list_skospreflabel_alpha
:list_skospreflabel_alpha rdf:type owl:NamedIndividual ,
                                   :SparqlListDatasource ;
                          :queryTemplate :query_list_label_alpha ;
                          :labelProperty <http://www.w3.org/2004/02/skos/core#prefLabel> ;
                          rdfs:comment "A datasource that returns a list of entities with their skos:prefLabel ordered alphabetically based on this property."@en .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#list_skospreflabel_alpha_with_count
:list_skospreflabel_alpha_with_count rdf:type owl:NamedIndividual ,
                                              :SparqlListDatasource ;
                                     :queryTemplate :query_list_label_alpha_with_count ;
                                     :labelProperty <http://www.w3.org/2004/02/skos/core#prefLabel> ;
                                     rdfs:comment "A datasource that returns a list of entities with their skos:prefLabel and the number of occurrences of the entity in parenthesis, ordered alphabetically based on this property."@en .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#list_skospreflabel_count
:list_skospreflabel_count rdf:type owl:NamedIndividual ,
                                   :SparqlListDatasource ;
                          :queryTemplate :query_list_label_count ;
                          :labelProperty <http://www.w3.org/2004/02/skos/core#prefLabel> ;
                          :noSort "true"^^xsd:boolean ;
                          rdfs:comment "A datasource that returns a list of entities with their skos:prefLabel ordered by the descending number of times the entity is used as a value."@en .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#literal_list_alpha
:literal_list_alpha rdf:type owl:NamedIndividual ,
                             :SparqlListDatasource ;
                    :queryTemplate :query_literal_list_alpha ;
                    rdfs:comment "A datasource that returns a list of literal ordered alphabetically."@en .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#literal_list_alpha_with_count
:literal_list_alpha_with_count rdf:type owl:NamedIndividual ,
                                        :SparqlListDatasource ;
                               :queryTemplate :query_literal_list_alpha_with_count ;
                               rdfs:comment "A datasource that returns a list of literal with count in parenthesis, ordered alphabetically."@en .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#literal_list_count
:literal_list_count rdf:type owl:NamedIndividual ,
                             :SparqlListDatasource ;
                    :queryTemplate :query_literal_list_count ;
                    :noSort "true"^^xsd:boolean ;
                    rdfs:comment "A datasource that returns a list of literal ordered by descending number of occurrences."@en .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#query_list_URI_alpha
:query_list_URI_alpha rdf:type owl:NamedIndividual ,
                               :SPARQLQuery ;
                      :queryString """SELECT DISTINCT ?uri (STR(?uri) AS ?label)
WHERE {
    ?domain $type $domain .
    ?domain $property ?uri .
    FILTER(isIRI(?uri))
    # Note how the range criteria is not used in this query
}
ORDER BY UCASE(STR(?label))
LIMIT 500""" .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#query_list_URI_count
:query_list_URI_count rdf:type owl:NamedIndividual ,
                               :SPARQLQuery ;
                      :queryString """SELECT ?uri ?count (CONCAT(STR(?uri), ' (', STR(?count), ')') AS ?label) (STR(?uri) AS ?itemLabel)
WHERE {
{
  SELECT DISTINCT ?uri (COUNT(?domain) AS ?count)
  WHERE {
    ?domain $type $domain .
    ?domain $property ?uri .
    FILTER(isIRI(?uri))
    # Note how the range criteria is not used in this query
  }
  GROUP BY ?uri
}
}
ORDER BY DESC(?count) UCASE(STR(?label))
LIMIT 500""" .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#query_list_URI_or_literal_alpha
:query_list_URI_or_literal_alpha rdf:type owl:NamedIndividual ,
                                          :SPARQLQuery ;
                                 :queryString """SELECT DISTINCT ?value (CONCAT(IF(isLiteral(?value) && LANG(?value) != '' && LANG(?value) != $lang,CONCAT(STR(?value), \" <sup>(\",LANG(?value),\")</sup>\"),STR(?value))) AS ?label)
WHERE {
    ?domain $type $domain .
    {
      {
        ?domain $property ?value . FILTER(isIRI(?value))
      }
      UNION
      {
        ?domain $property ?value . 
        FILTER(isLiteral(?value) && (lang(?value) = $lang))
      }
      UNION
      {
        ?domain $property ?value . 
        FILTER(isLiteral(?value) && (lang(?value) = $defaultLang))
        FILTER NOT EXISTS {
          ?domain $property ?valuePrefLang .
          FILTER(LANG(?valuePrefLang) = $lang)
        }
      }
      UNION
      {
        ?domain $property ?value . 
        FILTER(isLiteral(?value) && (lang(?value) = \"\"))
        FILTER NOT EXISTS {
          ?domain $property ?valueAnyLang .
          FILTER((LANG(?valueAnyLang) = $lang) || (LANG(?valueAnyLang) = $defaultLang))
        }
      }
    }
    # Note how the range criteria is not used in this query
}
ORDER BY UCASE(STR(?label))
LIMIT 500""" .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#query_list_URI_or_literal_alpha_with_count
:query_list_URI_or_literal_alpha_with_count rdf:type owl:NamedIndividual ,
                                                     :SPARQLQuery ;
                                            :queryString """SELECT DISTINCT ?value ?count (CONCAT(IF(isLiteral(?value) && LANG(?value) != '' && LANG(?value) != $lang,CONCAT(STR(?value), \" <sup>(\",LANG(?value),\")</sup>\"),STR(?value)), ' (', STR(?count), ')') AS ?label) (STR(?value) AS ?itemLabel)
WHERE {
{
  SELECT DISTINCT ?value (COUNT(DISTINCT ?domain) AS ?count)
  WHERE {
    ?domain $type $domain .
    {
      {
        ?domain $property ?value . FILTER(isIRI(?value))
      }
      UNION
      {
        ?domain $property ?value . 
        FILTER(isLiteral(?value) && (lang(?value) = $lang))
      }
      UNION
      {
        ?domain $property ?value . 
        FILTER(isLiteral(?value) && (lang(?value) = $defaultLang))
        FILTER NOT EXISTS {
          ?domain $property ?valuePrefLang .
          FILTER(LANG(?valuePrefLang) = $lang)
        }
      }
      UNION
      {
        ?domain $property ?value . 
        FILTER(isLiteral(?value) && (lang(?value) = \"\"))
        FILTER NOT EXISTS {
          ?domain $property ?valueAnyLang .
          FILTER((LANG(?valueAnyLang) = $lang) || (LANG(?valueAnyLang) = $defaultLang))
        }
      }      
    }
  }
  GROUP BY ?value
}
}
ORDER BY UCASE(STR(?label))
LIMIT 500""" .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#query_list_URI_or_literal_count
:query_list_URI_or_literal_count rdf:type owl:NamedIndividual ,
                                          :SPARQLQuery ;
                                 :queryString """SELECT ?value ?count (CONCAT(IF(isLiteral(?value) && LANG(?value) != '' && LANG(?value) != $lang,CONCAT(STR(?value), \" <sup>(\",LANG(?value),\")</sup>\"),STR(?value)), ' (', STR(?count), ')') AS ?label) (STR(?value) AS ?itemLabel)
WHERE {
{
  SELECT DISTINCT ?value (COUNT(DISTINCT ?domain) AS ?count)
  WHERE {
    ?domain $type $domain .
    {
      {
        ?domain $property ?value . FILTER(isIRI(?value))
      }
      UNION
      {
        ?domain $property ?value . 
        FILTER(isLiteral(?value) && (lang(?value) = $lang))
      }
      UNION
      {
        ?domain $property ?value . 
        FILTER(isLiteral(?value) && (lang(?value) = $defaultLang))
        FILTER NOT EXISTS {
          ?domain $property ?valuePrefLang .
          FILTER(LANG(?valuePrefLang) = $lang)
        }
      }
      UNION
      {
        ?domain $property ?value . 
        FILTER(isLiteral(?value) && (lang(?value) = \"\"))
        FILTER NOT EXISTS {
          ?domain $property ?valueAnyLang .
          FILTER((LANG(?valueAnyLang) = $lang) || (LANG(?valueAnyLang) = $defaultLang))
        }
      }      
    }
  }
  GROUP BY ?value
}
}
ORDER BY DESC(?count) UCASE(STR(?label))
LIMIT 500""" ;
                                 :noSort "true"^^xsd:boolean .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#query_list_label_alpha
:query_list_label_alpha rdf:type owl:NamedIndividual ,
                                 :SPARQLQuery ;
                        :queryString """SELECT DISTINCT ?uri ?label
WHERE {
    ?domain $type $domain .
    ?domain $property ?uri .
    # Note how the range criteria is not used in this query
    ?uri $labelPath ?label .
    FILTER(isIRI(?uri))
    FILTER(lang(?label) = \"\" || lang(?label) = $lang)
}
ORDER BY UCASE(STR(?label))
LIMIT 500""" .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#query_list_label_alpha_with_count
:query_list_label_alpha_with_count rdf:type owl:NamedIndividual ,
                                            :SPARQLQuery ;
                                   :queryString """SELECT ?uri ?count (CONCAT(STR(?theLabel), ' (', STR(?count), ')') AS ?label) (STR(?theLabel) AS ?itemLabel)
WHERE {
  {
  SELECT ?uri ?count ?theLabel
  WHERE {
  {
    SELECT DISTINCT ?uri (COUNT(?domain) AS ?count)
    WHERE {
      ?domain $type $domain .
      ?domain $property ?uri .
      FILTER(isIRI(?uri))
    }
    GROUP BY ?uri
  }
  ?uri $labelPath ?theLabel .
  FILTER(lang(?theLabel) = \"\" || lang(?theLabel) = $lang)
  }
  ORDER BY UCASE(?theLabel)
  LIMIT 500
  }
}
ORDER BY UCASE(STR(?label))""" .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#query_list_label_count
:query_list_label_count rdf:type owl:NamedIndividual ,
                                 :SPARQLQuery ;
                        :queryString """SELECT ?uri ?count (CONCAT(STR(?theLabel), ' (', STR(?count), ')') AS ?label) (STR(?theLabel) AS ?itemLabel)
WHERE {
  {
  SELECT ?uri ?count ?theLabel
  WHERE {
  {
    SELECT DISTINCT ?uri (COUNT(?domain) AS ?count)
    WHERE {
      ?domain $type $domain .
      ?domain $property ?uri .
      FILTER(isIRI(?uri))
    }
    GROUP BY ?uri
  }
  ?uri $labelPath ?theLabel .
  FILTER(lang(?theLabel) = \"\" || lang(?theLabel) = $lang)
  }
  ORDER BY DESC(?count) UCASE(?theLabel)
  LIMIT 500
  }
}
ORDER BY DESC(?count) UCASE(STR(?label))""" .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#query_list_label_with_range_alpha
:query_list_label_with_range_alpha rdf:type owl:NamedIndividual ,
                                            :SPARQLQuery ;
                                   :queryString """SELECT DISTINCT ?uri ?label
WHERE {
    ?domain $type $domain .
    ?domain $property ?uri .
    # range criteria
    ?uri $type $range .
    ?uri $labelPath ?label .
    FILTER(isIRI(?uri))
    FILTER(lang(?label) = \"\" || lang(?label) = $lang)
}
ORDER BY UCASE(STR(?label))
LIMIT 500""" .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#query_list_label_with_range_alpha_with_count
:query_list_label_with_range_alpha_with_count rdf:type owl:NamedIndividual ,
                                                       :SPARQLQuery ;
                                              :queryString """SELECT ?uri ?count (CONCAT(STR(?theLabel), ' (', STR(?count), ')') AS ?label) (STR(?theLabel) AS ?itemLabel)
WHERE {
  {
  SELECT ?uri ?count ?theLabel
  WHERE {
  {
    SELECT DISTINCT ?uri (COUNT(?domain) AS ?count)
    WHERE {
      ?domain $type $domain .
      ?domain $property ?uri .
      FILTER(isIRI(?uri))
      # range criteria
      ?uri $type $range .
    }
    GROUP BY ?uri
  }
  ?uri $labelPath ?theLabel .
  FILTER(lang(?theLabel) = \"\" || lang(?theLabel) = $lang)
  }
  ORDER BY UCASE(?theLabel)
  LIMIT 500
  }
}
ORDER BY UCASE(STR(?label))""" .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#query_list_label_with_range_count
:query_list_label_with_range_count rdf:type owl:NamedIndividual ,
                                            :SPARQLQuery ;
                                   :queryString """SELECT ?uri ?count (CONCAT(STR(?theLabel), ' (', STR(?count), ')') AS ?label) (STR(?theLabel) AS ?itemLabel)
WHERE {
  {
  SELECT ?uri ?count ?theLabel
  WHERE {
  {
    SELECT DISTINCT ?uri (COUNT(?domain) AS ?count)
    WHERE {
      ?domain $type $domain .
      ?domain $property ?uri .
      FILTER(isIRI(?uri))
      ?uri $type $range .
    }
    GROUP BY ?uri
  }
  ?uri $labelPath ?theLabel .
  FILTER(lang(?theLabel) = \"\" || lang(?theLabel) = $lang)
  }
  ORDER BY DESC(?count) UCASE(?theLabel)
  LIMIT 500
  }
}
ORDER BY DESC(?count) UCASE(STR(?label))""" .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#query_literal_list_alpha
:query_literal_list_alpha rdf:type owl:NamedIndividual ,
                                   :SPARQLQuery ;
                          :queryString """SELECT DISTINCT ?value (STR(?value) AS ?label)
WHERE {
    ?domain $type $domain .
    ?domain $property ?value .
}
ORDER BY UCASE(STR(?label))
LIMIT 500""" .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#query_literal_list_alpha_with_count
:query_literal_list_alpha_with_count rdf:type owl:NamedIndividual ,
                                              :SPARQLQuery ;
                                     :queryString """SELECT ?count (CONCAT(STR(?theLabel), ' (', STR(?count), ')') AS ?label) (STR(?theLabel) AS ?itemLabel)
WHERE {
  {
  SELECT DISTINCT ?count ?theLabel
  WHERE {
  {
    SELECT DISTINCT ?theLabel (COUNT(?theLabel) AS ?count)
    WHERE {
      ?domain $type $domain .
      ?domain $property ?theLabel .
      FILTER(lang(?theLabel) = \"\" || lang(?theLabel) = $lang)
    }
    GROUP BY ?theLabel
  }
  }
  ORDER BY UCASE(?theLabel)
  LIMIT 500
  }
}
ORDER BY UCASE(STR(?label))""" .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#query_literal_list_count
:query_literal_list_count rdf:type owl:NamedIndividual ,
                                   :SPARQLQuery ;
                          :queryString """SELECT ?count (CONCAT(STR(?theLabel), ' (', STR(?count), ')') AS ?label) (STR(?theLabel) AS ?itemLabel)
WHERE {
  {
  SELECT DISTINCT ?count ?theLabel
  WHERE {
  {
    SELECT DISTINCT ?theLabel (COUNT(?theLabel) AS ?count)
    WHERE {
      ?domain $type $domain .
      ?domain $property ?theLabel .
      FILTER(lang(?theLabel) = \"\" || lang(?theLabel) = $lang)
    }
    GROUP BY ?theLabel
  }
  }
  ORDER BY DESC(?count) UCASE(?theLabel)
  LIMIT 500
  }
}
ORDER BY DESC(?count) UCASE(STR(?label))""" .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#query_search_URI_contains
:query_search_URI_contains rdf:type owl:NamedIndividual ,
                                    :SPARQLQuery ;
                           :queryString """SELECT DISTINCT ?uri ?label
WHERE {
  ?domain $type $domain .
  ?domain $property ?uri .
  ?uri $type $range .
  FILTER(isIRI(?uri))
  BIND(STR(?uri) AS ?label)
  FILTER(CONTAINS(LCASE(?label), LCASE(\"$key\"))) 
} 
ORDER BY UCASE(STR(?label))
LIMIT 15""" .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#query_search_label_bifcontains
:query_search_label_bifcontains rdf:type owl:NamedIndividual ,
                                         :SPARQLQuery ;
                                :queryString """PREFIX bif: <http://www.openlinksw.com/schemas/bif#>
SELECT DISTINCT ?uri ?label
 WHERE {
  ?domain $type $domain .
  ?domain $property ?uri .
  ?uri $type $range .
  ?uri $labelPath ?label .
  FILTER(isIRI(?uri))
  FILTER(lang(?label) = '' || lang(?label) = $lang )
  # Note the single quote to handle space character
  ?label bif:contains \"'$key'\" . 
} 
ORDER BY UCASE(STR(?label))
LIMIT 15""" .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#query_search_label_contains
:query_search_label_contains rdf:type owl:NamedIndividual ,
                                      :SPARQLQuery ;
                             :queryString """SELECT DISTINCT ?uri ?label
WHERE {
  ?domain $type $domain .
  ?domain $property ?uri .
  ?uri $type $range .
  ?uri $labelPath ?label .
  FILTER(isIRI(?uri))
  FILTER(lang(?label) = '' || lang(?label) = $lang)
  FILTER(CONTAINS(LCASE(STR(?label)), LCASE(\"$key\"))) 
  BIND( IF( STRSTARTS(LCASE(STR(?label)), LCASE(\"$key\")),0,9 ) AS ?starts )
} 
ORDER BY UCASE(STR(?label))
LIMIT 15""" .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#query_search_label_strstarts
:query_search_label_strstarts rdf:type owl:NamedIndividual ,
                                       :SPARQLQuery ;
                              :queryString """SELECT DISTINCT ?uri ?label
WHERE {
  ?domain $type $domain .
  ?domain $property ?uri .
  ?uri $type $range .
  ?uri $labelPath ?label .
  FILTER(isIRI(?uri))
  FILTER(lang(?label) = '' || lang(?label) = $lang)
  FILTER(STRSTARTS(LCASE(STR(?label)), LCASE(\"$key\"))) 
} 
ORDER BY UCASE(STR(?label))
LIMIT 15""" .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#query_search_literal_contains
:query_search_literal_contains rdf:type owl:NamedIndividual ,
                                        :SPARQLQuery ;
                               :queryString """SELECT DISTINCT ?value ?label
WHERE {
  ?domain $type $domain .
  ?domain $property ?value .
  FILTER(isLiteral(?value))
  BIND(STR(?value) AS ?label)
  FILTER(CONTAINS(LCASE(STR(?value)), LCASE(\"$key\"))) 
} 
ORDER BY UCASE(STR(?label))
LIMIT 15""" .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#query_search_literal_strstarts
:query_search_literal_strstarts rdf:type owl:NamedIndividual ,
                                         :SPARQLQuery ;
                                :queryString """SELECT DISTINCT ?value ?label
WHERE {
  ?domain $type $domain .
  ?domain $property ?value .
  FILTER(isLiteral(?value))
  BIND(STR(?value) AS ?label)
  FILTER(STRSTARTS(LCASE(STR(?value)), LCASE(\"$key\"))) 
} 
ORDER BY UCASE(STR(?label))
LIMIT 15""" .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#query_tree_children
:query_tree_children rdf:type owl:NamedIndividual ,
                              :SPARQLQuery ;
                     :queryString """# Selects the children of a node
SELECT DISTINCT ?uri ?label ?hasChildren
WHERE {
  $node $childrenPath ?uri .
  ?uri $labelPath ?label .
  FILTER(isIRI(?uri))
  FILTER(lang(?label) = '' || lang(?label) = $lang)
  OPTIONAL {
  	?uri $childrenPath ?children .
  }
  BIND(IF(bound(?children),true,false) AS ?hasChildren)
}
ORDER BY UCASE(STR(?label))""" .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#query_tree_children_with_count
:query_tree_children_with_count rdf:type owl:NamedIndividual ,
                                         :SPARQLQuery ;
                                :queryString """SELECT ?uri (CONCAT(STR(?theLabel), ' (', STR(?count), ')') AS ?label) ?hasChildren ?count (STR(?theLabel) AS ?itemLabel)
WHERE {
  {
  SELECT DISTINCT ?uri ?theLabel ?hasChildren (COUNT(?x) AS ?count)
  WHERE {
    {
      SELECT ?uri ?theLabel ?hasChildren
      WHERE {
        $node $childrenPath ?uri .
        ?uri $labelPath ?theLabel .
        FILTER(isIRI(?uri))
        FILTER(lang(?theLabel) = '' || lang(?theLabel) = $lang)
        OPTIONAL {
          ?uri $childrenPath ?children .
        }
        BIND(IF(bound(?children),true,false) AS ?hasChildren)
      }
    }

    OPTIONAL {
      ?x $type $domain .
      ?x $property ?uri .
      # no range criteria
      # ?uri a $range .
    }
  }
  GROUP BY ?uri ?theLabel ?hasChildren
  }
}
ORDER BY UCASE(STR(?label))""" .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#query_tree_root_noparent
:query_tree_root_noparent rdf:type owl:NamedIndividual ,
                                   :SPARQLQuery ;
                          :queryString """SELECT ?uri ?label ?hasChildren
WHERE {
  ?uri $type $range .
  FILTER NOT EXISTS {
    ?parent $childrenPath ?uri .
  }
  ?uri $labelPath ?label .
  FILTER(isIRI(?uri))
  FILTER(lang(?label) = '' || lang(?label) = $lang)
  OPTIONAL {
    ?uri $childrenPath ?children .
  }
  BIND(IF(bound(?children),true,false) AS ?hasChildren)
}
ORDER BY UCASE(STR(?label))""" .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#query_tree_root_noparent_with_count
:query_tree_root_noparent_with_count rdf:type owl:NamedIndividual ,
                                              :SPARQLQuery ;
                                     :queryString """SELECT ?uri (CONCAT(STR(?theLabel), ' (', STR(?count), ')') AS ?label) ?hasChildren ?count (STR(?theLabel) AS ?itemLabel)
WHERE {
  {
  SELECT ?uri ?theLabel ?hasChildren (COUNT(?x) AS ?count)
  WHERE {
    {
      SELECT ?uri ?theLabel ?hasChildren
      WHERE {
        ?uri $type $range .
        FILTER NOT EXISTS {
          ?parent $childrenPath ?uri .
        }
        ?uri $labelPath ?theLabel .
        FILTER(isIRI(?uri))
        FILTER(lang(?theLabel) = '' || lang(?theLabel) = $lang)
        OPTIONAL {
          ?uri $childrenPath ?children .
        }
        BIND(IF(bound(?children),true,false) AS ?hasChildren)
      }
    }

    OPTIONAL {
      ?x $type $domain .
      ?x $property ?uri .
    }
  }
  GROUP BY ?uri ?theLabel ?hasChildren
  }
} 
ORDER BY UCASE(STR(?label))""" .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#search_URI_contains
:search_URI_contains rdf:type owl:NamedIndividual ,
                              :SparqlSearchDatasource ;
                     :queryTemplate :query_search_URI_contains ;
                     rdfs:comment "Searches for entities by looking up the provided $key in their URI string using the CONTAINS SPARQL function."@en .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#search_dctermstitle_bifcontains
:search_dctermstitle_bifcontains rdf:type owl:NamedIndividual ,
                                          :SparqlSearchDatasource ;
                                 :queryTemplate :query_search_label_bifcontains ;
                                 :labelProperty <http://purl.org/dc/terms/title> ;
                                 rdfs:comment "Searches for entities by looking up the provided $key inside their dcterms:title using the bif:contains Virtuoso function."@en .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#search_dctermstitle_contains
:search_dctermstitle_contains rdf:type owl:NamedIndividual ,
                                       :SparqlSearchDatasource ;
                              :queryTemplate :query_search_label_contains ;
                              :labelProperty <http://purl.org/dc/terms/title> ;
                              rdfs:comment "Searches for entities by looking up the provided $key inside their dcterms:title using the CONTAINS SPARQL function."@en .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#search_dctermstitle_strstarts
:search_dctermstitle_strstarts rdf:type owl:NamedIndividual ,
                                        :SparqlSearchDatasource ;
                               :queryTemplate :query_search_label_strstarts ;
                               :labelProperty <http://purl.org/dc/terms/title> ;
                               rdfs:comment "Searches for entities by looking up the provided $key at the beginning of their dcterms;title using the STRSTARTS SPARQL function."@en .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#search_foafname_bifcontains
:search_foafname_bifcontains rdf:type owl:NamedIndividual ,
                                      :SparqlSearchDatasource ;
                             :queryTemplate :query_search_label_bifcontains ;
                             :labelProperty <http://xmlns.com/foaf/0.1/name> ;
                             rdfs:comment "Searches for entities by looking up the provided $key inside their foaf:name using the bif:contains Virtuoso function."@en .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#search_foafname_contains
:search_foafname_contains rdf:type owl:NamedIndividual ,
                                   :SparqlSearchDatasource ;
                          :queryTemplate :query_search_label_contains ;
                          :labelProperty <http://xmlns.com/foaf/0.1/name> ;
                          rdfs:comment "Searches for entities by looking up the provided $key inside their foaf:name using the CONTAINS SPARQL function."@en .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#search_foafname_strstarts
:search_foafname_strstarts rdf:type owl:NamedIndividual ,
                                    :SparqlSearchDatasource ;
                           :queryTemplate :query_search_label_strstarts ;
                           :labelProperty <http://xmlns.com/foaf/0.1/name> ;
                           rdfs:comment "Searches for entities by looking up the provided $key at the beginning of their foaf:name using the STRSTARTS SPARQL function."@en .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#search_literal_contains
:search_literal_contains rdf:type owl:NamedIndividual ,
                                  :SparqlSearchDatasource ;
                         :queryTemplate :query_search_literal_contains .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#search_literal_strstarts
:search_literal_strstarts rdf:type owl:NamedIndividual ,
                                   :SparqlSearchDatasource ;
                          :queryTemplate :query_search_literal_strstarts .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#search_rdfslabel_bifcontains
:search_rdfslabel_bifcontains rdf:type owl:NamedIndividual ,
                                       :SparqlSearchDatasource ;
                              :queryTemplate :query_search_label_bifcontains ;
                              :labelProperty rdfs:label ;
                              rdfs:comment "Searches for entities by looking up the provided $key inside their rdfs:label using the bif:contains Virtuoso function."@en .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#search_rdfslabel_contains
:search_rdfslabel_contains rdf:type owl:NamedIndividual ,
                                    :SparqlSearchDatasource ;
                           :queryTemplate :query_search_label_contains ;
                           :labelProperty rdfs:label ;
                           rdfs:comment "Searches for entities by looking up the provided $key inside their rdfs:label using the CONTAINS SPARQL function."@en .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#search_rdfslabel_strstarts
:search_rdfslabel_strstarts rdf:type owl:NamedIndividual ,
                                     :SparqlSearchDatasource ;
                            :queryTemplate :query_search_label_strstarts ;
                            :labelProperty rdfs:label ;
                            rdfs:comment "Searches for entities by looking up the provided $key at the beginning of their rdfs:label using the STRSTARTS SPARQL function."@en .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#search_schemaname_bifcontains
:search_schemaname_bifcontains rdf:type owl:NamedIndividual ,
                                        :SparqlSearchDatasource ;
                               :queryTemplate :query_search_label_bifcontains ;
                               :labelPath <http://schema.org/name> ;
                               rdfs:comment "Searches for entities by looking up the provided $key inside their schema:name using the bif:contains Virtuoso function."@en .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#search_schemaname_contains
:search_schemaname_contains rdf:type owl:NamedIndividual ,
                                     :SparqlSearchDatasource ;
                            :queryTemplate :query_search_label_contains ;
                            :labelProperty <http://schema.org/name> ;
                            rdfs:comment "Searches for entities by looking up the provided $key inside their schema:name using the CONTAINS SPARQL function."@en .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#search_schemaname_strstarts
:search_schemaname_strstarts rdf:type owl:NamedIndividual ,
                                      :SparqlSearchDatasource ;
                             :queryTemplate :query_search_label_strstarts ;
                             :labelProperty <http://schema.org/name> ;
                             rdfs:comment "Searches for entities by looking up the provided $key at the beginning of their schema:name using the STRSTARTS SPARQL function."@en .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#search_skospreflabel_bifcontains
:search_skospreflabel_bifcontains rdf:type owl:NamedIndividual ,
                                           :SparqlSearchDatasource ;
                                  :queryTemplate :query_search_label_bifcontains ;
                                  :labelPath <http://www.w3.org/2004/02/skos/core#prefLabel> ;
                                  rdfs:comment "Searches for entities by looking up the provided $key inside their skos:prefLabel using the bif:contains Virtuoso function."@en .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#search_skospreflabel_contains
:search_skospreflabel_contains rdf:type owl:NamedIndividual ,
                                        :SparqlSearchDatasource ;
                               :queryTemplate :query_search_label_contains ;
                               :labelProperty <http://www.w3.org/2004/02/skos/core#prefLabel> ;
                               rdfs:comment "Searches for entities by looking up the provided $key inside their skos:prefLabel using the CONTAINS SPARQL function."@en .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#search_skospreflabel_strstarts
:search_skospreflabel_strstarts rdf:type owl:NamedIndividual ,
                                         :SparqlSearchDatasource ;
                                :queryTemplate :query_search_label_strstarts ;
                                :labelProperty <http://www.w3.org/2004/02/skos/core#prefLabel> ;
                                rdfs:comment "Searches for entities by looking up the provided $key at the beginning of their skos:prefLabel using the STRSTARTS SPARQL function."@en .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#tree_children_skosnarrower
:tree_children_skosnarrower rdf:type owl:NamedIndividual ,
                                     :SparqlTreeChildrenDatasource ;
                            :queryTemplate :query_tree_children ;
                            :childrenPath "<http://www.w3.org/2004/02/skos/core#narrower>|^<http://www.w3.org/2004/02/skos/core#broader>" ;
                            :labelPath "<http://www.w3.org/2004/02/skos/core#prefLabel>" .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#tree_children_skosnarrower_with_count
:tree_children_skosnarrower_with_count rdf:type owl:NamedIndividual ,
                                                :SparqlTreeChildrenDatasource ;
                                       :queryTemplate :query_tree_children_with_count ;
                                       :childrenPath "<http://www.w3.org/2004/02/skos/core#narrower>|^<http://www.w3.org/2004/02/skos/core#broader>" ;
                                       :labelPath "<http://www.w3.org/2004/02/skos/core#prefLabel>" .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#tree_root_skostopconcept
:tree_root_skostopconcept rdf:type owl:NamedIndividual ,
                                   :SparqlTreeRootDatasource ;
                          :queryString """PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
SELECT DISTINCT ?uri ?label ?hasChildren
WHERE {
  $range skos:hasTopConcept|^skos:topConceptOf ?uri .
  ?uri skos:prefLabel ?label .
  FILTER(isIRI(?uri))
  FILTER(lang(?label) = '' || lang(?label) = $lang)
  OPTIONAL {
    ?uri skos:narrower|^skos:broader ?children .
  }
  BIND(IF(bound(?children),true,false) AS ?hasChildren)
}
ORDER BY UCASE(STR(?label))""" .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources#tree_root_skostopconcept_with_count
:tree_root_skostopconcept_with_count rdf:type owl:NamedIndividual ,
                                              :SparqlTreeRootDatasource ;
                                     :queryString """PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
SELECT ?uri (CONCAT(STR(?theLabel), ' (', STR(?count), ')') AS ?label) ?hasChildren ?count
WHERE {
  {
    SELECT ?uri ?theLabel ?hasChildren (COUNT(?x) AS ?count)
    WHERE {
      {
        SELECT ?uri ?theLabel ?hasChildren
        WHERE {
          $range skos:hasTopConcept|^skos:topConceptOf ?uri .
          ?uri skos:prefLabel ?theLabel .
          FILTER(isIRI(?uri))
          FILTER(lang(?theLabel) = '' || lang(?theLabel) = $lang)
          OPTIONAL {
            ?uri skos:narrower|^skos:broader ?children .
          }
          BIND(IF(bound(?children),true,false) AS ?hasChildren)
        }
      }

      OPTIONAL {
        ?x a $domain .
        ?x $property ?uri .
        # no range criteria
        # ?uri a $range .
      }
    }
    GROUP BY ?uri ?theLabel ?hasChildren
  }
} ORDER BY UCASE(STR(?label))""" .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources/query_tree_root_domain
<http://data.sparna.fr/ontologies/sparnatural-config-datasources/query_tree_root_domain> rdf:type owl:NamedIndividual ,
                                                                                                  :SPARQLQuery ;
                                                                                         :queryString """PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT ?uri ?label ?hasChildren
WHERE {
  VALUES ?uri {$domain}
  ?uri $labelPath ?label .
  OPTIONAL {
    ?uri $childrenPath ?children .
  }
  FILTER(lang(?label) = '' || lang(?label) = $lang)
  BIND(IF(bound(?children),true,false) AS ?hasChildren)
}""" ;
                                                                                         rdfs:comment "Assumes that the domain URI is the root of the tree we want to build. Useful to build hierarchies based on rdfs:subClassOf."@en .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources/tree_children_subClassOf
<http://data.sparna.fr/ontologies/sparnatural-config-datasources/tree_children_subClassOf> rdf:type owl:NamedIndividual ,
                                                                                                    :SparqlTreeChildrenDatasource ;
                                                                                           :queryTemplate :query_tree_children ;
                                                                                           :childrenPath "^<http://www.w3.org/2000/01/rdf-schema#subClassOf>" ;
                                                                                           :labelPath "<http://www.w3.org/2000/01/rdf-schema#label>" .


###  http://data.sparna.fr/ontologies/sparnatural-config-datasources/tree_root_domain_subClassOf
<http://data.sparna.fr/ontologies/sparnatural-config-datasources/tree_root_domain_subClassOf> rdf:type owl:NamedIndividual ,
                                                                                                       :SparqlTreeRootDatasource ;
                                                                                              :queryTemplate <http://data.sparna.fr/ontologies/sparnatural-config-datasources/query_tree_root_domain> ;
                                                                                              :childrenPath "^<http://www.w3.org/2000/01/rdf-schema#subClassOf>" ;
                                                                                              :labelPath "<http://www.w3.org/2000/01/rdf-schema#label>" .


###  Generated by the OWL API (version 5.1.18) https://github.com/owlcs/owlapi/
