using the above Westpark example, which is entity Q100256456 (https://www.wikidata.org/wiki/Q100256456), i think you would just hit https://www.wikidata.org/w/api.php?action=wbgetentities&ids=Q100256456&props=sitelinks&format=json, which returns:
{
"entities": {
"Q100256456": {
"type": "item",
"id": "Q100256456",
"sitelinks": {
"commonswiki": {
"site": "commonswiki",
"title": "Category:Westpark (Groningen)",
"badges": []
},
"nlwiki": {
"site": "nlwiki",
"title": "Westpark (Groningen)",
"badges": []
}
}
}
},
"success": 1
}
from that, you could get the “title” from “nlwiki” to build a link to https://nl.wikipedia.org/wiki/Westpark_(Groningen). (you’d have to pick the right Wikipedia instance to match the preferred location, if there are articles for multiple Wikipedia instances.)
if you need to look up the Wikidata entity ID based on the iNaturalist place ID (160964), then the query would be something like this:
SELECT ?item ?itemLabel ?iNatPlace {
?item wdt:P7471 ?iNatPlace .
FILTER (?iNatPlace in ("160964"))
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
}
see https://query.wikidata.org/#SELECT%20%3Fitem%20%3FitemLabel%20%3FiNatPlace%20{ %20%20%3Fitem%20wdt%3AP7471%20%3FiNatPlace%20. %20%20FILTER%20(%3FiNatPlace%20in%20("160964")) %20%20SERVICE%20wikibase%3Alabel%20{%20bd%3AserviceParam%20wikibase%3Alanguage%20"[AUTO_LANGUAGE]%2Cen"%20} } for more options on how to connect this to Ruby or other languages. just for ease of reference, this is what that page recommends for Ruby code to display the results of the above sparql query:
#gem install sparql
#http://www.rubydoc.info/github/ruby-rdf/sparql/frames
require 'sparql/client'
endpoint = "https://query.wikidata.org/sparql"
sparql = <<'SPARQL'.chop
SELECT ?item ?itemLabel ?iNatPlace {
?item wdt:P7471 ?iNatPlace .
FILTER (?iNatPlace in ("160964"))
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
}
SPARQL
client = SPARQL::Client.new(endpoint,
:method => :get,
# TODO adjust user agent; see https://w.wiki/CX6
headers: {'User-Agent' => 'WDQS-example Ruby'})
rows = client.query(sparql)
puts "Number of rows: #{rows.size}"
for row in rows
for key,val in row do
# print "#{key.to_s.ljust(10)}: #{val}\t"
print "#{key}: #{val}\t"
end
print "\n"
end