Lifemap-ToL / lifemap-back

Lifemap infrastructure and builder.
GNU General Public License v3.0
0 stars 0 forks source link

Wikidata query to get other species identifiers #15

Open juba opened 1 month ago

juba commented 1 month ago

Should be a double query:

See what identifiers to get back.

See also #6

juba commented 1 month ago

Query template for querying taxid + sciname. Problem: it can yield wrong results if duplicated scinames.

SELECT DISTINCT * WHERE {
{SELECT ?gbifID ?otolID ?wormsID WHERE {
  ?species wdt:P685 "40".
  OPTIONAL { ?species wdt:P846 ?gbifID. }
  OPTIONAL { ?species wdt:P9157 ?otolID. }
  OPTIONAL { ?species wdt:P850 ?wormsID. }
}}
UNION {
SELECT DISTINCT ?gbifID ?otolID ?wormsID  WHERE {
  ?species ?label "Stigmatella"@en.  
  OPTIONAL { ?species wdt:P846 ?gbifID. }
  OPTIONAL { ?species wdt:P9157 ?otolID. }
  OPTIONAL { ?species wdt:P850 ?wormsID. } 
}}}

Example for Stigmatella

Simpler template only querying taxid:

SELECT ?gbifID ?otolID ?wormsID WHERE {
  ?species wdt:P685 "40".
  OPTIONAL { ?species wdt:P846 ?gbifID. }
  OPTIONAL { ?species wdt:P9157 ?otolID. }
  OPTIONAL { ?species wdt:P850 ?wormsID. }
}

Example for Stigmatella

juba commented 1 month ago

It seems better not to query on sciname to avoid wrong results.

More complete query (here for 9615, canis lupus familiaris):

SELECT ?item ?ncbi ?gbifID ?opentolID ?wormsID ?inaturalistID ?catalogueOfLifeID ?iucn ?iucnStatus WHERE {
  ?item wdt:P685 "9615".
  OPTIONAL { ?item wdt:P685 ?ncbi. }  
  OPTIONAL { ?item wdt:P846 ?gbifID. }
  OPTIONAL { ?item wdt:P9157 ?opentolID. }
  OPTIONAL { ?item wdt:P850 ?wormsID. }
  OPTIONAL { ?item wdt:P3151 ?inaturalistID. } 
  OPTIONAL { ?item wdt:P10585 ?catalogueOfLifeID. } 
  OPTIONAL { ?item wdt:P627 ?iucn. }   
  OPTIONAL { ?item wdt:P141 ?iucnStatus. } 
}

Example for canis lupus

Note: this query can return several rows, as this example illustrates. There are two wikidata entries associated to taxid 9609: Canis familiaris and Canis lupus familiaris.