Module:User:Isomorphyc/R:LSJ

local export = {}

local chart = { ['ᾰ']='a^', ['ᾱ']='a_', ['α']='a', ['ά']='a/', ['ὰ']='a\\', ['ᾶ']='a=', ['ἀ']='a)', ['ἁ']='a(', ['ἂ']='a)\\', ['ἃ']='a(\\', ['ἄ']='a)/', ['ἅ']='a(/', ['ἆ']='a)=', ['ἇ']='a(=', ['ᾳ']='a|', ['ᾴ']='a/|', ['ᾲ']='a\\|', ['ᾷ']='a=|', ['ᾀ']='a)|', ['ᾁ']='a(|', ['ᾂ']='a)\\|', ['ᾃ']='a(\\|', ['ᾄ']='a)/|', ['ᾅ']='a(/|', ['ᾆ']='a)=|', ['ᾇ']='a(=|', ['Ᾰ']='*a^', ['Ᾱ']='*a_', ['Α']='*a', ['Ά']='*/a', ['Ὰ']='*a\\', ['῀Α']='*a=', ['Ἀ']='*)a', ['Ἁ']='*(a', ['Ἂ']='*)a\\', ['Ἃ']='*(a\\', ['Ἄ']='*)/a', ['Ἅ']='*(/a', ['Ἆ']='*)a=', ['Ἇ']='*(a=', ['ᾼ']='*a|', ['ᾈ']='*)a|', ['ᾉ']='*(a|', ['ᾊ']='*)a\\|', ['ᾋ']='*(a\\|', ['ᾌ']='*)/a|', ['ᾍ']='*(/a|', ['ᾎ']='*)a=|', ['ᾏ']='*(a=|', ['β']='b', ['Β']='*b', ['γ']='g', ['Γ']='*g', ['δ']='d', ['Δ']='*d', ['ε']='e', ['έ']='e/', ['ὲ']='e\\', ['ἐ']='e)', ['ἑ']='e(', ['ἒ']='e)\\', ['ἓ']='e(\\', ['ἔ']='e)/', ['ἕ']='e(/', ['Ε']='*e', ['Έ']='*/e', ['Ὲ']='*\\e', ['Ἐ']='*)e', ['Ἑ']='*(e', ['Ἒ']='*)\\e', ['Ἓ']='*(\\e', ['Ἔ']='*)/e', ['Ἕ']='*(/e', ['ζ']='z', ['Ζ']='*z', ['η']='h', ['ή']='h/', ['ὴ']='h\\', ['ῆ']='h=', ['ἠ']='h)', ['ἡ']='h(', ['ἢ']='h)\\', ['ἣ']='h(\\', ['ἤ']='h)/', ['ἥ']='h(/', ['ἦ']='h)=', ['ἧ']='h(=', ['ῃ']='h|', ['ῄ']='h/|', ['ῂ']='h\\|', ['ῇ']='h=|', ['ᾐ']='h)|', ['ᾑ']='h(|', ['ᾒ']='h)\\|', ['ᾓ']='h(\\|', ['ᾔ']='h)/|', ['ᾕ']='h(/|', ['ᾖ']='h)=|', ['ᾗ']='h(=|', ['Η']='*h', ['Ή']='*h/', ['Ὴ']='*h\\', ['Ἠ']='*)h', ['Ἡ']='*(h', ['Ἢ']='*)h\\', ['Ἣ']='*(h\\', ['Ἤ']='*)/h', ['Ἥ']='*(/h', ['Ἦ']='*)h=', ['Ἧ']='*(h=', ['ῌ']='*h|', ['ᾘ']='*)h|', ['ᾙ']='*(h|', ['ᾚ']='*)h\\|', ['ᾛ']='*(h\\|', ['ᾜ']='*)/h|', ['ᾝ']='*(/h|', ['ᾞ']='*)h=|', ['ᾟ']='*(h=|', ['θ']='q', ['Θ']='*q', ['ῐ']='i^', ['ῑ']='i_', ['ϊ']='i%252B', ['ῒ']='i\\%252B', ['ΐ']='i/%252B', ['ῖ']='i=', ['ῗ']='i=%252B', ['ι']='i', ['ί']='i/', ['ὶ']='i\\', ['ἰ']='i)', ['ἱ']='i(', ['ἲ']='i)\\', ['ἳ']='i(\\', ['ἴ']='i)/', ['ἵ']='i(/', ['ἶ']='i)=', ['ἷ']='i(=', ['Ῐ']='*i^', ['Ῑ']='*i_', ['Ϊ']='*i%252B', ['Ι']='*i', ['Ί']='*i/', ['Ὶ']='*i\\', ['Ἰ']='*)i', ['Ἱ']='*(i', ['Ἲ']='*)i\\', ['Ἳ']='*(i\\', ['Ἴ']='*)/i', ['Ἵ']='*(/i', ['Ἶ']='*)i=', ['Ἷ']='*(i=', ['κ']='k', ['Κ']='*k', ['λ']='l', ['Λ']='*l', ['μ']='m', ['Μ']='*m', ['ν']='n', ['Ν']='*n', ['ξ']='c', ['Ξ']='*c', ['ο']='o', ['ό']='o/', ['ὸ']='o\\', ['ὀ']='o)', ['ὁ']='o(', ['ὂ']='o)\\', ['ὃ']='o(\\', ['ὄ']='o)/', ['ὅ']='o(/', ['Ο']='*o', ['Ό']='*/o', ['Ὸ']='*o\\', ['Ὀ']='*)o', ['Ὁ']='*(o', ['Ὂ']='*)o\\', ['Ὃ']='*(o\\', ['Ὄ']='*)/o', ['Ὅ']='*(/o', ['π']='p', ['Π']='*p', ['ρ']='r', ['ῤ']='r)',	['ῥ']='r(', ['Ρ']='*r', ['Ῥ']='*(r', ['σ']='s', ['Σ']='*s', ['ς']='s',	['τ']='t', ['Τ']='*t',	['ῠ']='u^', ['ῡ']='u_', ['ϋ']='u%252B', ['ΰ']='u/%252B', ['ῢ'] ='u\\%252B', ['ῧ']='u=%252B',	['υ']='u', ['ύ']='u/', ['ὺ']='u\\', ['ῦ']='u=', ['ὐ']='u)', ['ὑ']='u(',	['ὒ']='u)\\', ['ὓ']='u(\\', ['ὔ']='u)/', ['ὕ']='u(/', ['ὖ']='u)=', ['ὗ']='u(=',	['Ῠ']='*u^', ['Ῡ']='*u_', ['Ϋ']='*u%252B',	['Υ']='*u', ['Ύ']='*/u', ['Ὺ']='*u\\', ['Ὑ']='*(u', ['Ὓ']='*(u\\', ['Ὕ']='*(u/', ['Ὗ']='*(u=',	['φ']='f', ['ψ']='y', ['Ψ']='*y', ['Φ']='*f', ['χ']='x', ['Χ']='*x',	['ω']='w', ['ώ']='w/', ['ὼ']='w\\', ['ῶ']='w=', ['ὠ']='w)', ['ὡ']='w(',	['ὢ']='w)\\', ['ὣ']='w(\\', ['ὤ']='w)/', ['ὥ']='w(/', ['ὦ']='w)=', ['ὧ']='w(=',	['ῳ']='w|', ['ῴ']='w/|', ['ῲ']='w\\|', ['ῷ']='w=|', ['ᾠ']='w)|', ['ᾡ']='w(|',	['ᾢ']='w)\\|', ['ᾣ']='w(\\|', ['ᾤ']='w)/|', ['ᾥ']='w(/|', ['ᾦ']='w)=|', ['ᾧ']='w(=|',	['Ω']='*w', ['Ώ']='*/w', ['Ὼ']='*w\\', ['Ὠ']='*)w', ['Ὡ']='*(w',	['Ὢ']='*)w\\', ['Ὣ']='*(w\\', ['Ὤ']='*)w/', ['Ὥ']='*(/w', ['Ὦ']='*)w=', ['Ὧ']='*(w=',	['ῼ']='*w|', ['ᾨ']='*)w|', ['ᾩ']='*(w|',	['ᾪ']='*)w\\|', ['ᾫ']='*(w\\|', ['ᾬ']='*)/w|', ['ᾭ']='*(/w|', ['ᾮ']='*)w=|', ['ᾯ']='*(w=|',	['ϝ']='v', ['Ϝ']='*v'}

