Module:Sandbox/ATDT/AbstractWikipedia/Renderers/en

From Meta, a Wikimedia project coordination wiki
Module documentation
local p = {}

function superlative ( by )
	-- Ok, this is cheating, but...
	if by == "number of individuals" then
		return "most populous"
	else
		error("Not implemented for " .. by)
	end
end

function ordinal ( n )
	local ordinals = {"", "second", "third", "fourth", "fifth", "sixth"}
	return ordinals[n]
end

function p.Article( args )
	return table.concat(args.content, " ")
end

function p.Instantiation( args )
	return args.instance .. " is " .. args.class .. "."
end

function p.And_modifier ( args ) 
	local conjuncts = args.conjuncts
	if #conjuncts == 1 then
		return conjuncts[1]
	elseif #conjuncts == 2 then
		return table.concat(conjuncts, " and ")
	else
		local last = table.remove(conjuncts)
		return table.concat(conjuncts, ", ") .. " and " .. last
	end
end

function p.Object_with_modifier_and_of ( args )
	local s = args.object
	if type(args.modifier) == "string" then
		s = args.modifier .. " " .. s
	end
	if type(args.of) == "string" then
		s = s .. " of " .. args.of
	end
	return "the " .. s
end

function p.Ranking ( args )
	local s = args.subject .. " is the " .. ordinal(args.rank) .. " " .. superlative(args.by) .. " " .. args.object
	if type(args.local_constraint) == "string" then
		s = s .. " in " .. args.local_constraint
	end
	if type(args.after) == "string" then
		s = s .. ", after " .. args.after
	end
	return s .. "."
end

return p