Модуль:Wikidata/safety labelling

Википеди материал

Для документации этого модуля может быть создана страница Модуль:Wikidata/safety labelling/doc

local p = {}

function p.formatNFPA704( context, options, statement )
	if (not context) then error('context is not specified') end;
	if (not options) then error('options is not specified') end;
	if (not statement) then error('statement is not specified') end;
	
	if (not statement.qualifiers) then return '' end;

	local qualifiers = {
		P993 = 'магара кхераме я',
		P994 = 'атта лоталуш я',
		P995 = 'реакционноспособность',
		P877 = 'кхыдар'
	}
	local parameters = {}
	
	options.somevalue = '?' -- TODO
	options.novalue = '-'
	for qualifier, parameter in pairs(qualifiers) do
		if statement.qualifiers[qualifier] then
			parameters[parameter] = context.formatSnak( options, statement.qualifiers[qualifier][1] )
		end
	end
	
	return options.frame:expandTemplate{ title = 'NFPA 704', args = parameters };
end

function p.formatGHSPictograms( context, options, statement )
	if (not context) then error('context is not specified') end;
	if (not options) then error('options is not specified') end;
	if (not statement) then error('statement is not specified') end;
	
	local pictograms = {
		Q51080746 = '01',
		Q51791331 = '02',
		Q51843300 = '03',
		Q51843559 = '04',
		Q51843949 = '05',
		Q51843956 = '06',
		Q51843962 = '07',
		Q51843964 = '08',
		Q51843973 = '09'
	}
	
	if statement.qualifiers and statement.qualifiers.P5040 then
		local codes = {}
		for _, snak in pairs(statement.qualifiers.P5040) do
			if snak.datavalue then
				table.insert(codes, pictograms[snak.datavalue.value.id] or '') -- TODO
			end
		end
		return options.frame:expandTemplate{ title = 'Пиктограммы СГС', args = codes }; 
	else
		return ''
	end
end

function p.formatGHSWord( context, options, statement )
	if (not context) then error('context is not specified') end;
	if (not options) then error('options is not specified') end;
	if (not statement) then error('statement is not specified') end;

	local words = {
		Q15221217 = 'опасно',
		Q15350847 = 'осторожно'
	}

	if statement.qualifiers and statement.qualifiers.P1033 and statement.qualifiers.P1033[1].datavalue then
		return words[statement.qualifiers.P1033[1].datavalue.value.id] or '' -- TODO
	else
		return ''
	end
end	

function p.formatGHSHStatements( context, options, statement )
	if (not context) then error('context is not specified') end;
	if (not options) then error('options is not specified') end;
	if (not statement) then error('statement is not specified') end;
	
	if statement.qualifiers and statement.qualifiers.P5041 then
		local hPhrases = {}
		for _, snak in pairs(statement.qualifiers.P5041) do
			if snak.datavalue then
				table.insert(hPhrases, mw.wikibase.label(snak.datavalue.value.id)) -- TODO
			end
		end
		return options.frame:expandTemplate{ title = 'H-фразы', args = hPhrases }; 
	else
		return ''
	end
end

function p.formatGHSPStatements( context, options, statement )
	if (not context) then error('context is not specified') end;
	if (not options) then error('options is not specified') end;
	if (not statement) then error('statement is not specified') end;
	
	if statement.qualifiers and statement.qualifiers.P5042 then
		local pPhrases = {}
		for _, snak in pairs(statement.qualifiers.P5042) do
			if snak.datavalue then
				table.insert(pPhrases, mw.wikibase.label(snak.datavalue.value.id)) -- TODO
			end
		end
		return options.frame:expandTemplate{ title = 'P-фразы', args = pPhrases }; 
	else
		return ''
	end
end

return p