Module:EUPP seats/config
Appearance
--[[--------------------------< S E T T I N G S >--------------------------------------------------------------
settings definitions for i18n; translate only the rvalues
]]
local settings_t = {
template_name = 'EUPP seats', -- name of the template that #invokes this module
err_category = 'Articles with EUPP seats errors', -- name of category that lists article with EUPP seats errors
help = 'help' -- help link display text for error messages
}
--[[--------------------------< E R R O R _ M E S S A G E S _ T >----------------------------------------------
error message definitions for i18n; translate only the rvalues
]]
local error_messages_t = {
thisparty = 'not called from the page of a European party', -- misapplied 'thisparty' keyword
inst_unknown_party = 'institution $1 has unknown party: $2', -- $1 is institution; $2 is party
missing_inst = 'institution is required', -- first positional parameter is always required
party_req = 'party is required', -- for those cases when party is missing when required
party_req_share = 'party is required for share', -- for those cases when party is missing when required because share is called
unknown_inst = 'unknown institution: $1', -- $1 is content of first positional parameter (should be institution abbrev)
unknown_party = 'unknown party: $1', -- $1 is content of second positional parameter (should be party abbrev)
unknown_house_type = 'unknown house type: $1', -- $1 is content of second positional parameter (should be accepted house types)
unknown_param = 'unknown parameter: $1', -- $1 is content of third positional parameter; not '%' or 'share'
parameter_invalid = 'parameter invalid: $1',
percentage_invalid = 'percentage invalid: $1', -- $1 is content of fourth positional parameter; not 'yes' or 'pc=yes'
reference_invalid = 'reference invalid: $1', -- $1 is content of fifth positional parameter; not 'yes' or 'ref=yes'
}
--[[--------------------------< W I K I D A T A M A P P I N G >----------------------------------------------
do not translate these. These tables map abbreviations use in the template/module call to wikidata qids
]]
local institutions_t = { -- map institution abbreviation to wikidata qid
COR = 'Q205203', -- European Committee of the Regions
EC = 'Q8880', -- European Commission
EP = 'Q8889', -- European Parliament
EUCO = 'Q8886' -- European Council
}
local parties_t = { -- map party abbreviation to wikidata qid
ALDE = 'Q25079', -- Alliance of Liberals and Democrats for Europe Party
ECPM = 'Q1377279', -- European Christian Political Movement
ECR = 'Q1577483', -- European Conservatives and Reformists
EDP = 'Q734792', -- European Democratic Party
EFA = 'Q639383', -- European Free Alliance
EGP = 'Q950179', -- European Green Party
EL = 'Q202649', -- Party of the European Left
ELA = 'Q130219314', -- European Left Alliance for the People and the Planet
EPP = 'Q208242', -- European People's Party
ESN = 'Q130269264', -- Europe of Sovereign Nations
PATRIOTS = 'Q18907386', -- Patriots.eu
PES = 'Q220945' -- Party of European Socialists
}
local alliances_t = { -- map alliances abbreviation to wikidata qid
VOLT = 'Q55229798', -- Volt Europa
DIEM25 = 'Q22674451', -- Democracy in Movement 2025
PIRATES = 'Q15081858', -- European Pirate Party
ANIMAL = 'Q22079847', -- Animal Politics EU
ECA = 'Q123785828', -- European Communist Action
}
local misc_parties_t = {
IND = 'Q327591', -- independent politicians on the European Council
}
local body_prop_t = {
COR = 'P194', -- legislative body
EC = 'P208', -- executive body
EP = 'P194',
EUCO = 'P208'
}
--[[--------------------------< K E Y W O R D S >--------------------------------------------------------------
do not translate these. this table lists all known keywords that may appear in the party (2nd) positional parameter
]]
local keywords_t = {
ALL = true, -- seats of all European parties combined
NONE = true, -- seats not occupied by European parties
THISPARTY = true, -- for use when module is called from the page of a European party
}
local keywords_lower_upper_t = {
ALL = true, -- seats of all European parties combined
THISPARTY = true, -- for use when module is called from the page of a European party
}
--[[--------------------------< B U I L D _ T A B _ D A T A >--------------------------------------------------
this module uses tabular data files from commons. This function builds a sequence of associative tables for
the tabular data file named in <file_name>.
this function extracts two 'sections' from the tabular data files: column names and row data. Every row data
item is indexed by the associated column name
]]
local function build_tab_data (file_name)
local data_raw_t = mw.ext.data.get (file_name); -- get the tabular data from <file_name>
local column_heads_t = data_raw_t.schema.fields; -- point to the column headings sequence
local rows_t = data_raw_t.data; -- point to the data sequence
local out_data_t = {};
for _, row_t in ipairs (rows_t) do -- for each data row in the <rows_t> sequence
local row_data_t = {}; -- make a new associative table of row with column headings as indexes
for i=1, #column_heads_t do -- done this way because some data cells in <data_raw_t> may be nil (which would stop ipairs() loop)
row_data_t[column_heads_t[i].name] = row_t[i]; -- make a table entry
end
row_data_t.european_party = row_data_t.european_party:upper(); -- ensure <european_party> values are always uppercase
table.insert (out_data_t, row_data_t); -- done; add this table to the output sequence
end
return out_data_t; -- all data added; done
end
local tab_data_t = build_tab_data ('Seats of EU national parties in lower and upper houses.tab');
--[[--------------------------< E X T R A C T _ M S _ D A T A >------------------------------------------------
extracts member state upper/lower house names and associated qids from <tab_data_t>
Source data has multiple copies of the required data; we'll take only on copy of each.
]]
local function extract_ms_data ()
local raw_data_t = {}; -- raw, unordered data go here
for i, row_t in ipairs (tab_data_t) do -- for each row in the source data
if not raw_data_t[row_t.member_state] then -- if the source data are already in <raw_data_t> then skip to the next source data row
raw_data_t[row_t.member_state] = { -- otherwise add these data from the current source data row
member_state = row_t.member_state,
lower_house = row_t.lower_house,
lower_house_qid = row_t.lower_house_qid,
upper_house = row_t.upper_house,
upper_house_qid = row_t.upper_house_qid
};
end
end
local out_data_t = {}; -- final output will go here
for ms, house_data_t in pairs (raw_data_t) do -- create a sortable sequence
table.insert (out_data_t, house_data_t);
end
table.sort (out_data_t, function (a_t, b_t) -- custom ascending sort on member state name
return a_t.member_state < b_t.member_state;
end
);
return out_data_t; -- and done
end
--[[--------------------------< I N V E R T _ Q I D _ M A P >--------------------------------------------------
invert the contents of <in_data_t> so that qid indexes (maps to) the abbreviation; used to invert <parties_t>
and <aliances_t>
]]
local function invert_qid_map (in_data_t)
local out_data_t = {}; -- inverted data go here
for p, q in pairs (in_data_t) do -- for each party/qid pair in <parties_t> table
out_data_t[q] = p; -- swap party/qid to qid/party into <out_data_t> table
end
return out_data_t; -- all done
end
--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]
return {
error_messages_t = error_messages_t, -- these are translatable
settings_t = settings_t,
alliances_t = alliances_t, -- these must not be translated
body_prop_t = body_prop_t,
institutions_t = institutions_t,
keywords_t = keywords_t,
keywords_lower_upper_t = keywords_lower_upper_t,
misc_parties_t = misc_parties_t,
parties_t = parties_t,
rev_parties_t = invert_qid_map (parties_t),
rev_alliances_t = invert_qid_map (alliances_t),
tab_data_t = tab_data_t;
ms_data_t = extract_ms_data();
}