Jump to content

Module:User:Əkrəm Cəfər/az-infl

From Wiktionary, the free dictionary
local export = {}

local get_harmony = require("Module:az-harmony")._main
local ends_in = require("Module:az-ends-in")._main
local sub = mw.ustring.sub

--[=[
This function generates the case declension forms.

The function accepts 2 arguments:
# {lemma}, a string, the lemma itself.
# {change}, a Boolean, whether the final consonant changes when a suffix starting with vowel is affixed. These changes include: k -> y (e.g. külək -> küləyin), and q -> ğ (e.g. qabaq -> qabağım). While such changes happen in most words, some one-syllabic ones (e.g. türk -> türkə, morq -> morqu) and some borrowings (e.g. təbrik -> təbriki, sadiq -> sadiqi) are exceptions.

There are 6 cases in Azerbaijani: nominative, genitive, dative, accusative, locative and ablative.
]=]

function export.case(lemma, change)
  local lemma_ends_in = ends_in(lemma, true)
  local final_letter = ends_in(lemma)
  local stem = lemma_ends_in == "consonant" and (change and (final_letter == "q" and sub(lemma, 1, -2) .. "ğ" or (sub(lemma, 1, -2) .. "y")) or lemma)
  local o = get_harmony(lemma, "open") -- the vowel that maintains the open vowels' harmony, i.e. either "a" or "ə"
  local c = get_harmony(lemma, "close") -- the vowel that maintains the close vowels' harmony, i.e. one of "ı", "i", "u", "ü"

  return {
    ["genitive"] = lemma_ends_in == "vowel" and (lemma .. "n" .. c .. "n") or (stem .. c .. "n"),
    ["dative"] = lemma_ends_in == "vowel" and (lemma .. "y" .. o) or (stem .. o),
    ["accusative"] = lemma_ends_in == "vowel" and (lemma .. "n" .. c) or (stem .. c),
    ["locative"] = lemma .. "d" .. o,
    ["ablative"] = lemma .. "d" .. o .. "n"
  }
end

--[=[
This function generates the possessive declension forms.

The function accepts 3 arguments:
# {lemma}, a string, the lemma itself.
# {change}, a Boolean, whether the final consonant changes when a suffix starting with vowel is affixed. These changes include: k -> y (e.g. külək -> küləyin), and q -> ğ (e.g. qabaq -> qabağım). While such changes happen in most words, some one-syllabic ones (e.g. türk -> türkə, morq -> morqu) and some borrowings (e.g. təbrik -> təbriki, sadiq -> sadiqi) are exceptions.
# {connector}, a string, the connector consonant i.e. either "s" or "y". If not provided, it defaults to "s", which is the most common one among Azerbaijani words. A connector consonant is necessary when a word that ends in vowel gets a suffix that starts with a vowel.

p.poss() is an alias for this function, as defined below.
]=]

function export.possessive(lemma, change, connector)
  local lemma_ends_in = ends_in(lemma, true)
  local final_letter = ends_in(lemma)
  local stem = lemma_ends_in == "consonant" and (change and (final_letter == "q" and sub(lemma, 1, -2) .. "ğ" or (sub(lemma, 1, -2) .. "y")) or lemma)
  local o = get_harmony(lemma, "open") -- the vowel that maintains the open vowels' harmony, i.e. either "a" or "ə"
  local c = get_harmony(lemma, "close") -- the vowel that maintains the close vowels' harmony, i.e. one of "ı", "i", "u", "ü"

  local nominative = {
    ["1s_spos_nom"] = lemma_ends_in == "vowel" and (connector == "y" and (lemma .. "y" .. c .. "m") or (lemma .. "m")) or (lemma .. c .. "m"),
    ["2s_spos_nom"] = lemma_ends_in == "vowel" and (connector == "y" and (lemma .. "y" .. c .. "n") or (lemma .. "n")) or (lemma .. c .. "n"),
    ["3s_spos_nom"] = lemma_ends_in == "vowel" and (lemma .. connector .. c) or lemma .. c,
    ["1p_spos_nom"] = lemma_ends_in == "vowel" and (connector == "y" and (lemma .. "y" .. c .. "m" .. c .. "z") or (lemma .. "m" .. c .. "z")) or (lemma .. c .. "m" .. c .. "z"),
    ["2p_spos_nom"] = lemma_ends_in == "vowel" and (connector == "y" and (lemma .. "y" .. c .. "n" .. c .. "z") or (lemma .. "n" .. c .. "z")) or (lemma .. c .. "n" .. c .. "z"),
    ["3p_spos_nom"] = lemma .. "l" .. o .. "r" .. get_harmony(o, "close")
  }

  return {}
end

function export.poss(lemma, change)
  return export.possessive(lemma, change)
end

--[=[
This function generates the predicative declension forms.

p.pred() is an alias for this function, as defined below.
]=]

function export.predicative(lemma)

end

function export.pred(lemma)
  return export.predicative(lemma)
end

--[=[
This function generates the nominal declension forms. It should be used with nouns, pronouns, adjectives, numerals, infinitives and participles.

p.nomi() is an alias for this function, as defined below.
]=]

function export.nominal(lemma, change)

end

function export.nomi(lemma)
  return export.nominal(lemma)
end

--[=[
This function generates the verb inflection forms.
]=]

function export.verb(lemma, d)
  local stem = mw.ustring.sub(lemma, 1, -4)
end

--[=[
This is the core function that generates all the necessary data for an inflection table.
]=]

function export._main(lemma, pos)
  if #lemma == 0 then
    error("is the lemma in the room with us right now? one must be provided.")
  end

  local parts_of_speech = {
    "noun",
    "adjective",
    "verb",
    "pronoun",
    "numeral"
  }
end

--[=[
This is the main function that should be invoked by templates, such as {{az-infl}}.
]=]

function export.main(frame)
  local args = frame["args"] or frame
  local lemma = args[1] or (frame:getParent() ~= nil and frame:getParent():getTitle() or "")
  local pos = args[2]
end

return export