Difference between revisions of "Module:IPAc-en/data"
Jump to navigation
Jump to search
blackwiki>Mr. Stradivarius (check for pronunciation key dupes) |
blackwiki>Mr. Stradivarius (update with new data module name) |
||
| Line 3: | Line 3: | ||
local PRONUNCIATION_MODULE = 'Module:IPAc-en/pronunciation' | local PRONUNCIATION_MODULE = 'Module:IPAc-en/pronunciation' | ||
| − | local | + | local PHONEME_MODULE = 'Module:IPAc-en/phonemes' |
local function makeData(oldData) | local function makeData(oldData) | ||
| Line 26: | Line 26: | ||
local function main() | local function main() | ||
local pronunciation = makeData(require(PRONUNCIATION_MODULE)) | local pronunciation = makeData(require(PRONUNCIATION_MODULE)) | ||
| − | local | + | local phonemes = makeData(require(PHONEME_MODULE)) |
| − | -- Check that no pronunciation keys are also contained in the | + | -- Check that no pronunciation keys are also contained in the phonemes |
-- data. This would cause silent, hard-to-debug errors if it went | -- data. This would cause silent, hard-to-debug errors if it went | ||
-- unchecked, so make it cause a big red error message instead. | -- unchecked, so make it cause a big red error message instead. | ||
for id in pairs(pronunciation) do | for id in pairs(pronunciation) do | ||
| − | if | + | if phonemes[id] then |
error(string.format( | error(string.format( | ||
"duplicate ID '%s' found in %s and %s", | "duplicate ID '%s' found in %s and %s", | ||
id, | id, | ||
PRONUNCIATION_MODULE, | PRONUNCIATION_MODULE, | ||
| − | + | PHONEME_MODULE | |
)) | )) | ||
end | end | ||
| Line 44: | Line 44: | ||
return { | return { | ||
pronunciation = pronunciation, | pronunciation = pronunciation, | ||
| − | + | phonemes = phonemes, | |
} | } | ||
end | end | ||
return main() | return main() | ||
Revision as of 09:06, 17 June 2015
| 40x40px | This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
-- This module processes data for [[Module:IPAc-en]]. It is intended to be
-- loaded with mw.loadData.
local PRONUNCIATION_MODULE = 'Module:IPAc-en/pronunciation'
local PHONEME_MODULE = 'Module:IPAc-en/phonemes'
local function makeData(oldData)
local newData = {}
for id, old in pairs(oldData) do
local new = {}
for k, v in pairs(old) do
if k ~= 'aliases' then
new[k] = v
end
end
newData[id] = new
if old.aliases then
for i, alias in ipairs(old.aliases) do
newData[alias] = new
end
end
end
return newData
end
local function main()
local pronunciation = makeData(require(PRONUNCIATION_MODULE))
local phonemes = makeData(require(PHONEME_MODULE))
-- Check that no pronunciation keys are also contained in the phonemes
-- data. This would cause silent, hard-to-debug errors if it went
-- unchecked, so make it cause a big red error message instead.
for id in pairs(pronunciation) do
if phonemes[id] then
error(string.format(
"duplicate ID '%s' found in %s and %s",
id,
PRONUNCIATION_MODULE,
PHONEME_MODULE
))
end
end
return {
pronunciation = pronunciation,
phonemes = phonemes,
}
end
return main()