local id = args.id or frame:preprocess('{{BASEPAGENAME}}')
if args.lang then
p.setLang(args.lang)
end
entity = d.getEntityFromId(id)
if not entity then
return error('Entity not found')
end
addcat('All Properties')
addcat('Properties with ' .. entity.datatype .. '-datatype')
end
function p.links(args)
local forQualifierUse = false
-- todo: use property constraints
if entity.claims and entity.claims.P31 then
for _, statement in ipairs(entity.claims.P31) do
if d.getmainid(statement) == 'Q15720608' then
forQualifierUse = true
break
end
end
end
local id = entity.id
local lang = p.getLang()
local queries = {}
local linkText, linkURL
if not forQualifierUse then
linkText = translate("basic item query")
linkURL = "https://query.wikidata.org/#PREFIX%20wd%3A%20%3Chttp%3A%2F%2Fwww.wikidata.org%2Fentity%2F%3E%0APREFIX%20wdt%3A%20%3Chttp%3A%2F%2Fwww.wikidata.org%2Fprop%2Fdirect%2F%3E%0APREFIX%20wikibase%3A%20%3Chttp%3A%2F%2Fwikiba.se%2Fontology%23%3E%0APREFIX%20p%3A%20%3Chttp%3A%2F%2Fwww.wikidata.org%2Fprop%2F%3E%0APREFIX%20ps%3A%20%3Chttp%3A%2F%2Fwww.wikidata.org%2Fprop%2Fstatement%2F%3E%0APREFIX%20pq%3A%20%3Chttp%3A%2F%2Fwww.wikidata.org%2Fprop%2Fqualifier%2F%3E%0APREFIX%20rdfs%3A%20%3Chttp%3A%2F%2Fwww.w3.org%2F2000%2F01%2Frdf-schema%23%3E%0A%23Sample%20query%20to%20start%20a%20list%20of%20values%20for%20property%20" .. id .. "%0A%23Remove%20some%20of%20the%20%22%23%22%20below%20to%20see%20if%20it%20helps%20you%0A%0ASELECT%20%3Fitem%20%3FitemLabel%20%3Fvalue%20%3FvalueLabel%20%0A%23sample%20variables%20defined%20below%20%28but%20commented%20out%29%0A%3Fdob%20%3Fdod%20%3Fcountry%0AWHERE%0A{%0A%09%3Fitem%20wdt%3A" .. id .. "%20%3Fvalue%20.%0A%23%09%3Fitem%20wdt%3AP569%20%3Fdob%20.%20%0A%23%09OPTIONAL%20{%3Fitem%20wdt%3AP570%20%3Fdod%20}%20.%20%0A%23%09%3Fitem%20wdt%3AP17%20%3Fcountry%20.%20%0A%09SERVICE%20wikibase%3Alabel%20{%20bd%3AserviceParam%20wikibase%3Alanguage%20%22" .. lang .. "%2Cen%22%20%20}%20%20%20%20%0A}%0ALIMIT%2010"
( entity.datatype == "wikibase-item" and "%20%3FvalueLabel" or "" ) .. -- Only include "?valueLabel" if property has datatype wikibase-item
"%0A{%0A%09%3Fitem%20wdt%3A" .. id .. "%20%3Fvalue%20.%0A%09SERVICE%20wikibase%3Alabel%20{%20bd%3AserviceParam%20wikibase%3Alanguage%20%22" .. lang .. "%2Cen%22%20%20}%20%20%20%20%0A}%0ALIMIT%201000"
linkURL = "https://query.wikidata.org/#%23top%2050%20for%20P31%20and%20P279%20of%20items%20using%20" .. id .. "%0ASELECT%20%3Fclass%20%3FclassLabel%20%3Fcount%20%3Fuse_as_Label%0A{%09{%09SELECT%20%3Fclass%20%28COUNT%28*%29%20AS%20%3Fcount%29%20%28wd%3AP31%20as%20%3Fuse_as_%29%0A%09%09{%09%3Fa%09wdt%3A" .. id .. "%09%3Fp%09%3B%20wdt%3AP31%09%3Fclass}%0A%20%20%20%20%20%20%20%20GROUP%20BY%20%3Fclass%20ORDER%20BY%20DESC%28%3Fcount%29%20LIMIT%2050%0A%20%20%09}%0A%20%20%09UNION%0A%09{%09SELECT%20%3Fclass%20%28COUNT%28*%29%20AS%20%3Fcount%29%20%28wd%3AP279%20as%20%3Fuse_as_%29%0A%09%09{%09%3Fa%09wdt%3A" .. id .. "%09%3Fp%09%3B%20wdt%3AP279%09%3Fclass}%0A%20%20%20%20%20%20%20%20GROUP%20BY%20%3Fclass%20ORDER%20BY%20DESC%28%3Fcount%29%20LIMIT%2050%0A%20%20%09}%0A%20%20%09SERVICE%20wikibase%3Alabel%20{%20bd%3AserviceParam%20wikibase%3Alanguage%20%22" .. lang .. "%2Cen%22%20}%0A}%0AORDER%20BY%20DESC%28%3Fcount%29%20%3Fclass"
linkURL = "https://query.wikidata.org/#PREFIX%20wd%3A%20%3Chttp%3A%2F%2Fwww.wikidata.org%2Fentity%2F%3E%0APREFIX%20wdt%3A%20%3Chttp%3A%2F%2Fwww.wikidata.org%2Fprop%2Fdirect%2F%3E%0APREFIX%20wikibase%3A%20%3Chttp%3A%2F%2Fwikiba.se%2Fontology%23%3E%0APREFIX%20p%3A%20%3Chttp%3A%2F%2Fwww.wikidata.org%2Fprop%2F%3E%0APREFIX%20ps%3A%20%3Chttp%3A%2F%2Fwww.wikidata.org%2Fprop%2Fstatement%2F%3E%0APREFIX%20pq%3A%20%3Chttp%3A%2F%2Fwww.wikidata.org%2Fprop%2Fqualifier%2F%3E%0APREFIX%20rdfs%3A%20%3Chttp%3A%2F%2Fwww.w3.org%2F2000%2F01%2Frdf-schema%23%3E%0A%23Sample%20query%20to%20start%20a%20list%20of%20statements%20using%20the%20qualifer%20" .. id .. "%0A%0ASELECT%20%3Fitem%20%3FitemLabel%20%3Fproperty%20%3FpropertyLabel%20%3Fvalue%20%3FvalueLabel%20%3Fqualifier" .. id .. "value%0AWHERE%0A{%0A%20%20%20%20%3Fprop%20pq%3A" .. id .. "%20%3Fqualifier" .. id .. "value%20.%0A%20%20%09hint%3AQuery%20hint%3Aoptimizer%20%22None%22%20.%09%0A%09%3Fitem%20%3Fp%20%3Fprop%20.%20%0A%09%3Fproperty%20wikibase%3Aclaim%20%3Fp%20.%20%20%0A%20%20%09%3Fproperty%20wikibase%3AstatementProperty%20%3Fps%20.%0A%20%20%20%20%3Fprop%20%3Fps%20%3Fvalue%20.%20%20%20%20%20%20%0A%0A%09SERVICE%20wikibase%3Alabel%20{%20bd%3AserviceParam%20wikibase%3Alanguage%20%22" .. lang .. "%2Cen%22%20%20}%20%20%20%20%0A}%0ALIMIT%2020"
linkText = translate("properties using this qualifier")
linkURL = "https://query.wikidata.org/#%23Number%20of%20items%2Fstatements%20using%20qualifer%20" .. id .. "%20for%20each%20property%0A%23added%202016-02-24%20by%20Jura1%20%0A%0ASELECT%20%3Fproperty%20%3FpropertyLabel%20%3Fitems%20%3Fstatements%0AWHERE%0A{%0A%09{%0A%09%09SELECT%20%3Fproperty%20%28COUNT%28DISTINCT%28%3Fitem%29%29%20as%20%3Fitems%29%20%28COUNT%28%3Fvalue%29%20as%20%3Fstatements%29%0A%09%09WHERE%0A%09%09{%0A%20%20%20%20%09%09%3Fprop%20pq%3A" .. id .. "%20%3Fqualifier" .. id .. "value%20.%0A%20%20%09%09%09hint%3AQuery%20hint%3Aoptimizer%20%22None%22%20.%09%0A%09%09%09%3Fitem%20%3Fp%20%3Fprop%20.%20%0A%09%09%09%3Fproperty%20wikibase%3Aclaim%20%3Fp%20.%20%20%0A%20%20%09%09%09%3Fproperty%20wikibase%3AstatementProperty%20%3Fps%20.%0A%20%20%20%20%09%09%3Fprop%20%3Fps%20%3Fvalue%20.%20%20%20%20%20%20%0A%09%09}%0A%09%09GROUP%20BY%20%3Fproperty%20%0A%09%09ORDER%20BY%20DESC%28%3Fitems%29%20DESC%28%3Fstatements%29%0A%09%09LIMIT%2025%0A%09}%0A%09SERVICE%20wikibase%3Alabel%20{%20bd%3AserviceParam%20wikibase%3Alanguage%20%22en%2Cen%22%20%20}%20%20%20%20%0A}%0AORDER%20BY%20DESC%28%3Fitems%29%20DESC%28%3Fstatements%29%0A%0A%0A"
linkURL = "https://query.wikidata.org/#%23Uses%20of%20" .. id .. "%3A%09as%20property%20%28any%20rank%2Fbest%20rank%29.%20For%20performance%20reasons%2C%20detailed%20counts%20by%20rank%20are%20not%20included.%0A%23%09%09%09%09as%20qualifier%0A%23%09%09%09%09in%20references%0A%23by%20Jura1%2C%20rev%202016-03-03%0ASELECT%09%3Fuse%20%3Frank%20%3Fitems_with_property%09%3Fuses_of_property%0AWHERE{%09{%09%09SELECT%20%09%28wikibase%3AstatementProperty%20as%20%3Fuse%29%09%28COUNT%28DISTINCT%28%3Fitem%29%29%20as%20%3Fitems_with_property%29%09%28COUNT%28%3Fvalue%29%20as%20%3Fuses_of_property%29%0A%09%09%09%09WHERE%09{%3Fitem%20p%3A" .. id .. "%20%3Fvalue}}%0AUNION%09{%09%09SELECT%20%09%28wikibase%3AstatementProperty%20as%20%3Fuse%29%09%28wikibase%3ABestRank%20as%20%3Frank%29%09%28COUNT%28DISTINCT%28%3Fitem%29%29%09as%20%3Fitems_with_property%29%09%28COUNT%28%3Fbestvalue%29%20as%20%3Fuses_of_property%29%0A%20%20%20%20%20%09%09%09WHERE%20%09{%3Fitem%20wdt%3A" .. id .. "%20%3Fbestvalue%20}%20}%0AUNION%09{%09%09SELECT%20%09%28wikibase%3Areference%20as%20%3Fuse%29%09%09%09%28COUNT%28DISTINCT%28%3Fitem%29%29%20as%20%3Fitems_with_property%29%09%28COUNT%28%3Fvalue%29%20as%20%3Fuses_of_property%29%0A%20%20%20%20%20%09%09%09WHERE%20%09{%3Fitem%20pr%3A" .. id .. "%20%3Fvalue%20}}%0AUNION%09{%09%09SELECT%20%09%28wikibase%3Aqualifier%20as%20%3Fuse%29%09%09%09%28COUNT%28DISTINCT%28%3Fitem%29%29%20as%20%3Fitems_with_property%29%09%28COUNT%28%3Fvalue%29%20as%20%3Fuses_of_property%29%0A%20%20%20%20%20%09%09%09WHERE%20%09{%3Fitem%20pq%3A" .. id .. "%20%3Fvalue%20}}%0A}%0AORDER%20BY%20DESC%28%3Fuse%29%20DESC%28%3Fitems_with_property%29%20%3Frank%0A%0A%23PLEASE%20NOTE%3A%20Deleted%20items%20appear%20in%20counts%20for%20some%20ranks%2C%20but%20not%20in%20others."
else
linkURL = "https://query.wikidata.org/#%23Uses%20of%20" .. id .. "%3A%09as%20property%20%28any%20rank%2Fbest%20rank%2Fnormal%20rank%2Fpreferred%20rank%2Fdeprecated%20rank%29%0A%23%09%09%09%09as%20qualifier%0A%23%09%09%09%09in%20references%0A%23by%20Jura1%2C%20rev%202016-03-03%0ASELECT%09%3Fuse%20%3Frank%20%3Fitems_with_property%09%3Fuses_of_property%0AWHERE{%09{%09%09SELECT%20%09%28wikibase%3AstatementProperty%20as%20%3Fuse%29%09%28COUNT%28DISTINCT%28%3Fitem%29%29%20as%20%3Fitems_with_property%29%09%28COUNT%28%3Fvalue%29%20as%20%3Fuses_of_property%29%0A%09%09%09%09WHERE%09{%3Fitem%20p%3A" .. id .. "%20%3Fvalue}}%0AUNION%09{%09%09SELECT%20%09%28wikibase%3AstatementProperty%20as%20%3Fuse%29%09%28wikibase%3ABestRank%20as%20%3Frank%29%09%28COUNT%28DISTINCT%28%3Fitem%29%29%09as%20%3Fitems_with_property%29%09%28COUNT%28%3Fbestvalue%29%20as%20%3Fuses_of_property%29%0A%20%20%20%20%20%09%09%09WHERE%20%09{%3Fitem%20wdt%3A" .. id .. "%20%3Fbestvalue%20}%20}%0AUNION%20%09{%09%09SELECT%20%20%28wikibase%3AstatementProperty%20as%20%3Fuse%29%09%3Frank%09%28COUNT%28DISTINCT%28%3Fitem%29%29%20as%20%3Fitems_with_property%29%09%28COUNT%28%28%3Fstatement%29%29%20as%20%3Fuses_of_property%29%20%0A%09%09%09%09WHERE%09{%3Fitem%20p%3A" .. id .. "%20%3Fstatement%20.%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Fstatement%20wikibase%3Arank%20%3Frank%20}%0A%09%09%09%09%09%09GROUP%20BY%20%3Frank%20}%0AUNION%09{%09%09SELECT%20%09%28wikibase%3Areference%20as%20%3Fuse%29%09%09%09%28COUNT%28DISTINCT%28%3Fitem%29%29%20as%20%3Fitems_with_property%29%09%28COUNT%28%3Fvalue%29%20as%20%3Fuses_of_property%29%0A%20%20%20%20%20%09%09%09WHERE%20%09{%3Fitem%20pr%3A" .. id .. "%20%3Fvalue%20}}%0AUNION%09{%09%09SELECT%20%09%28wikibase%3Aqualifier%20as%20%3Fuse%29%09%09%09%28COUNT%28DISTINCT%28%3Fitem%29%29%20as%20%3Fitems_with_property%29%09%28COUNT%28%3Fvalue%29%20as%20%3Fuses_of_property%29%0A%20%20%20%20%20%09%09%09WHERE%20%09{%3Fitem%20pq%3A" .. id .. "%20%3Fvalue%20}}%0A}%0AORDER%20BY%20DESC%28%3Fuse%29%20DESC%28%3Fitems_with_property%29%20%3Frank%0A%0A%23PLEASE%20NOTE%3A%20Deleted%20items%20appear%20in%20counts%20for%20some%20ranks%2C%20but%20not%20in%20others."