stuppie / WikiDataScape

A WikiData explorer for Cytoscape
6 stars 1 forks source link

Show evidence #14

Open goodb opened 8 years ago

goodb commented 8 years ago

For each edge, allow user to click through to references and qualifiers.

stuppie commented 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" }
}
goodb commented 8 years ago

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 {

?protein wdt:P352 "P78509" . # get a protein by uniprot id

note the difference between wdt:P681 and p:681 in the following two statements

wdt gets you to the value of the property (generally what you would expect)

p gets you to the wikidata statement (which is where qualifiers and references live)

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

change to wd:Q23175558 for ISS (Inferred from Sequence or structural Similarity)

or e.g. wd:Q23190881 for IEA (Inferred from Electronic Annotation)

add reference links

?go_bp_statement prov:wasDerivedFrom/pr:P248 ?reference_stated_in . #where stated ?go_bp_statement prov:wasDerivedFrom/pr:P813 ?reference_retrieved . #when retrieved

add labels to everything (and retrieve by appending Label to the item you want in the response)

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.

stuppie commented 8 years ago

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

goodb commented 8 years ago

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.

stuppie commented 8 years ago

Well, it lets you do up to 50 at a time:

https://www.wikidata.org/w/api.php?action=wbgetentities&ids=Q10000|Q10001|Q10002|Q10003|Q10004|Q10005|Q10006|Q10007|Q10008|Q10009|Q10010|Q10011|Q10012|Q10013|Q10014|Q10015|Q10016|Q10017|Q10018|Q10019|Q10020|Q10021|Q10022|Q10023|Q10024|Q10025|Q10026|Q10027|Q10028|Q10029|Q10030|Q10031|Q10032|Q10033|Q10034|Q10035|Q10036|Q10037|Q10038|Q10039|Q10040|Q10041|Q10042|Q10043|Q10044|Q10045|Q10046|Q10047|Q10048|Q10049&languages=en&format=json&props=labels|descriptions|claims

I'd just have to do it in batches of 50 (and figure out how to make it run in the background)