Difference between revisions of "Module:IPAc-en/data"

From blackwiki
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 TOOLTIP_MODULE = 'Module:IPAc-en/tooltips'
+
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 tooltips = makeData(require(TOOLTIP_MODULE))
+
local phonemes = makeData(require(PHONEME_MODULE))
  
-- Check that no pronunciation keys are also contained in the tooltips
+
-- 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 tooltips[id] then
+
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,
TOOLTIP_MODULE
+
PHONEME_MODULE
 
))
 
))
 
end
 
end
Line 44: Line 44:
 
return {
 
return {
 
pronunciation = pronunciation,
 
pronunciation = pronunciation,
tooltips = tooltips,
+
phonemes = phonemes,
 
}
 
}
 
end
 
end
  
 
return main()
 
return main()

Revision as of 09:06, 17 June 2015


-- 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()