Modul:es-conj

Üdvözlöm, Ön a Modul:es-conj szó jelentését keresi. A DICTIOUS-ban nem csak a Modul:es-conj szó összes szótári jelentését megtalálod, hanem megismerheted az etimológiáját, a jellemzőit és azt is, hogyan kell a Modul:es-conj szót egyes és többes számban mondani. Minden, amit a Modul:es-conj szóról tudni kell, itt található. A Modul:es-conj szó meghatározása segít abban, hogy pontosabban és helyesebben fogalmazz, amikor beszélsz vagy írsz. AModul:es-conj és más szavak definíciójának ismerete gazdagítja a szókincsedet, és több és jobb nyelvi forráshoz juttat.

This module conjugates Spanish verbs.

The module uses numbers to refer to individual verb forms. A map from these numbers to the verb form properties is below:

Public functions

  • frame objects take numbered parameters of 1=ending, 2=pattern, and parameters 3 onwards stems for the verb; and named parameters ref (to toggle reflexive conjugation) and json (to toggle JSON output).
  • json_raw: Takes a frame object. Returns a JSON object containing inflected forms and their properties.
  • json_wikt_forms: Takes a frame object. Returns a JSON object containing inflected forms and corresponding Wiktionary inflection templates.
  • json_combined_forms: Takes a table of inflections generated with inflect, and the ending of the verb. Returns a JSON object containing combined forms and corresponding Wiktionary inflection templates.
  • json_paradigms: Exports the list of verb paradigms as a JSON object (see Template:es-conj/paradigms)
  • inflect: Takes a table of args (containing ending, pattern, a table of stems, and boolean ref (reflexive)), a table of categories, and boolean toggle_decorate. Returns a table containing the inflected forms of the verb, decorated with links or plain based on toggle_decorate.
  • inflect_combined: Takes a table of inflections generated with inflect. Returns a table of some combined forms of the verb.
  • headword_line: Takes a frame object. Returns a headword line for the verb.
  • verb_table: Takes a frame object. Returns a conjugation table or JSON object containing inflected forms of the verb.

Data subpages

  • Data modules are located at data/ending/pattern (or data/ending for the basic -ar/-er/-ir patterns). Individual data modules inherit the base pattern of the parent module (-ar/-er/-ir), and return a table with the following properties:
  • description: Optional description of the conjugation type
  • replacement: Replacement rules to be applied to base conjugation pattern
  • patterns: Table of patterns that differ from base pattern
  • ref: Table of any reflexive forms that need to be specified
  • defective: Table of defective form numbers
  • unstressed: Table of forms that should not be automatically stressed in reflexive conjugation

Other subpages


local export = {}

local lang = require('Module:languages').getByCode('es')
local entry_data = require('Module:es-conj/data/entry_data')
local paradigms = require('Module:es-conj/data/paradigms')
local json = require('Module:Json')

local ulen = mw.ustring.len
local usub = mw.ustring.sub
local ufind = mw.ustring.find
local ugsub = mw.ustring.gsub

local pronouns = { = {7,14,20,26,32,38,45,51,57},
				   = {8,15,21,27,33,39,46,52,58,69},
				   = {9,40,64,10,13,16,19,22,25,28,31,34,37,41,44,47,50,53,56,59,62,70,73},
				   = {11,17,23,29,35,42,48,54,60,71},
				   = {12,18,24,30,36,43,49,55,61,72}}

local vowels = {="á",
				="é",
				="í",
				="ó",
				="ú"}
local stressed_vowels = {
				="a",
				="e",
				="i",
				="o",
				="u"}

local function to_boolean(val)
	if type(val) == 'string' then
		val = mw.text.trim(val)
	end
	return not (not val or val == "" or val == "0" or val == "no" or val == "n" or val == "false")
end

function unpack_args(frame)
	local args = frame.args
	if (not args) then
		args = frame:getParent().args
	end
	
	local ending = args
    local pattern = args
    local ref = to_boolean(args)
	local json = to_boolean(args)
	local combined = to_boolean(args)
	local json_combined = to_boolean(args)
	
    local stems = {}
    local i = 3
    while args do
   		stems = args
   		i = i + 1
    end
    return {ending, pattern, stems, ref, json, combined, json_combined}
