set up the ability to query wikidata

import urllib.parse
from IPython.display import IFrame
baseurl='https://query.wikidata.org/embed.html#'

def wdq(query='',width=800,height=500):
  return IFrame(baseurl+urllib.parse.quote(query), width=width, height=height)

All museums with only one language wikipedia article, coloured by language.

wdq(width=1000,height=1000,query="""
#defaultView:Map{"layer":"?lang"}

SELECT DISTINCT ?p ?pLabel ?coords ?lang WHERE {
   ?c wdt:P279* wd:Q33506 .
   ?p wdt:P31 ?c; wikibase:sitelinks 1
      
   {
      ?article schema:about ?p .
      ?article schema:inLanguage ?lang .
      FILTER (CONTAINS(str(?article), ".wikipedia.org/")) .
   }
  
   ?p wdt:P625 ?coords.
  
   SERVICE wikibase:label {
    bd:serviceParam wikibase:language "en" .
   }
 }
LIMIT 10000
 """)

All schools with only one language wikipedia article, coloured by language.

wdq(width=1000,height=1000,query="""
#defaultView:Map{"layer":"?lang"}

SELECT DISTINCT ?p ?pLabel ?coords ?lang WHERE {
   ?c wdt:P279* wd:Q3914 .
   ?p wdt:P31 ?c; wikibase:sitelinks 1
      
   {
      ?article schema:about ?p .
      ?article schema:inLanguage ?lang .
      FILTER (CONTAINS(str(?article), ".wikipedia.org/")) .
   }
  
   ?p wdt:P625 ?coords.
  
   SERVICE wikibase:label {
    bd:serviceParam wikibase:language "en" .
   }
 }
LIMIT 30000
 """)
wdq(width=1000,height=1000,query="""
#defaultView:Map{"markercluster":"{"disableClusteringAtZoom":"100","chunkedLoading":"true"}","layer":"?lang"}
#this version (with limit 50000) was used to generate the md5rgb maps
SELECT DISTINCT ?person ?personLabel ?lang ?coords ?rgb WHERE {
     ?person wdt:P106 wd:Q82955 .
     ?person wdt:P19 ?p .
     ?person wikibase:sitelinks 1 .
   {
      ?article schema:about ?person .
      ?article schema:inLanguage ?lang .
      FILTER (CONTAINS(str(?article), ".wikipedia.org/")) .
   }
   ?p wdt:P625 ?coords.
   SERVICE wikibase:label {
    bd:serviceParam wikibase:language "en" .
   }
   BIND( substr(md5(STR(?lang)),1,6) as ?rgb )
 }
LIMIT 5000
 """)

All islands with only one language wikipedia article, coloured by language.

wdq(width=1000,height=1000,query="""
#defaultView:Map{"layer":"?lang"}

SELECT DISTINCT ?p ?pLabel ?coords ?lang WHERE {
     
     ?c wdt:P279* wd:Q23442 .
     ?p wdt:P31 ?c; wikibase:sitelinks 1
     
     
   {
      ?article schema:about ?p .
      ?article schema:inLanguage ?lang .
      FILTER (CONTAINS(str(?article), ".wikipedia.org/")) .
   }
  
   ?p wdt:P625 ?coords.
  
   SERVICE wikibase:label {
    bd:serviceParam wikibase:language "en" .
   }
 }
LIMIT 10000
 """)

politicians in only one language (by birthplace)

wdq(width=1000,height=1000,query="""
#defaultView:Map{"layer":"?lang"}

SELECT DISTINCT ?person ?personLabel ?coords ?lang WHERE {
     
     #?c wdt:P279* wd:Q23442 .
     ?person wdt:P106 wd:Q82955 .
     ?person wdt:P19 ?p .
     ?p wdt:P31 ?c .
     
     ?person wikibase:sitelinks 1 .
   {
      ?article schema:about ?person .
      ?article schema:inLanguage ?lang .
      FILTER (CONTAINS(str(?article), ".wikipedia.org/")) .
   }
  
   ?p wdt:P625 ?coords.
  
   SERVICE wikibase:label {
    bd:serviceParam wikibase:language "en" .
   }
 }
LIMIT 40000
 """)
