Module:Person
From Eli's Software Encyclopedia
Documentation for this module may be created at Module:Person/doc
local utils = require('Module:Utils')
local p = {}
local function getISOdate( txt )
if not txt or txt == '' then
return
end
local iso
iso = string.match(txt, "%((%d%d%d%d%-%d%d%-%d%d)%)") -- (YYYY-MM-DD)
or string.match(txt, "(%d%d%d%d%-%d%d%-%d%d)") -- YYYY-MM-DD
if not iso then
iso = string.match(txt, "%((%d%d%d%d%-%d%d)%)") -- (YYYY-MM)
or string.match(txt, "(%d%d%d%d%-%d%d)") -- YYYY-MM
end
if not iso then
local mon, yr = string.match(txt, "([A-Za-z]+)%s+(%d%d%d%d)")
if mon and yr then
local mnum = month_name_to_num(mon)
if mnum then iso = yr .. "-" .. mnum end
end
end
if not iso then
iso = string.match(txt, "(%d%d%d%d)")
end
return iso
end
function p.semanticStore(frame)
local titleObj = mw.title.getCurrentTitle()
local args = frame:getParent().args or {}
-- Get and normalize parameter values
local title = args['name'] or args['Name'] or args['title'] or titleObj.text
local image = args['image'] or args['photo'] or args['Photo'] or ''
local imageFilename, imageAlt, imageCaption = '', '', ''
if image ~= '' then
local fn, alt = utils.parseFileLink(image)
if fn then
imageFilename = fn
imageAlt = alt or args['caption'] or args['Caption'] or ''
else
imageFilename = frame:preprocess('{{PAGENAME:' .. image .. '}}')
end
imageCaption = args['caption'] or args['Caption'] or ''
end
local birth_name = args['birth_name'] or title or ''
local birth_date = getISOdate(args['birth_date']) or ''
local birth_place = args['birth_place'] or ''
local death_date = getISOdate(args['death_date']) or ''
local death_place = args['death_place'] or ''
local death_cause = args['death_cause'] or ''
local body_discovered = args['body_discovered'] or ''
local resting_place = args['resting_place'] or ''
local resting_place_coordinates = args['resting_place_coordinates'] or ''
local residence = args['residence'] or ''
local nationality = args['nationality'] or ''
local other_names = args['other_names'] or ''
local ethnicity = args['ethnicity'] or ''
local citizenship = args['citizenship'] or ''
local education = args['education'] or ''
local alma_mater = args['alma_mater'] or ''
local occupation = args['occupation'] or ''
local years_active = args['years_active'] or ''
local employer = args['employer'] or ''
local home_town = args['home_town'] or ''
local salary = args['salary'] or ''
local networth = args['networth'] or ''
local height = args['height'] or ''
local weight = args['weight'] or ''
local known = args['known'] or args['known for'] or ''
local title = args['title'] or ''
local term = args['term'] or ''
local predecessor = args['predecessor'] or ''
local successor = args['successor'] or ''
local party = args['party'] or ''
local opponents = args['opponents'] or ''
local boards = args['boards'] or ''
local religion = args['religion'] or ''
local spouse = args['spouse'] or ''
local partner = args['partner'] or ''
local children = args['children'] or ''
local parents = args['parents'] or ''
local relations = args['relations'] or args['relatives'] or ''
local callsign = args['callsign'] or ''
local awards = args['awards'] or ''
local signature = args['signature'] or ''
local signature_alt = args['signature_alt'] or ''
local website = args['website'] or ''
local footnotes = args['footnotes'] or ''
local misc = args['misc'] or ''
-- Set properties
local data = {
'Has Title=' .. title,
'Has Image=' .. imageFilename,
'Has Image Caption=' .. imageCaption,
'Birth Name=' ..birth_name,
'Birth Date=' ..birth_date,
'Birth Place=' ..birth_place,
'Death Date=' ..death_date,
'Death Place=' ..death_place,
'Death Cause=' ..death_cause,
'Body Discovered=' ..body_discovered,
'Resting Place=' ..resting_place,
'Resting Place Coordinates=' ..resting_place_coordinates,
'Residence=' ..residence,
'Nationality=' ..nationality,
'Nickname=' ..other_names,
'+sep=,',
'Etnicity=' ..ethnicity,
'Citizenship=' ..citizenship,
'Education=' ..education,
'Alma Mater=' ..alma_mater,
'Occupation=' ..occupation,
'+sep=,',
'Years Active=' ..years_active,
'Employer=' ..employer,
'Home Town=' ..home_town,
'Salary=' ..salary,
'Networth=' ..networth,
'Height=' ..height,
'Weight=' ..weight,
'Also Is Known=' ..known,
'Job Title=' ..title,
'Period=' ..term,
'Predecessor=' ..predecessor,
'Successor=' ..successor,
'Political Party=' ..party,
'Opponent=' ..opponents,
'Board Member Of=' ..boards,
'Religious Belief=' ..religion,
'Has Spouse=' ..spouse,
'+sep=,',
'Has Partner=' ..partner,
'+sep=,',
'Has Child=' ..children,
'+sep=,',
'Has Parent=' ..parents,
'+sep=,',
'Has Relative=' ..relations,
'+sep=,',
'Has Call-Sign=' ..callsign,
'Has Award=' ..awards,
'+sep=,',
'Signature Image=' ..signature,
'Signature Image Alt=' ..signature_alt,
'Website URL=' ..website,
'Note=' ..footnotes,
'Other Info=' ..misc,
}
mw.smw.set( data )
end
return p
