User:Nehemie.strupler/sparql beta

# Which human occupation is recorded in North Africa?

SELECT ?occupationLabel ?country_citizenshipLabel (COUNT(?occupationLabel) AS ?count) WHERE {
  ?item wdt:P31 wd:Q5. # Human
  ?item wdt:P27 ?country_citizenship. #With country citizenship
  ?country_citizenship wdt:P361 wd:Q27381. # Which is in north Africa
  OPTIONAL { ?item wdt:P106 ?occupation. }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
} GROUP BY ?occupationLabel ?country_citizenshipLabel
ORDER BY DESC (?count)
Try it!


# Tunisian Singer

SELECT DISTINCT ?item ?itemLabel ?occupationLabel ?statements WHERE {
  ?item wdt:P31 wd:Q5. # Human
  ?item wdt:P27 wd:Q948. # Citizenship = Tunisia
  ?item wdt:P106 wd:Q177220.  #Occupation = Singer
  ?item wikibase:statements ?statements. # Number of statements
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
} ORDER BY desc(?statements) # Sort by number of statements
Try it!
# A string in specif languages

select ?string ?lang where {
  wd:Q1107971 rdfs:label ?string.
  bind (lang(?string) as ?lang)# values ?lang {'eu' 'en' 'es' 'de' 'fr'}
  }
Try it!


# Tim, a physicist

SELECT ?item ?itemLabel ?statements WHERE {
  ?item wdt:P106 wd:Q169470;  #Occupation -> physicist
        rdfs:label ?itemLabel;
        wikibase:statements ?statements. # Number of statements
          FILTER(LANG(?itemLabel) = "en").
          FILTER(CONTAINS(?itemLabel, "Tim")).
}ORDER BY DESC(?statements)
Try it!


# Women Archaeologists born in a city with a birth date 
#defaultView:Map
SELECT DISTINCT ?person ?personLabel ?birthplaceLabel ?birth_year ?coordinates WHERE {
  ?person wdt:P101 wd:Q23498;
          wdt:P21 wd:Q6581072;
          wdt:P19 ?birthplace.
  ?birthplace wdt:P31 wd:Q515;
              wdt:P625 ?coordinates.
  ?person p:P569/psv:P569 ?birth_date_node. 
  ?birth_date_node wikibase:timeValue ?birth_dateyear.
  BIND( YEAR(?birth_dateyear)  AS ?birth_year)
  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
Try it!


# Iranian female born in a city with a birth date > 1900
SELECT DISTINCT ?person ?personLabel ?birthplaceLabel ?birth_year ?sex_or_genderLabel ?coordinates
(GROUP_CONCAT(DISTINCT ?occupationLabel; SEPARATOR=", ") AS ?occupations)
                
WHERE {
  ?person wdt:P31 wd:Q5;
          wdt:P19 ?birthplace;
          wdt:P21 wd:Q6581072;
          wdt:P106 ?occupation.
  ?birthplace wdt:P31/wdt:P279* wd:Q515;
              wdt:P17 wd:Q794;
              wdt:P625 ?coordinates.
  ?person p:P569/psv:P569 ?birth_date_node. 
  ?birth_date_node wikibase:timeValue ?birth_dateyear.
  BIND( YEAR(?birth_dateyear)  AS ?birth_year)
  BIND( YEAR(?birth_dateyear)  AS ?birth_year)
  BIND( wd:Q6581072  AS ?sex_or_gender)
  FILTER(?birth_year > 1900).
  # Define label because of Group
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,fa".
                           ?occupation rdfs:label ?occupationLabel.
                           ?person rdfs:label ?personLabel.
                           ?birthplace rdfs:label ?birthplaceLabel.
                           ?sex_or_gender rdfs:label ?sex_or_genderLabel.}
} GROUP BY ?person ?personLabel ?birthplaceLabel ?birth_year ?sex_or_genderLabel ?coordinates ?occupations
Try it!


# Iranian cities, Max pop from last point in time
SELECT ?city ?city_FA ?city_EN (MAX(?population) AS ?pop) ?coordinates ?date
             
WHERE {
  ?city wdt:P31/wdt:P279* wd:Q515;
        wdt:P17 wd:Q794;
        wdt:P625 ?coordinates;
        p:P1082 [pq:P585 ?date; ps:P1082 ?population].
   FILTER NOT EXISTS {?city p:P1082 [pq:P585 ?date_] FILTER (?date_ > ?date)}
     SERVICE wikibase:label { bd:serviceParam wikibase:language "en".
            ?city rdfs:label ?city_EN.
     }
     SERVICE wikibase:label { bd:serviceParam wikibase:language "fa".
            ?city rdfs:label ?city_FA.
     } hint:Prior hint:runLast false.
 } GROUP BY ?city ?city_FA ?city_EN ?pop ?coordinates ?date
Try it!