Exemple #1
0
    def get_all(self):
        physician = 'Q39631'

        query = """SELECT ?subclass_of WHERE {
          SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
          ?subclass_of wdt:P279 wd:Q39631.
        }
        """
        sparql = SparqlQuery()
        results = sparql.query(query)

        physician_types = set([
            q['subclass_of']['value'].split("/")[-1]
            for q in results['results']['bindings']
        ])
        physician_types.add(physician)

        physicians = set()

        for t in physician_types:
            query = sub(
                'physician_type', t, """SELECT ?physician WHERE {
          SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
          ?physician wdt:P106 wd:physician_type.
          ?physician wdt:P31 wd:Q5.
        }
        """)
            sparql = SparqlQuery()
            try:
                results = sparql.query(query)
                results = set([
                    q['physician']['value'].split("/")[-1]
                    for q in results['results']['bindings']
                ])
            except Exception as e:
                pprint(e)
            physicians = physicians.union(results)
        return physicians
Exemple #2
0
def get_existing_items_with_instanceof_and_rfcnum():
	sparqlquery = SparqlQuery()
	response = sparqlquery.query('SELECT ?rfcid ?item WHERE { ?item wdt:P31/wdt:P279* wd:Q212971 . ?item wdt:P892 ?rfcid }')
	bindings = response['results']['bindings']
	existing_items = {}
	for binding in bindings:
		item_url = binding['item']['value']
		result = re.search(r'(Q\d+)', item_url)
		if not result:
			print('Error: could not find Wikidata item identifier in SPARQL results obtained by get_existing_items_with_instanceof_and_rfcnum()')
			continue
		item = result.group(1)
		rfc = binding['rfcid']['value']
		existing_items[rfc] = item
	return existing_items
Exemple #3
0
def get_existing_items_with_rfc_dois():
	sparqlquery = SparqlQuery()
	response = sparqlquery.query('SELECT ?doi ?item WHERE { ?item wdt:P356 ?doi . FILTER regex(?doi, \'^10.17487/RFC\\\\d{4}\') }')
	bindings = response['results']['bindings']
	existing_items = {}
	for binding in bindings:
		item_url = binding['item']['value']
		result = re.search(r'(Q\d+)', item_url)
		if not result:
			print('Error: could not find Wikidata item identifier in SPARQL results obtained by get_existing_items_with_rfc_dois()')
			continue
		item = result.group(1)
		doi = binding['doi']['value']
		result = re.search(r'RFC(\d+)', doi)
		if not result:
			print('Error: could not find RFC identifier in SPARQL results obtained by get_existing_items_with_rfc_dois()')
			continue
		rfc = result.group(1)
		existing_items[rfc] = item
	return existing_items
Exemple #4
0
 def do_call():
     from pywikibot.data.sparql import SparqlQuery
     sparql = SparqlQuery()
     results = sparql.query(query)
     idle_add(lambda: callback(results, *cb_args, **kwargs))
     return None
Exemple #5
0
file_name_ssb = '07459_20220224-190529.json'
year_adding = 2022
test_edit = '[[Wikidata:Requests for permissions/Bot/IngeniousBot 2|Test edit]]: '

query_municipality = """
SELECT DISTINCT ?item ?value WHERE {
  ?item wdt:P2504 ?value;
    wdt:P31 wd:Q755707, wd:Q755707;
    p:P1082 _:b30.
  _:b30 pq:P585 ?pointintime;
    rdf:type wikibase:BestRank.
  FILTER(?pointintime != "2022-01-01T00:00:00Z"^^xsd:dateTime)
}
"""
wikiquery = SparqlQuery()
xml = wikiquery.query(query_municipality)

# Opening JSON file from SSB
f = open(file_name_ssb)

# returns JSON object as a dictionary
data = json.load(f)

# the dict for data
data_mun = {}

# Iterating through the json
blacklist = ['21-22', '23', 'Rest']
k_num = data['dataset']['dimension']['Region']['category']['index']
for i in k_num:
    if i[2:] not in blacklist: