# Named Queries for truly tabular analysis
# WF 2022-03-14
"mostFrequentProperties":
    title: most frequently used  properties
    description: most frequently used  properties
    sparql: |
        # get the most frequently used properties for
        # %s
        PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
        PREFIX schema: <http://schema.org/>
        PREFIX wd: <http://www.wikidata.org/entity/>
        PREFIX wdt: <http://www.wikidata.org/prop/direct/>
        PREFIX xsd:  <http://www.w3.org/2001/XMLSchema#>
        SELECT ?prop ?propLabel ?count WHERE {
          {
            SELECT ?prop (COUNT(DISTINCT ?item) AS ?count) WHERE {
              #hint:Query hint:optimizer "None".
              %s
                ?p ?id.
              ?prop wikibase:directClaim ?p.
            }
            GROUP BY ?prop ?propLabel
          }
          ?prop rdfs:label ?propLabel
          filter(lang(?propLabel) = "%s")      
        }
        ORDER BY DESC (?count)
"mostFrequentIdentifiers":
    title: most frequently used identifier properties
    description: most frequently used identifier properties
    sparql: |
        SELECT ?prop ?propLabel ?count WHERE {
        {
            SELECT ?prop (COUNT(DISTINCT ?item) AS ?count) WHERE {
               
               hint:Query hint:optimizer "None" .
               ?item wdt:P31 wd:%s .
               ?item ?p ?id .
               ?prop wikibase:directClaim ?p .
               {?prop wdt:P31 wd:Q19847637}  # Wikidata property representing a unique identifier
                    UNION
               {?prop wdt:P31 wd:Q19595382}  # Wikidata property for authority control for people
            }  GROUP BY ?prop
        }
               
        SERVICE wikibase:label {
            bd:serviceParam wikibase:language "en" .
        }
    
        } ORDER BY DESC (?count)
