Module:User:Jberkel/pt-conj

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

This is a private module sandbox of Jberkel, for their own experimentation. Items in this module may be added and removed at Jberkel's discretion; do not rely on this module's stability.


local exports = {}

local function verbData(ending)
   local group
   if ending == 'pôr' or ending == 'por' then
     group = 'er'
   elseif ending == 'erir-defective' then
     group = 'ir'
   else
     group, _ = string.gsub(ending, "%d+$", "")
     group = string.sub(group, #group-1)
   end
   
   if group == "" then
   	  return nil
   end
   
   local success, m_verb_data = pcall(require, "Module:pt-conj/data/-"..group)
   if success and m_verb_data then
      return mw.clone(m_verb_data)
   else
      return nil
   end
end

local function applyFuncToTableValues(tbl, func)
   for k,v in pairs(tbl) do
      if type(v) == 'table' then
         applyFuncToTableValues(v, func)
      else
         tbl = func(v)
      end
   end
end

-- stem (required if applicable): beginning of the verb. All characters of the infinitive form, except those in the template's title.
-- ending (required): Ending of the verb. The last characters chosen specifically by the template.
-- compound (required if applicable): Compound words. Text to be added after the verb.
function exports.inflect(stem, ending, compound)
   local data = verbData(ending)
   if data then
      applyFuncToTableValues(data.forms, function(form)
         if form ~= "" then
            return stem .. form .. (compound and (' ' .. compound) or '')
         else
            return ""
         end
      end)
      return data
   else
      return nil
   end
end


-- The main entry point.
-- This is the only function that can be invoked from a template.
function exports.show(frame)
   local m_table = require("Module:User:Jberkel/pt-conj/table")
   local args = frame:getParent().args
   local stem, ending, compound = args, args, args
   local word = exports.inflect(stem, ending, compound)
   if word then
      return m_table.create(word)
   else
      error("No inflection data found")
   end
end

return exports