Open main menu
Home
Random
Donate
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:A or an/sandbox
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
local p = {} local words = mw.loadData('Module:A or an/words') local lcVChars = 'aeiouà-æè-ïò-öø-üāăąēĕėęěĩīĭįıijōŏőœũūŭůűų' local ucVvChars = 'AEFHILMNORSXÀ-ÆÈ-ÏÒ-ÖØĀĂĄĒĔĖĘĚĨĪĬĮıIJŌŎŐŒÑĤĦĹĻĽĿŁŃŅŇŊŔŖŘŚŜŞ' local article = { a = "a", an = "an", } local function findWord(text, array) for _, v in ipairs(array) do if mw.ustring.find(text, '^' .. v .. '$') then return true end end end local function get_article_from_acronym(text) if mw.ustring.find(text, '^[' .. ucVvChars .. ']') and not findWord(text, words.cvAcronyms) -- Exclude 'NASA' etc. or findWord(text, words.vvAcronyms) -- 'UNRWA' etc. then return article.an end return article.a end local function get_article_from_number_word(text) text = mw.ustring.match(text, '^[0-9]+') -- Extract the number if findWord(text, words.vNums) then -- '18' etc. return article.an end return article.a end local function clean_text(text) text = mw.ustring.gsub(text, '</?[A-Za-z][^>]->', '') -- Remove HTML tags text = mw.ustring.gsub(text, '%[%[[^%|]+%|(..-)%]%]', '%1') -- Remove wikilinks text = mw.ustring.gsub(mw.ustring.gsub(text, '%[%[', ''), '%]%]', '') text = mw.ustring.gsub(text, '^["%$\'%(<%[%{¢-¥₠-₿]+', '') -- Strip some symbols at the beginning text = mw.ustring.match(text, '^%.?[0-9%u%l]+') or text -- Extract the first word return text end function p._main(args) local original_text = args[1] and mw.text.trim(args[1]) local text = original_text local article = article.a local ret = '' if text and text ~= '' then text = clean_text(text) 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) else text = mw.ustring.lower(text) -- Uncapitalize if mw.ustring.find(text, '^['.. lcVChars .. ']') then -- It begins with a vowel if not findWord(text, words.vcWords) -- Exclude 'euro' etc. or findWord(text, words.vvWords) -- But not 'Euler' etc. then article = article.an end elseif args.variety and mw.ustring.lower(args.variety) == 'us' -- 'herb' etc. and findWord(text, words.cvWordsUS) or findWord(text, words.cvWords) -- 'hour' etc. then article = article.an end end ret = article .. ' ' .. original_text end return ret end function p.main(frame) return p._main(frame:getParent().args) end return p
Summary:
Please note that all contributions to Stockhub may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Stockhub:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Template used on this page:
Module:A or an/sandbox/doc
(
edit
)