wdq(width=1000,height=1000,query="""
#defaultView:Map{"markercluster":"{"disableClusteringAtZoom":"100","chunkedLoading":"true"}","layer":"?lang"}
#this version (with limit 50000) was used to generate the md5rgb maps (to separate Japanese from English, among others)
SELECT DISTINCT ?person ?personLabel ?lang ?coords ?rgb WHERE {
     ?person wdt:P106 wd:Q82955 .
     ?person wdt:P19 ?p .
     ?person wikibase:sitelinks 1 .
   {
      ?article schema:about ?person .
      ?article schema:inLanguage ?lang .
      FILTER (CONTAINS(str(?article), ".wikipedia.org/")) .
   }
   ?p wdt:P625 ?coords.
   SERVICE wikibase:label {
    bd:serviceParam wikibase:language "en" .
   }
   BIND( substr(md5(STR(?lang)),1,6) as ?rgb )
 }
LIMIT 5000
 """)

Now for cartographers, with a more comprehensive covereage (not using sitelinks screening, which includes commons and others)

wdq(width=1000,height=1000,query="""
#defaultView:Map{"layer":"?lang"}
SELECT DISTINCT ?person ?personLabel ?coords (SAMPLE(?lang) AS ?lang) WHERE {
     ?person wdt:P106 wd:Q1734662 .
     ?person wdt:P19 ?p .
    # ?person wikibase:sitelinks 1 .
    {
      ?article schema:about ?person .
      ?article schema:inLanguage ?lang .
      FILTER (CONTAINS(str(?article), ".wikipedia.org/")) .
    }
   ?p wdt:P625 ?coords.
   SERVICE wikibase:label {
    bd:serviceParam wikibase:language "en" .
   }
 } GROUP BY ?person ?personLabel ?coords
HAVING (COUNT(*) < 2)
LIMIT 10000
 """)

Researchers (by birthplace)

wdq(width=1000,height=1000,query="""
#defaultView:Map{"layer":"?lang"}

SELECT DISTINCT ?person ?personLabel ?coords ?lang WHERE {
     
     ?occupations wdt:P279* wd:Q1650915 .
     
     ?person wdt:P106 ?occupations .
     ?person wdt:P19 ?p .
     ?p wdt:P31 ?c .
     
     ?person wikibase:sitelinks 1 .
   {
      ?article schema:about ?person .
      ?article schema:inLanguage ?lang .
      FILTER (CONTAINS(str(?article), ".wikipedia.org/")) .
   }
  
   ?p wdt:P625 ?coords.
  
   SERVICE wikibase:label {
    bd:serviceParam wikibase:language "en" .
   }
 }
LIMIT 10000
 """)

cross-polination: people covered in two languages - not currently working due to sampling problems

wdq(width=1000,height=1000,query="""
#defaultView:Map{"layer":"?lang"}

SELECT DISTINCT ?person ?personLabel ?coords ?lang ?lang2 WHERE {
#SELECT DISTINCT ?p ?pLabel ?coords ?lang ?lang2 WHERE {
     
     #?occupations wdt:P279* wd:Q1650915 .
     
     #?person wdt:P106 ?occupations .
     ?person wdt:P19 ?p .

     ?person wikibase:sitelinks 2 .
   {
      ?article schema:about ?person .
      ?article schema:inLanguage ?lang .
      FILTER (CONTAINS(str(?article), ".wikipedia.org/")) .
   }
   {
      ?article2 schema:about ?person .
      ?article2 schema:inLanguage ?lang2 .
      FILTER (CONTAINS(str(?article2), ".wikipedia.org/")) .
   }
     
  FILTER (?lang != ?lang2)
  
   ?p wdt:P625 ?coords.
  
   SERVICE wikibase:label {
    bd:serviceParam wikibase:language "en" .
   }
 }
LIMIT 10
 """)