end

function strip_accents(form)
	if form then
		return (mw.ustring.gsub(form, ".", stressed_vowels):gsub(",+", ","))
	end
end

function create_accented_form(form, ua_disyllabic)
	-- create accented stem for reflexive verbs
	
	-- split by commas if more than 1 form is given
	if form then
		if string.find(form, ',') then
			local result_t = {}
			for term in string.gmatch(form, '+') do
				table.insert(result_t, create_accented_form(term, ua_disyllabic))
			end
			return table.concat(result_t, ',')
		end

		local result = form
		
		-- c: index of current character
		local c = ulen(result)
		local vowel_count = 0
		
		while (c >= 0) do
			local v1 = usub(result, c, c)
			
			if vowels then
				vowel_count = vowel_count + 1
			end
			
			-- 'ue' or 'ua' count as 1 vowel, accent goes on e or a
			if c ~= ulen(result) then
				local v2 = usub(result, c+1, c+1)
				if (v1 == 'u' and v2 == 'e') then
					vowel_count = vowel_count - 1
				end
				if (not ua_disyllabic) then
					if (v1 == 'u' and v2 == 'a') then
						vowel_count = vowel_count - 1
					end
				end
			end
			
			-- 'ai' or 'oi' counts as 1 vowel, accent goes on a or o
			if (c ~= 1) then
				local v3 = usub(result, c-1, c-1)
				if (v3 == 'a' and v1 == 'i') then
					vowel_count = vowel_count - 1
				end
				if (v3 == 'o' and v1 == 'i') then
					vowel_count = vowel_count - 1
				end
			end
		
			if vowel_count == 3 then
				return usub(result, 1, c-1)..vowels..usub(result, c+1, ulen(result))
			end
			c = c - 1
		end
	end

	return form

end

local function makeLink(term, face, allow_self_link)
    local m_links = require('Module:links')
    local alt, sc, id, annotations = nil, nil, nil, nil
    
    if string.find(term, ',') then
    	local result = {}
    	local c = 1
    	local found = {}
    	for i in string.gmatch(term, '+') do
    		if not found then
    			found = true
	    		result = m_links.full_link({lang = lang, term = i}, face, allow_self_link)
    			c = c + 1
    		end
		end
		return table.concat(result, ', ')
	end
	
    return m_links.full_link({lang = lang, term = term}, face, allow_self_link)
end

function decorate_inflections(inflections, ref, defective, patterns)
	local defective_t = {}
	
	if defective then
		for k1,v1 in pairs(defective) do
			defective_t = true
		end
	end

	local result = {}
	for k1,v1 in pairs(inflections) do
		if not defective_t then
			result = makeLink(v1, nil, true)
		else
			result = "<div style=\"color:#aaa\">" .. v1 .. "</div>"
		end
	end
	
	if ref then
		for k1,v1 in pairs(pronouns) do
			for k2,v2 in pairs(v1) do
				if result then
					if not defective_t then
						result = k1.." "..result
					else
						result = "<div style=\"color:#aaa\">" .. k1 .. "</div> " .. result
					end
					
				end
			end
		end
	end
	
	return result
end

function deepcopy(orig)
    local orig_type = type(orig)
    local copy
    if orig_type == 'table' then
        copy = {}
        for orig_key, orig_value in next, orig, nil do
            copy = deepcopy(orig_value)
        end
        setmetatable(copy, deepcopy(getmetatable(orig)))
    else -- number, string, boolean, etc
        copy = orig
    end
    return copy
end

function export.json_raw(frame)
	local args = unpack_args(frame)
	local forms = export.inflect(args, {}, false)
	local result = {}
	
	for i, form in pairs(forms) do
		if not result then
			result = {}
		end
		for j, def in pairs(entry_data.data) do
			table.insert(result, def)
		end
	end
	
	return json.jsonValueFromValue(result)
	
end

