#
# example SPARQL query 167
#

@prefix schema: <https://schema.org/> . 
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . 
@prefix sh: <http://www.w3.org/ns/shacl#> . 
@prefix cello: <https://purl.expasy.org/cellosaurus/rdf/ontology/> .


cello:Query_167 a sh:SPARQLExecutable ;
    sh:prefixes _:sparql_examples_prefixes ;
    rdfs:comment """Count of cell lines established by organization"""@en ; 
    schema:keywords "from" , "provided" , "established by" , "organization" , "stats" , "private" ; 
    schema:target <https://sparql.cellosaurus.org/sparql> ; 
    sh:select """
PREFIX cello: <https://purl.expasy.org/cellosaurus/rdf/ontology/>
PREFIX cvcl: <https://purl.expasy.org/cellosaurus/rdf/cvcl/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX schema: <https://schema.org/>
select
        ?org_name 		              # organization name
        ?person_name                # name of contact person (optional)
        (count(?cl) as ?cl_count)		# count of cell linesknown as etablished by organization
where {
  #values ?cl { cvcl:CVCL_C2T2 }
  ?cl a / rdfs:subClassOf cello:CellLine .
  ?cl cello:establishedBy ?org.
  ?org a schema:Organization.
  ?org cello:recommendedName ?org_name . # there is 1 and only 1 rec name by org
  optional {
    ?person cello:isMemberOf ?org.
    ?person a schema:Person .
    ?person cello:name ?person_name .
  }
}
group by ?org_name ?person_name
order by desc(count(?cl))
    """
    .

