Open goodb opened 8 years ago
Can't figure out how to construct the sparql query. This is what I have so far:
SELECT distinct ?item ?p ?vals ?prop ?propLabel ?d (datatype (?vals) AS ?type) ?ref ?refp ?refval WHERE {
hint:Query hint:optimizer "None" .
values ?item {wd:Q86591}
?item ?p ?vals .
{?prop wikibase:directClaim ?p .}
union {
?vals prov:wasDerivedFrom ?ref .
?ref ?refp ?refval .
?vals ?prop ?d }
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
Here is an example of a query into references and qualifiers when you know what you are looking for.
PREFIX prov: http://www.w3.org/ns/prov# PREFIX p: http://www.wikidata.org/prop/ PREFIX wd: http://www.wikidata.org/entity/ PREFIX wdt: http://www.wikidata.org/prop/direct/ PREFIX pq: http://www.wikidata.org/prop/qualifier/
SELECT distinct ?go_bp ?go_bpLabel ?determination ?determinationLabel ?reference_stated_inLabel ?reference_retrieved WHERE {
wd:Q13561329 wdt:P681 ?go_bp . # get a protein record directly and get biological process annotations wd:Q13561329 p:P681 ?go_bp_statement . #get the statements associated with the bp annotations ?go_bp_statement pq:P459 ?determination . # get 'determination method' qualifiers associated with the statements
?go_bp_statement prov:wasDerivedFrom/pr:P248 ?reference_stated_in . #where stated ?go_bp_statement prov:wasDerivedFrom/pr:P813 ?reference_retrieved . #when retrieved
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . } } limit 10
Perhaps it would be more straightforward to do this in two queries. The first to get the claims and the second to get the references based on the properties found in step one.
I didn't think if this before, but it might be easier to scrap sparql altogether and just use the mediawiki api:
https://www.wikidata.org/w/api.php?action=wbgetentities&ids=Q86591&languages=en
For getting all data about one item that might be a better approach.. Basically that is how Wikipedia reads from Wikidata in the Lua scripts used there. Would also start you down the road of being able to write back to wikidata.
Well, it lets you do up to 50 at a time:
I'd just have to do it in batches of 50 (and figure out how to make it run in the background)
For each edge, allow user to click through to references and qualifiers.