function export.json_wikt_forms(frame)
	local args = unpack_args(frame)
	local forms = export.inflect(args, {}, false)
	local ending = args
	local pattern = args
	
	local pattern_data = deepcopy(require("Module:es-conj/data/"..ending))
	if pattern ~= ending then
		pattern_data = deepcopy(require("Module:es-conj/data/"..ending.."/"..pattern))
	end

	local defective = pattern_data
	if not defective then
		defective = {}
	end
	
	local defective_t = {}
	for k1,v1 in pairs(defective) do
		defective_t = true
	end
	
	local infinitive = forms
	local ending = args
	local result = {}
	
	for i, form in pairs(forms) do
		if not defective_t then
			if (form ~= infinitive) then
				 for form_s in string.gmatch(form, '+') do
				 	local form_s_t = mw.text.trim(form_s)
					if not result then
						result = {}
					end
					for j, def in pairs(entry_data.data) do
						table.insert(result, entry_data.make_template(def, ending, infinitive))
					end
				end
			end
		end
	end
	
	return json.jsonValueFromValue(result)	
end

function export.json_paradigms(frame)
	return json.jsonValueFromValue(paradigms)
end

function export.inflect(args,   toggle_decorate)

	--table.insert(categories, "]")
	
	local ending = args
	local pattern = args
	local stems = args
	local ref = args
	
	local ending_data = deepcopy(require("Module:es-conj/data/"..ending))
	local pattern_data = deepcopy(require("Module:es-conj/data/"..ending))
	if pattern ~= ending then
		pattern_data = deepcopy(require("Module:es-conj/data/"..ending.."/"..pattern))
	end

	local description = pattern_data
	local defective = pattern_data
	local unstressed = pattern_data or {}
	
	if not defective then
		defective = {}
	else
		--table.insert(categories, "]")
	end
	
	if ref then
		--table.insert(categories, "]")
		for k1,v1 in pairs(ending_data) do
			ending_data = v1
		end
		
		if (pattern_data) then
			for k1,v1 in pairs(pattern_data) do
				pattern_data = v1
			end
		end
		
	end
	
	if pattern_data then
		for k1,v1 in pairs(pattern_data) do
			for k2,v2 in pairs(ending_data) do
				ending_data = ugsub(ending_data, k1, v1)
			end
		end
	end

	for k1,v1 in pairs(pattern_data) do
		
		if v1 == '-' then
			ending_data = nil
		else
			if ending_data ~= v1 then
				if entry_data.data then
					for k2,v2 in pairs(entry_data.data) do
						tense = v2.tense
						mood = v2.mood
						if mood ~= 'infinitive' then
							if tense then
								--table.insert(categories, "]")
							else
								--table.insert(categories, "]")
							end
						end
					end
				end
				ending_data = v1
			end
		end
	end

	for k1,v1 in pairs(ending_data) do
		for k2,v2 in pairs(stems) do
			ending_data = ugsub(ending_data, k2, v2)
		end
	end

	if ref then
		if not unstressed then
			ending_data = create_accented_form(ending_data, false)
		end
		if not unstressed then
			ending_data = create_accented_form(ending_data, false)
		end
		if not unstressed then
			ending_data = create_accented_form(ending_data, false)
		end
	end
	
	for i=98,121 do
		ending_data = create_accented_form(ending_data, false)
	end

	for i=146,157 do
		ending_data = create_accented_form(ending_data , false)
	end

	if not toggle_decorate then
		return ending_data
	end
	
	-- detect redlinks
	local defective_t = {}
	for k1,v1 in pairs(defective) do
		defective_t = true
	end
	for k1,v1 in pairs(ending_data) do
		if (k1 <= 73) then
			if not defective_t then
				
				for form_s in string.gmatch(v1, '+') do
					local form_s_t = mw.text.trim(form_s)
					local link_object = mw.title.new(form_s_t) or nil
					if (link_object) then
						local link_id = link_object.id
						if link_object.id == 0 then
							--table.insert(categories, "]")
						end
					end
				end
			end
		end
	end

	ending_data = decorate_inflections(ending_data, ref, defective, pattern_data)
	ending_data = description
	return ending_data

end

