Module:Propriétés

 Documentation
local p = {instance_de= "P31",    sous_classe_de = "P279",    prenom = "P735",    nomdefamille = "P734",     isbn10 = "P957",    publie_dans = "P1433",    langue = "P407" }-- this module gives solutions to get the Pnumber of a property by its name-- could be automatized, but for now just defining a muanual mappingp.p_from_name = {["country"] = 17 ;["gender"] = 21 ;["instance of"] = 31 ;["field"] = 101 ; ["occupation"] = 106 ;["genre"] = 136 ;["named after"] = 138 ;["preceded by"] = 155;["succeeded by"] = 156;["collection"] = 195;["subclass of"] = 279 ;["category's topic"] = 301;["list of"] = 360 ; ["part of"] = 361 ;["commons category"] = 373;["terminus"] = 559;["direction"] = 560;["start date"] = 580 ;["begin date"] = 580 ;["end date"] = 582 ;["date"] = 585 ;["of"] = 642 ;["participant"] = 710 ;["edition"] = 747 ;["edition of"] = 629 ;['key event'] = 793 ;['significant event'] = 793 ;["topic's category"] = 910;["subject"] = 921; -- work subject["inspired by"] = 941 ;["fictional analog of"] = 1074 ;["statement disputed by"] = 1310 ;["disputed by"] = 1310 ;["of"] = 642 ;["history"] = 2184 ;["property for this type"] = 1963 ;    ["metasubclass of"] = 2445 ;    ["number"] = 1114 ;["union of"] = 2737;["disjoint union of"] = 2738;["has part of the type"] = 2670 ;}local function string_to_propnumber(label)local res = p.p_from_name[label] ;if res ~= nil thenreturn tostring( res) ;elseres = mw.wikibase.resolvePropertyId(label)if res thenreturn string.sub(res, 2)elsereturn nilend    endendp.numberFromPropertylabel = function(frame)  local label = frame.args[1] ;mw.log(label)return string_to_propnumber(label)end;-- returns a pid of the form "Pnnn..." where n is a character in "123456789"--from either --* a number representing a property wikidata number--* a string number representing a property wikidata number--* a pid of the form "Pnnn"--* a "property name" corresponding to a property, where the names are listed in the array p.p_from_name-- or "nil" if the id does not match to any of the cases abovep.normalize = function(input_pid)local input_pid = tostring(input_pid)if mw.ustring.match(input_pid, "P%d+") thenreturn input_pidelseif mw.ustring.match(input_pid, "%d+") thenreturn "P" .. input_pidelsereturn "P" .. tostring(string_to_propnumber(input_pid))endend-- function that takes a string with a set of pids and returns an array of propertiesp.expandPropList = function(plist)local props = mw.text.split(plist,",")for ind, val in ipairs(props) doprops[ind] = p.normalize(val)endreturn propsendfunction p.datatype(property)if type(property) ~= "table" thenproperty = mw.wikibase.getEntityObject(p.normalize(property))endreturn property.datatypeend----------------------------------------------------------------- wikitemplate interface---------------------------------------------------------------p.Pid = function(frame)  local label = frame.args[1] ;return p.normalize(label)end;p.Pdatatype = function(frame)return p.datatype(frame.args[1])end;p.of = p.normalize("of")p.union_of = p.normalize("union of")p.disjoint_union_of = p.normalize("disjoint union of")return p