Module:R:Perseus/sandbox

Hello, you have come here looking for the meaning of the word Module:R:Perseus/sandbox. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:R:Perseus/sandbox, but we will also tell you about its etymology, its characteristics and you will know how to say Module:R:Perseus/sandbox in singular and plural. Everything you need to know about the word Module:R:Perseus/sandbox you have here. The definition of the word Module:R:Perseus/sandbox will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:R:Perseus/sandbox, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.


local export = {}

-- Collisions contained in submodules of ].
local m_params = require("Module:parameters")
local m_utils = require("Module:grc-utilities")
local m_scripts = require("Module:scripts")
local m_script_utils = require("Module:script utilities")
local m_languages = require("Module:languages")

local tag_greek = m_utils.tag

local function tag_latin(text)
	local lang = m_languages.getByCode("la")
	local sc = m_scripts.getByCode("Latn")
	return m_script_utils.tag_text(text, lang, sc, nil)
end

local function track(code)
	require('Module:debug').track('R:Perseus/' .. code)
	return '' -- for format_perseus_wikilink
end

local function lower_dashed(w)
	return string.gsub(string.lower(w), " ", "-")
end

local function remove_diacritics(x)
	return mw.ustring.gsub(mw.ustring.toNFD(x), '%W+', "")
end

-- maybe there is a better way to do this
local function beta(w)
	return require("Module:R:Perseus/polytonic-to-perseus-betacode").polytonic_to_perseus_betacode(w)
end

--[[ Resources:
	template name, with "R:" removed = {
		 = Perseus resource id,
		 = collisions index name,
		 = f-query-entry-postprocess,
		 = query-entry-suffix,
		 = language name
	}
	]]
-- This allows the optional selection of a different bio number for Smith's Persons.
if mw.getCurrentFrame():getParent().args then
	if mw.ustring.match(mw.getCurrentFrame():getParent().args,'-bio-',1) then
		a = ""
	else
		a = '-bio-1'
	end
end
local resources = {
	 = {
		"1999.04.0059",
		"LS",
		nil,
		nil,
		'latin',
	},
	 = {
		"1999.04.0060",
		"EL",
		nil,
		nil,
		'latin'
	},
	 = {
		"1999.04.0062",
		nil,
		lower_dashed,
		'-harpers',
		'latin'
	},
	 = {
		"1999.04.0004",
		nil,
		lower_dashed,
		"",
		'latin'
	},
	 = {
		"1999.04.0006",
		"PECS",
		lower_dashed,
		"",
		'latin'
	},
	 = {
		"1999.04.0054",
		"TDAR",
		lower_dashed,
		"",
		'latin'
	},
	 = {
		"1999.04.0063",
		nil,
		lower_dashed,
		'-cn',
		'latin'
	},
	 = {
		"1999.04.0104",
		nil,
		lower_dashed,
		a,
		'latin'
	},
	 = {
		"1999.04.0064",
		nil,
		lower_dashed,
		'-geo',
		'latin'
	},
	 = {
		"1999.04.0057",
		"LSJ",
		nil,
		nil,
		'greek'
	},
	 = {
		"1999.04.0058",
		"ML",
		nil,
		nil,
		'greek'
	},
	 = {
		"2013.01.0002",
		nil,
		function(w)
			return lower_dashed(remove_diacritics(w))
		end,
		"",
		'greek'
	},
	 = {
		"1999.04.0073",
		"Autenrieth",
		nil,
		nil,
		'greek'
	},
	 = {
		"1999.04.0072",
		"Slater",
		nil,
		nil,
		"greek"
	},
	 = {
		"2003.02.0002",
		"Zoega",
		nil,
		nil,
		'non'
	},
}

local function get_language(template)
	return resources
end

local function is_collision(x, template)
	local collisions_data = resources
	local lhs_postprocess = resources or x
	if collisions_data then
		return mw.loadData("Module:R:Perseus/collision-data/" .. resources) == true
	end
end

local function format_perseus_url(beta_or_latin, template, redirect)
	local harpo = template == 'Harpocration' and ":letter=" .. string.upper(string.sub(remove_diacritics(beta_or_latin), 1, 1)) or ""
	local data = resources
	local id = data or ''
	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:' .. id .. harpo .. ':entry='
	local url_rhs = redirect and '&lang=' .. get_language(template) or ''
	
	local postprocess
	if data ~= nil then
		postprocess =
		function(w)
			return data(w) .. (data or '')
		end
	else
		postprocess =
		function(w)
			return w
		end
	end
	
	return (redirect and url_redirect_lhs or url_entry_lhs)
			.. postprocess(beta_or_latin)
			.. url_rhs
end

local function is_polytonic(text)
	local lang = m_languages.getByCode("grc")
	return m_scripts.findBestScript(text, lang):getCode() == "polytonic"
end

local function format_perseus_wikilink(title, beta_or_latin, template, redirect)
	local title_span = title
	
	if get_language(template) == 'greek' then
		if not is_polytonic(title_span) then
			-- ]
			track('wrong-script')
		end
		title_span = tag_greek(title_span)
	elseif get_language(template) == 'latin' then
		title_span = tag_latin(title_span)
	end
	return (beta_or_latin == '' and track('no Perseus link')
			or ' in ')
end

function export.create(frame)
	local params = {
		 = {}, -- Perseus code or word
		 = {}, -- word; only for Greek templates?
	}
	local args = m_params.process(frame:getParent().args, params)
	
	local template = string.gsub(frame:getParent():getTitle(), "^Template:R:", "")
	template = string.gsub(template, "/sandbox$", "")
	local latin = not (get_language(template) == 'greek')
	
	if not latin and args and not args then
		error('Parameter 2 should be placed in parameter 1.')
	end
	
	local title = mw.title.getCurrentTitle()
	
	local word, perseus_code
	if latin then
		word = args or title.text
		perseus_code = args or title.text
	else
		word = args
		
		if word and not is_polytonic(word) then
			error('Second parameter of {{[[Template:R:' .. template .. '|R:' .. template ..
					']]}} should be a Greek word.')
		end
		
		if args then
			if is_polytonic(args) then
				if not word then
					word = args
				else
					error('Second parameter of {{[[Template:R:' .. template .. '|R:' .. template ..
							']]}} is a Greek word, so first parameter must be Perseus entry code.')
				end
			else
				perseus_code = args
			end
		end
			
		
		if not word then
			local pagename = title.text
			if is_polytonic(pagename) then
				word = pagename
			elseif title.nsText == "Template" then
				word = 'λέξις'
			else
				error('{{[[Template:R:' .. template .. '|R:' .. template ..
						']]}} needs manual input: pagename is not Greek.')
			end
		end
		
		if not perseus_code then
			perseus_code = beta(word)
		end
	end
	
	local redirect = not (args or args) and is_collision(word, template)
	
	if word == template then
		return ""
	else
		return format_perseus_wikilink(word, perseus_code, template, redirect)
	end
end

return export