function export.inflect_combined(forms, args, toggle_decorate, toggle_json)
	local ending = args
	local pattern = args
	local ref = args
	
	local pattern_data = deepcopy(require("Module:es-conj/data/"..ending))
	if pattern ~= ending then
		pattern_data = deepcopy(require("Module:es-conj/data/"..ending.."/"..pattern))
	end

	local unstressed = pattern_data
	
	local result = {}
	
	local aspects = { = "acc",  = "dat"}
	
	local combined_data = require("Module:es-conj/data/combined")
	
	for paradigm,paradigm_data in pairs(combined_data) do
		local stem = forms]
		
		if (ref) then
			stem = usub(stem,1,-3)
		end
		
		if (not toggle_json) then
			result = stem
		end
		
		for form in string.gmatch(stem, '+') do
			for k1,aspect in pairs(aspects) do
				for k2,pronoun_table in pairs(paradigm_data) do

					local t = {}
					for k3,pronoun in pairs(pronoun_table) do
						local irregular = false
						local form_modified = deepcopy(form)

						if paradigm_data then
							if (#paradigm_data == 2) then
								form_modified = usub(form_modified, paradigm_data, paradigm_data)
							else
								if (pronoun == paradigm_data) then
									form_modified = usub(form_modified, paradigm_data, paradigm_data)
								end
							end
						end
						
						if paradigm_data then
							for k4,pattern_data in  pairs(paradigm_data) do
								if (aspect == pattern_data) then
									if (k2 == pattern_data) then
										if (pronoun == pattern_data) then
											form_modified = pattern_data(form_modified)
										end
									end
								end
							end
						end

						if (paradigm_data) then
							for k4,pattern_data in pairs(paradigm_data) do
								if (aspect == pattern_data) then
									if (k2 == pattern_data) then
										if (pronoun == pattern_data) then
											form_modified = pattern_data(form_modified)
											irregular = true
										end
									end
								end
							end
						end
					
						if (unstressed) then
							if (unstressed]) then
								form_modified = strip_accents(form_modified)
							end
						end
						
						if (paradigm_data) then
							form_modified = strip_accents(form_modified)..pronoun
						else
							if (not irregular) then
								if (paradigm_data)  then
									if paradigm_data then
										form_modified = create_accented_form(strip_accents(form_modified)..pronoun, true)
									else
										form_modified = create_accented_form(strip_accents(form_modified)..pronoun, false)
									end
								else
									form_modified = form_modified..pronoun
								end
							end
						end
					
						if (not toggle_json) then
							table.insert(t, form_modified)
						else
							result = {pronoun, paradigm, stem}
						end
					
					end
					if (not toggle_json) then
						local parameter = paradigm .. "_" .. aspect .. "_" .. k2
						if (result) then
							result = result .. ',' .. table.concat(t, ',')
						else
							result = table.concat(t, ',')
						end
					end
				end
			end
		end
	end

	if (toggle_json) then
		return json.jsonValueFromValue(result)
	end
	
	if not toggle_decorate then
		return result
	end
	
	result = forms
	return decorate_inflections(result, false, nil, nil)
	
end

function export.headword_line(frame)
   local args = unpack_args(frame)
   local categories = {}
   
   local forms = export.inflect(args,  true)
   
   if forms then
        local result = {title = "head", args = { = "es",
        										 = "verb",
        										 = 'first-person singular present',
        										 = 'first-person singular preterite',
        										 = 'past participle'}}
        									
        if (forms) then
        	result.args = forms
        end
        if (forms) then
        	result.args = forms
    	end
    	if (forms) then
    		result.args = forms
		end
		
		return frame:expandTemplate(result)
		
   else
      error("No inflection data found")
   end
end

function export.verb_table(frame)
	local calling_title = mw.title.getCurrentTitle()
	
	local m_table = require("Module:es-conj/table")
	
	local args = unpack_args(frame)
   
    if (args) then
        return export.json_wikt_forms(frame)
    end
    
    categories = {}

    local forms = export.inflect(args,  true)

	if (args) then
		return export.inflect_combined(export.inflect(args,   false), args, false, true)
	end

	if (args) then
		local combined = export.inflect_combined(export.inflect(args,   false), args, true)
		if calling_title.namespace == 0 then
	   		return m_table.create(frame, args, forms, combined)
    	else
    		return m_table.create(frame, args, forms, combined)
		end
	end
	
    if forms then
    	if calling_title.namespace == 0 then
	    	return m_table.create(frame, args, forms) 
    	else
    		return m_table.create(frame, args, forms)
		end
    else
       error("No inflection data found")
    end
	
end

function export.boiler(frame)

	local categories = ""
	return categories
	
end

return export