Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Wikidata objects connected to Europeana merged in the last week -
# see https://phabricator.wikimedia.org/T240809
# query https://w.wiki/E3V
# youtube https://youtu.be/NnoIhdaU6SQ
from SPARQLWrapper import SPARQLWrapper, JSON
endpoint_url = "https://query.wikidata.org/sparql"
query = """SELECT ?EuropeanaEntity ?tgt ?change (REPLACE(STR(?item), ".*Q", "Q") AS ?qid) (REPLACE(STR(?tgt), ".*Q", "Q") AS ?tgtQid) ?tgtLabel WHERE {
?tgt wdt:P7704 ?EuropeanaEntityID.
?item owl:sameAs ?tgt;
schema:dateModified ?change.
BIND((NOW()) - ?change AS ?date_range)
FILTER(?date_range < 8 )
BIND(URI(CONCAT("http://data.europeana.eu/", ?EuropeanaEntityID)) AS ?EuropeanaEntity)
SERVICE wikibase:label { bd:serviceParam wikibase:language "en,de". }
}
ORDER BY DESC(?change)"""
def get_results(endpoint_url, query):
sparql = SPARQLWrapper(endpoint_url)
sparql.setQuery(query)
sparql.setReturnFormat(JSON)
return sparql.query().convert()
results = get_results(endpoint_url, query)
for result in results["results"]["bindings"]:
print(result)
@salgo60

This comment has been minimized.

Copy link
Owner Author

salgo60 commented Dec 20, 2019

Output
{'tgt': {'type': 'uri', 'value': 'http://www.wikidata.org/entity/Q172788'}, 'tgtLabel': {'xml:lang': 'en', 'type': 'literal', 'value': 'O. Henry'}, 'change': {'datatype': 'http://www.w3.org/2001/XMLSchema#dateTime', 'type': 'literal', 'value': '2019-12-19T18:12:30Z'}, 'EuropeanaEntity': {'type': 'uri', 'value': 'http://data.europeana.eu/agent/base/60399'}, 'qid': {'type': 'literal', 'value': 'Q50414656'}, 'tgtQid': {'type': 'literal', 'value': 'Q172788'}}
{'tgt': {'type': 'uri', 'value': 'http://www.wikidata.org/entity/Q2849054'}, 'tgtLabel': {'xml:lang': 'en', 'type': 'literal', 'value': 'Martin Sjardijn'}, 'change': {'datatype': 'http://www.w3.org/2001/XMLSchema#dateTime', 'type': 'literal', 'value': '2019-12-19T16:39:39Z'}, 'EuropeanaEntity': {'type': 'uri', 'value': 'http://data.europeana.eu/agent/base/1534'}, 'qid': {'type': 'literal', 'value': 'Q77971378'}, 'tgtQid': {'type': 'literal', 'value': 'Q2849054'}}
{'tgt': {'type': 'uri', 'value': 'http://www.wikidata.org/entity/Q12850169'}, 'tgtLabel': {'xml:lang': 'en', 'type': 'literal', 'value': 'Shakili Alasgar'}, 'change': {'datatype': 'http://www.w3.org/2001/XMLSchema#dateTime', 'type': 'literal', 'value': '2019-12-19T06:35:24Z'}, 'EuropeanaEntity': {'type': 'uri', 'value': 'http://data.europeana.eu/agent/base/8706'}, 'qid': {'type': 'literal', 'value': 'Q55197795'}, 'tgtQid': {'type': 'literal', 'value': 'Q12850169'}}
{'tgt': {'type': 'uri', 'value': 'http://www.wikidata.org/entity/Q8013902'}, 'tgtLabel': {'xml:lang': 'en', 'type': 'literal', 'value': 'William Kelly'}, 'change': {'datatype': 'http://www.w3.org/2001/XMLSchema#dateTime', 'type': 'literal', 'value': '2019-12-19T00:53:33Z'}, 'EuropeanaEntity': {'type': 'uri', 'value': 'http://data.europeana.eu/agent/base/152528'}, 'qid': {'type': 'literal', 'value': 'Q20858032'}, 'tgtQid': {'type': 'literal', 'value': 'Q8013902'}}
{'tgt': {'type': 'uri', 'value': 'http://www.wikidata.org/entity/Q5539465'}, 'tgtLabel': {'xml:lang': 'en', 'type': 'literal', 'value': 'George Frederick Harris'}, 'change': {'datatype': 'http://www.w3.org/2001/XMLSchema#dateTime', 'type': 'literal', 'value': '2019-12-18T13:06:49Z'}, 'EuropeanaEntity': {'type': 'uri', 'value': 'http://data.europeana.eu/agent/base/31964'}, 'qid': {'type': 'literal', 'value': 'Q43131267'}, 'tgtQid': {'type': 'literal', 'value': 'Q5539465'}}
{'tgt': {'type': 'uri', 'value': 'http://www.wikidata.org/entity/Q234289'}, 'tgtLabel': {'xml:lang': 'en', 'type': 'literal', 'value': 'Halide Edib Adıvar'}, 'change': {'datatype': 'http://www.w3.org/2001/XMLSchema#dateTime', 'type': 'literal', 'value': '2019-12-18T10:12:35Z'}, 'EuropeanaEntity': {'type': 'uri', 'value': 'http://data.europeana.eu/agent/base/80356'}, 'qid': {'type': 'literal', 'value': 'Q16434869'}, 'tgtQid': {'type': 'literal', 'value': 'Q234289'}}
{'tgt': {'type': 'uri', 'value': 'http://www.wikidata.org/entity/Q526915'}, 'tgtLabel': {'xml:lang': 'en', 'type': 'literal', 'value': 'Princess Eugénie of Sweden'}, 'change': {'datatype': 'http://www.w3.org/2001/XMLSchema#dateTime', 'type': 'literal', 'value': '2019-12-17T16:15:09Z'}, 'EuropeanaEntity': {'type': 'uri', 'value': 'http://data.europeana.eu/agent/base/20732'}, 'qid': {'type': 'literal', 'value': 'Q75385428'}, 'tgtQid': {'type': 'literal', 'value': 'Q526915'}}
{'tgt': {'type': 'uri', 'value': 'http://www.wikidata.org/entity/Q4741823'}, 'tgtLabel': {'xml:lang': 'en', 'type': 'literal', 'value': 'Ambrose Macdonald Poynter'}, 'change': {'datatype': 'http://www.w3.org/2001/XMLSchema#dateTime', 'type': 'literal', 'value': '2019-12-17T15:22:20Z'}, 'EuropeanaEntity': {'type': 'uri', 'value': 'http://data.europeana.eu/agent/base/45597'}, 'qid': {'type': 'literal', 'value': 'Q75491003'}, 'tgtQid': {'type': 'literal', 'value': 'Q4741823'}}
....
....

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.