Jump to content

Module:a or an/sandbox

From Wikipedia, the free encyclopedia
localp={}localwords=mw.loadData('Module:A or an/words')locallcVChars='aeiouà-æè-ïò-öø-üāăąēĕėęěĩīĭįıijōŏőœũūŭůűų'localucVvChars='AEFHILMNORSXÀ-ÆÈ-ÏÒ-ÖØĀĂĄĒĔĖĘĚĨĪĬĮıIJŌŎŐŒÑĤĦĹĻĽĿŁŃŅŇŊŔŖŘŚŜŞ'localarticle={a="a",an="an",}localfunctionfindWord(text,array)for_,vinipairs(array)doifmw.ustring.find(text,'^'..v..'$')thenreturntrueendendendlocalfunctionget_article_from_acronym(text)ifmw.ustring.find(text,'^['..ucVvChars..']')andnotfindWord(text,words.cvAcronyms)-- Exclude 'NASA' etc.orfindWord(text,words.vvAcronyms)-- 'UNRWA' etc.thenreturnarticle.anendreturnarticle.aendlocalfunctionget_article_from_number_word(text)text=mw.ustring.match(text,'^[0-9]+')-- Extract the numberiffindWord(text,words.vNums)then-- '18' etc.returnarticle.anendreturnarticle.aendlocalfunctionclean_text(text)text=mw.ustring.gsub(text,'</?[A-Za-z][^>]->','')-- Remove HTML tagstext=mw.ustring.gsub(text,'%[%[[^%|]+%|(..-)%]%]','%1')-- Remove wikilinkstext=mw.ustring.gsub(mw.ustring.gsub(text,'%[%[',''),'%]%]','')text=mw.ustring.gsub(text,'^["%$\'%(<%[%{¢-¥₠-₿]+','')-- Strip some symbols at the beginningtext=mw.ustring.match(text,'^%.?[0-9%u%l]+')ortext-- Extract the first wordreturntextendfunctionp._main(args)localoriginal_text=args[1]andmw.text.trim(args[1])localtext=original_textlocalarticle=article.alocalret=''iftextandtext~=''thentext=clean_text(text)ifmw.ustring.find(text,'^[0-9]')then-- It begins with a numberarticle=get_article_from_number_word(text)elseifmw.ustring.match(text,'^[0-9%u]+$')then-- It looks like an acronymarticle=get_article_from_acronym(text)elsetext=mw.ustring.lower(text)-- Uncapitalizeifmw.ustring.find(text,'^['..lcVChars..']')then-- It begins with a vowelifnotfindWord(text,words.vcWords)-- Exclude 'euro' etc.orfindWord(text,words.vvWords)-- But not 'Euler' etc.thenarticle=article.anendelseifargs.varietyandmw.ustring.lower(args.variety)=='us'-- 'herb' etc.andfindWord(text,words.cvWordsUS)orfindWord(text,words.cvWords)-- 'hour' etc.thenarticle=article.anendendret=article..' '..original_textendreturnretendfunctionp.main(frame)returnp._main(frame:getParent().args)endreturnp
close