Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import requests
query = '''
select distinct ?p1 where {
VALUES ?pd {
<http://www.wikidata.org/entity/Q423026>
<http://www.wikidata.org/entity/Q616005>
<http://www.wikidata.org/entity/Q7644128>
<http://www.wikidata.org/entity/Q898273>
<http://www.wikidata.org/entity/Q898362>
<http://www.wikidata.org/entity/Q3273544>
}
?all_domains wdt:P279 ?pd .
?p1 wdt:P352 ?up1 .
?p1 wdt:P527 ?all_domains .
}
'''
query2 = '''
select distinct ?p where {
VALUES ?pd {
<http://www.wikidata.org/entity/Q423026>
<http://www.wikidata.org/entity/Q616005>
<http://www.wikidata.org/entity/Q7644128>
<http://www.wikidata.org/entity/Q898273>
<http://www.wikidata.org/entity/Q898362>
<http://www.wikidata.org/entity/Q3273544>
}
?all_domains wdt:P279 ?pd .
?p wdt:P352 ?up .
?p p:P527/ps:P527 ?all_domains .
}
'''
wd_standard_prefix = '''
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX v: <http://www.wikidata.org/prop/statement/>
PREFIX q: <http://www.wikidata.org/prop/qualifier/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
'''
params = {
'query': wd_standard_prefix + query,
'format': 'json'
}
headers = {
'Accept': 'application/sparql-results+json'
}
results = requests.get('https://query.wikidata.org/sparql', params=params, headers=headers).json()['results']['bindings']
params = {
'query': wd_standard_prefix + query2,
'format': 'json'
}
results2 = requests.get('https://query.wikidata.org/sparql', params=params, headers=headers).json()['results']['bindings']
r1 = {x['p1']['value'] for x in results}
print('r1', len(r1))
r2 = {x['p']['value'] for x in results2}
print('r2', len(r2))
print('r1 to r2 diff', r1.difference(r2))
print('r2 to r1 diff', r2.difference(r1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.