wdq(width=1000,height=1000,query="""
SELECT DISTINCT ?lang1item ?lang1itemLabel ?rgb ?size ?link ?linkLabel ?rgb2 WHERE {
  SELECT DISTINCT ?lang1item (?lang1 as ?lang1itemLabel) ("AAAAAA" AS ?rgb) ?size (?lang2item as ?link) (?lang2 as ?linkLabel) WHERE {
   
     SELECT DISTINCT ?item ?lang1item ?lang1 ?size ?lang2item ?lang2 WHERE {         
       {
         ?item wikibase:sitelinks 2 .
       
         {
         ?article1 schema:about ?item .
         ?article1 schema:inLanguage ?lang1 .
         FILTER (CONTAINS(str(?article1), ".wikipedia.org/")) .
         ?lang1item wdt:P424 ?lang1 .
         ?lang1item wdt:P31 wd:Q10876391 .
         ?lang1item wikibase:sitelinks ?size .
         }
         
         {
         ?article2 schema:about ?item .
         ?article2 schema:inLanguage ?lang2 .
         FILTER (CONTAINS(str(?article2), ".wikipedia.org/")) .
         ?lang2item wdt:P424 ?lang2 .
         ?lang2item wdt:P31 wd:Q10876391 .
         }
         FILTER (?lang1 != ?lang2)
       }        
    
     }
     LIMIT 100000
     
 # SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }

  } GROUP BY ?lang1item ?lang1 ?size ?lang2item ?lang2 
  HAVING (count(*) > 5) 
  ORDER BY DESC(count(*))
 }
""")
 
wdq(width=1000,height=1000,query="""
#defaultView:Graph
# Graph of knowledge overlap in different language versions of Wikipedia, using articles in only two languages as a proxy, with a threshold of 50 to add a connection.
#SELECT DISTINCT ?language1 (?lang1 AS ?language1Label) ?language1_classLabel ?rgb ?count ((?size * ?size * ?size) AS ?sizecubed) (?language2 AS ?link) (?lang2 AS ?linkLabel) 
SELECT DISTINCT ?language1 ?language1Label ?language1_classLabel ?rgb ?count ((?size * ?size * ?size) AS ?sizecubed) ?language2 ?language2Label 
WITH {
  SELECT DISTINCT ?lang1 ?lang2 (COUNT(*) AS ?count) WHERE {
     SELECT DISTINCT ?item ?lang1 ?lang2 WHERE {         
        ?item wikibase:sitelinks 2 .
        ?article1 schema:about ?item .
        ?article1 schema:inLanguage ?lang1 .
        ?article2 schema:about ?item .
        ?article2 schema:inLanguage ?lang2 .

        FILTER (?lang1 != ?lang2)
        #FILTER (CONTAINS(str(?article1), ".wikipedia.org/")) .
        #FILTER (CONTAINS(str(?article2), ".wikipedia.org/")) .
       }        
       LIMIT 1000000   
  } GROUP BY ?lang1 ?lang2 
  HAVING (count(*) > 50) 
  } AS %l1l2                   
WITH {
  SELECT DISTINCT ?language1 ?lang1 ?language1_class ?size ?rgb WHERE {
      hint:Query hint:optimizer "None".
      ?lang1item wdt:P31 wd:Q10876391 .
      ?lang1item wdt:P407 ?language1 .
    
      {?language1_class wdt:P279 wd:Q20162172 .}
        UNION
      {?language1_class wdt:P279 wd:Q19860 .}
      FILTER (?language1_class != wd:Q19860). #the Indo-Euro class of languages is too broad, but has been split above
      FILTER (?language1_class != wd:Q276314). #the proposed Nostratic class of languages is too broad
      FILTER (?language1_class != wd:Q771861). #the proposed Eurasiatic class of languages is too broad
    
      ?language1 wdt:P279* ?language1_class .
    
      ?lang1item wikibase:sitelinks ?size .
      ?lang1item wdt:P424 ?lang1 .

       BIND( substr(md5(STR(?language1_class)),1,6) as ?rgb )
   }
} AS %l1
WHERE {
  INCLUDE %l1l2 .
  INCLUDE %l1 .
  ?lang2item wdt:P424 ?lang2 .
  ?lang2item wdt:P31 wd:Q10876391 .   
  ?lang2item wdt:P407 ?language2 .
  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
#ORDER BY DESC(?count)
 """)
wdq(width=1000,height=1000,query="""
SELECT DISTINCT ?lang1 ?language1 ?language1_class ?language1_classLabel WHERE {

  {
  hint:Query hint:optimizer "None".
  ?lang1item wdt:P31 wd:Q10876391 .
  ?lang1item wdt:P407 ?language1 .
    
      {?language1_class wdt:P279 wd:Q20162172 .}
        UNION
      {?language1_class wdt:P279 wd:Q19860 .}
      FILTER (?language1_class != wd:Q19860). #the Indo-Euro class of languages is too broad, but has been split above
      FILTER (?language1_class != wd:Q276314). #the proposed Nostratic class of languages is too broad
      FILTER (?language1_class != wd:Q771861). #the proposed Eurasiatic class of languages is too broad

?language1 wdt:P279* ?language1_class .
  #hint:Prior hint:gearing "forward".

  ?lang1item wikibase:sitelinks ?size .
  ?lang1item wdt:P424 ?lang1 .
  }
  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}

""")
wdq(width=1000,height=1000,query="""
#defaultView:BubbleChart
SELECT DISTINCT ?language1_class ?language1_classLabel (count(*) AS ?count) WHERE {

  {
  hint:Query hint:optimizer "None".
  ?lang1item wdt:P31 wd:Q10876391 .
  ?lang1item wdt:P407 ?language1 .
    
      {?language1_class wdt:P279 wd:Q20162172 .}
        UNION
      {?language1_class wdt:P279 wd:Q19860 .}
      FILTER (?language1_class != wd:Q19860). #the Indo-Euro class of languages is too broad, but has been split above
      FILTER (?language1_class != wd:Q276314). #the proposed Nostratic class of languages is too broad
      FILTER (?language1_class != wd:Q771861). #the proposed Eurasiatic class of languages is too broad

  ?language1 wdt:P279* ?language1_class .
  #hint:Prior hint:gearing "forward".

  ?lang1item wikibase:sitelinks ?size .
  ?lang1item wdt:P424 ?lang1 .
  }
  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
} GROUP BY ?language1_class ?language1_classLabel

""")
 
