Module:A or an and Module:A or an/sandbox: Difference between pages
Appearance
(Difference between pages)
Content deleted Content added
mNo edit summary |
No edit summary |
||
Line 5: | Line 5: | ||
local ucVvChars = 'AEFHILMNORSXÀ-ÆÈ-ÏÒ-ÖØĀĂĄĒĔĖĘĚĨĪĬĮıIJŌŎŐŒÑĤĦĹĻĽĿŁŃŅŇŊŔŖŘŚŜŞ' |
local ucVvChars = 'AEFHILMNORSXÀ-ÆÈ-ÏÒ-ÖØĀĂĄĒĔĖĘĚĨĪĬĮıIJŌŎŐŒÑĤĦĹĻĽĿŁŃŅŇŊŔŖŘŚŜŞ' |
||
local |
local article = { |
||
a = "a", |
|||
⚫ | |||
an = "an", |
|||
⚫ | |||
} |
|||
local function findWord(text, array) |
|||
⚫ | |||
⚫ | |||
return true |
return true |
||
end |
end |
||
end |
end |
||
⚫ | |||
local function get_article_from_acronym(text) |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
return article.an |
|||
⚫ | |||
return article.a |
|||
end |
|||
local function get_article_from_number_word(text) |
|||
⚫ | |||
⚫ | |||
return article.an |
|||
end |
|||
return article.a |
|||
end |
|||
local function clean_text(text) |
|||
⚫ | |||
text = mw.ustring.gsub(text, '%[%[[^%|]+%|(..-)%]%]', '%1') -- Remove wikilinks |
|||
text = mw.ustring.gsub(mw.ustring.gsub(text, '%[%[', ''), '%]%]', '') |
|||
⚫ | |||
⚫ | |||
return text |
|||
end |
end |
||
function p._main(args) |
function p._main(args) |
||
local |
local original_text = args[1] and mw.text.trim(args[1]) |
||
local |
local text = original_text |
||
local article = article.a |
|||
local ret = '' |
local ret = '' |
||
if |
if text and text ~= '' then |
||
text = clean_text(text) |
|||
local origStr = s |
|||
if mw.ustring.find(text, '^[0-9]') then -- It begins with a number |
|||
article = get_article_from_number_word(text) |
|||
⚫ | |||
elseif mw.ustring.match(text, '^[0-9%u]+$') then -- It looks like an acronym |
|||
article = get_article_from_acronym(text) |
|||
⚫ | |||
⚫ | |||
if mw.ustring.find(s, '^[0-9]') then -- It begins with a number |
|||
⚫ | |||
⚫ | |||
pron = 'an' |
|||
⚫ | |||
elseif mw.ustring.match(s, '^[0-9%u]+$') then -- It looks like an acronym |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
pron = 'an' |
|||
⚫ | |||
else |
else |
||
text = mw.ustring.lower(text) -- Uncapitalize |
|||
if mw.ustring.find( |
if mw.ustring.find(text, '^['.. lcVChars .. ']') then -- It begins with a vowel |
||
if not findWord( |
if not findWord(text, words.vcWords) -- Exclude 'euro' etc. |
||
or findWord( |
or findWord(text, words.vvWords) -- But not 'Euler' etc. |
||
then |
then |
||
article = article.an |
|||
end |
end |
||
elseif args.variety and mw.ustring.lower(args.variety) == 'us' -- 'herb' etc. |
elseif args.variety and mw.ustring.lower(args.variety) == 'us' -- 'herb' etc. |
||
and findWord( |
and findWord(text, words.cvWordsUS) |
||
or findWord( |
or findWord(text, words.cvWords) -- 'hour' etc. |
||
then |
then |
||
article = article.an |
|||
end |
end |
||
end |
end |
||
ret = |
ret = article .. ' ' .. original_text |
||
end |
end |
||