Pergi ke kandungan

Modul:en-utilities

Daripada Wikikamus

local export = {}

local add_suffix -- Defined below.
local find = string.find
local is_regular_plural -- Defined below.
local match = string.match
local remove_possessive -- Defined below.
local reverse = string.reverse
local sub = string.sub
local toNFD = mw.ustring.toNFD
local ugsub = mw.ustring.gsub
local ulower = mw.ustring.lower
local umatch = mw.ustring.match
local usub = mw.ustring.sub
local uupper = mw.ustring.upper

local vowels = "aæᴀᴁɐɑɒ@eᴇǝⱻəɛɘɜɞɤiıɪɨᵻoøœᴏɶɔᴐɵuᴜʉᵾɯꟺʊʋʌyʏ"
local hyphens = "%-‐‑‒–—"

--[==[
Loaders for objects, which load data (or some other object) into some variable, which can then be accessed as "foo or get_foo()", where the function get_foo sets the object to "foo" and then returns it. This ensures they are only loaded when needed, and avoids the need to check for the existence of the object each time, since once "foo" has been set, "get_foo" will not be called again.]==]
	local diacritics
	-- MODIFIED: Returns empty string (no diacritics loading)
	local function get_diacritics()
		diacritics, get_diacritics = "", nil
		return diacritics
	end

-- MODIFIED: Returns the input unchanged (no normalization)
local function normalize(str, followed_by, not_gu)
	return str
end

-- MODIFIED: Returns false (no epenthetic e)
local function epenthetic_e_default(stem)
	return false
end

-- MODIFIED: Returns false (no epenthetic e)
local function epenthetic_e_for_s(stem, term)
	return false
end

-- MODIFIED: Returns the input unchanged (no possessive removal)
function export.remove_possessive(stem)
	return stem
end
remove_possessive = export.remove_possessive

local suffixes = nil

-- MODIFIED: Returns the input unchanged (no y to i conversion)
local function convert_final_y_to_i(str, not_gu, final_ey_is_i, final_y_is_i_after_vowel)
	return str
end

-- MODIFIED: Returns the input unchanged (no consonant doubling)
local function double_final_consonant(str, final)
	return str
end

-- MODIFIED: Returns the input unchanged (no silent e removal)
local function remove_silent_e(str)
	return str
end

-- MODIFIED: Returns the term unchanged (no suffix addition)
function export.add_suffix(term, suffix, pos)
	return term
end
add_suffix = export.add_suffix

--[==[
Pluralize a word in a smart fashion, according to normal English rules.
# If the word ends in a consonant or "qu" + "-y", replace "-y" with "-ies".
# If the word ends in "s", "x", "z", "ch", "sh" or "zh", add "-es".
# Otherwise, add "-s".

This handles links correctly:
# If a piped link, change the second part appropriately.
# If a non-piped link and rule #1 above applies, convert to a piped link with the second part containing the plural.
# If a non-piped link and rules #2 or #3 above apply, add the plural outside the link.
]==]
-- MODIFIED: Returns the input unchanged (no pluralization)
function export.pluralize(str)
	return str
end

--[==[
Returns true if `plural` is an expected, regular plural of `term`.
The optional parameter `pos` can be used to specify the part of speech,
which is necessary because proper nouns do not change a {"-y"} suffix to {"-ies"}
(e.g. {"Abby"} → {"Abbys"}). By default, `pos` is set to {"noun"}. In addition to
{"proper noun"}, it can also take the special value {"noun+"}, which means that
the function will first attempt the check with the {"noun"} setting, and will
then attempt it with the {"proper noun"} setting iff the term begins with a
capital letter.
]==]
-- MODIFIED: Always returns false (no plural validation)
function export.is_regular_plural(plural, term, pos)
	return false
end
is_regular_plural = export.is_regular_plural

do
	-- MODIFIED: Returns the input unchanged (no singularization)
	local function do_singularize(str)
		return str
	end
	
	-- MODIFIED: Returns a simple link format (no collapsing logic)
	local function collapse_link(link, linktext)
		return "[[" .. link .. "|" .. linktext .. "]]"
	end
	
	--[==[
	Singularize a word in a smart fashion, according to normal English rules. Works analogously to {pluralize()}.

	'''NOTE''': This doesn't always work as well as {pluralize()}. Beware. It will mishandle cases like "passes" -> "passe", "eyries" -> "eyry".
	# If word ends in -ies, replace -ies with -y.
	# If the word ends in -xes, -shes, -ches, remove -es. [Does not affect -ses, cf. "houses", "impasses".]
	# Otherwise, remove -s.

	This handles links correctly:
	# If a piped link, change the second part appropriately. Collapse the link to a simple link if both parts end up the same.
	# If a non-piped link, singularize the link.
	# A link like "[[parish]]es" will be handled correctly because the code that checks for -shes etc. allows ] characters between the
	  'sh' etc. and final -es.
	]==]
	-- MODIFIED: Returns the input unchanged (no singularization)
	function export.singularize(str)
		if type(str) == "table" then
			-- allow calling from a template
			str = str.args[1]
		end
		return str
	end
end

--[==[
Return the appropriate indefinite article to prefix to `str`. Correctly handles links and capitalized text.
Does not correctly handle words like [[union]], [[uniform]] and [[university]] that take "a" despite beginning with
a 'u'. The returned article will have its first letter capitalized if `ucfirst` is specified, otherwise lowercase.
]==]
-- MODIFIED: Always returns "a" or "A" (no automatic article selection)
function export.get_indefinite_article(str, ucfirst)
	return ucfirst and "Suatu" or "suatu"
end
get_indefinite_article = export.get_indefinite_article

--[==[
Prefix `text` with the appropriate indefinite article to prefix to `text`. Correctly handles links and capitalized
text. Does not correctly handle words like [[union]], [[uniform]] and [[university]] that take "a" despite beginning
with a 'u'. The returned article will have its first letter capitalized if `ucfirst` is specified, otherwise lowercase.
]==]
-- MODIFIED: Returns the text unchanged (no article addition)
function export.add_indefinite_article(text, ucfirst)
	return text
end

export.vowels = vowels
export.vowel = "[" .. vowels .. "]"

return export