wdq(width=1000,height=1000,query="""
SELECT DISTINCT ?lang1 ?language1 ?language1_class ?language1_classLabel WHERE {

  {
  #hint:Query hint:optimizer "None".
  #?lang1item wdt:P31 wd:Q10876391 .
  #?lang1item wdt:P407 ?language1 .
    
    
  
   ?language_class wdt:P279* wd:Q20162172 .

#FILTER (?language1_class != wd:Q19860). #the Indo-Euro class of languages is too broad, but has been split above
#FILTER (?language1_class != wd:Q276314). #the proposed Nostratic class of languages is too broad
#FILTER (?language1_class != wd:Q771861). #the proposed Eurasiatic class of languages is too broad

?language1 wdt:P279* ?language1_class .
  #hint:Prior hint:gearing "forward".

  ?lang1item wikibase:sitelinks ?size .
  ?lang1item wdt:P424 ?lang1 .
  }
  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}

""")
wdq(width=1000,height=1000,query="""
#defaultView:Graph
SELECT DISTINCT ?item1 ?item1Label (count(*) AS ?count) ?rgb ?item2 ?item2Label WHERE
{
  BIND (wd:Q20162172 AS ?tree0)
  {
    ?item2 wdt:P279* ?tree0 .
  } 
  UNION 
  {
    VALUES (?item2) {(wd:Q20162172)}
  }
    
  ?item1 wdt:P279 ?item2 .
  ?item0 wdt:P279 ?item1 .
  FILTER (?item1 != wd:Q33742) .
  FILTER (?item2 != wd:Q33742) .
  FILTER (?item1 != wd:Q1288568) .
  FILTER (?item2 != wd:Q1288568) .
  FILTER (?item1 != wd:Q45762) .
  FILTER (?item2 != wd:Q45762) .
  FILTER (?item1 != wd:wd:Q4316069) .
  FILTER (?item2 != wd:wd:Q4316069) .
  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
  BIND( "33AACC" AS ?rgb).  
} GROUP BY ?item1 ?item1Label ?rgb ?item2 ?item2Label
LIMIT 3000
""")
wdq(width=1000,height=1000,query="""
#defaultView:Graph
SELECT DISTINCT ?item1 ?item1Label ?count ?rgb ?item2 ?item2Label 
WITH {
  SELECT DISTINCT ?language1 ?lang1 ?language1_class ?size WHERE {
      hint:Query hint:optimizer "None".
      ?lang1item wdt:P31 wd:Q10876391 .
      ?lang1item wdt:P407 ?language1 .
    
      {?language1_class wdt:P279 wd:Q20162172 .}
        UNION
      {?language1_class wdt:P279 wd:Q19860 .}
      FILTER (?language1_class != wd:Q19860). #the Indo-Euro class of languages is too broad, but has been split above
      FILTER (?language1_class != wd:Q276314). #the proposed Nostratic class of languages is too broad
      FILTER (?language1_class != wd:Q771861). #the proposed Eurasiatic class of languages is too broad
    
      ?language1 wdt:P279* ?language1_class .
    
      ?lang1item wikibase:sitelinks ?size .
      ?lang1item wdt:P424 ?lang1 .

       #BIND( substr(md5(STR(?language1_class)),1,6) as ?rgb )
   }
} AS %l1
WITH {
  SELECT DISTINCT ?item1 (count(*) AS ?count) ?item2 WHERE {
  {
    ?item2 wdt:P279* wd:Q20162172 .
  } 
  UNION 
  {
    VALUES (?item2) {(wd:Q20162172)}
  }
    
  ?item1 wdt:P279 ?item2 .
  ?item0 wdt:P279 ?item1 .
  } GROUP BY ?item1 ?item2
} AS %l2

WHERE
{
  INCLUDE %l1
  INCLUDE %l2
  #OPTIONAL  {
          
  {        
    ?language1 wdt:P279 ?item1 .
  } UNION {
    ?language1 wdt:P279/wdt:P279 ?item1 .
  } UNION {
    ?language1 wdt:P279/wdt:P279/wdt:P279 ?item1 .
  } UNION {
    ?language1 wdt:P279/wdt:P279/wdt:P279/wdt:P279 ?item1 .
  }
    BIND( substr(md5(STR(?language1_class)),1,6) as ?rgb )
  #}
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
} 
LIMIT 3000
""")
wdq(width=1000,height=1000,query="""
#defaultView:Map{"layer":"?lang"}
SELECT ?s ?desc (SAMPLE(?coords) AS ?coords) (lang(?desc) AS ?lang) (COUNT(DISTINCT ?label) as ?labelcount) (SAMPLE(?rgb) AS ?rgb)
WHERE
{
  ?s wdt:P625 ?coords.
  ?s wdt:P17 wd:Q408 .
  ?s rdfs:label ?label .
  OPTIONAL {
     ?s rdfs:label ?desc .
     #filter (lang(?desc) = "en").
   }
  BIND( substr(md5(STR(LANG(?desc))),1,6) as ?rgb )
} GROUP BY ?s ?desc 
HAVING (?labelcount=1)
 """)
wdq(width=1000,height=1000,query="""
#defaultView:Map{"layer":"?lang"}
SELECT ?s ?desc (SAMPLE(?coords) AS ?coords) (lang(?desc) AS ?lang) (COUNT(DISTINCT ?label) as ?labelcount) (SAMPLE(?rgb) AS ?rgb)
WHERE
{
  ?s wdt:P625 ?coords.
  ?s wdt:P17 wd:Q1008 .
  ?s rdfs:label ?label .
  OPTIONAL {
     ?s rdfs:label ?desc .
     #filter (lang(?desc) = "en").
   }
  BIND( substr(md5(STR(LANG(?desc))),1,6) as ?rgb )
} GROUP BY ?s ?desc 
HAVING (?labelcount=1)
 """)