local collisions_lsj = require("Module:R:LSJ/collision-data")

function is_collision(x) if collisions_lsj[string.lower(x)] == Nil then return false else return true end end

function polytonic_to_perseus_beta(polytonic) local length = mw.ustring.len(polytonic) local x = 1 local letter = '' local betaTable = {} while x <= length do		letter = mw.ustring.sub(polytonic, x, x)		if chart[letter] then table.insert(betaTable, chart[letter]) end x = x + 1 end return table.concat(betaTable, '') end

function format_perseus_url(title, beta, redirect) local url_redirect_lhs = 'http://www.perseus.tufts.edu/hopper/resolveform?type=exact&lookup=' local url_entry_lhs = 'http://www.perseus.tufts.edu/hopper/text?doc=Perseus:text:1999.04.0057:entry=' local url_rhs = redirect and '&lang=greek' or '' return (redirect and url_redirect_lhs or url_entry_lhs)..beta..url_rhs end

function format_perseus_wikilink(title, beta, redirect) local lsj_biblio = "A Greek–English Lexicon by Liddell & Scott, Clarendon Press, Oxford, 1940" local url = format_perseus_url(title, beta, redirect) local w_link = '['..url..' '..title..'] in ' return (beta ==  and  or w_link)..lsj_biblio end

function export.create(frame) local args = frame:getParent.args local title = args['w'] or mw.title.getCurrentTitle.text local beta = args[1] or polytonic_to_perseus_beta(title) local redirect = args['resolve'] or (is_collision(title) and not args[1] and not args['w']) return format_perseus_wikilink(title, beta, redirect) end

return export