Saltu al enhavo

Modulo:meoformo

El Vikivortaro
Ĉi tiu modulo estas multfoje bindita.
Se vi konas la eblajn sekvojn, tiam vi povas zorgeme ekredakti.
Se vi ne kuraĝas redakti tiam vi povas proponi la deziratan ŝanĝon en la diskutejo.
Memtesto disponeblas sur la dokumentaĵa subpaĝo.

--[===[

MODULE "MEOFORMO" (esperanto form)

"eo.wiktionary.org/wiki/Modulo:meoformo" <!--2021-Dec-30-->

Purpose: analyzes a flexion non-base form of an -eo- noun or adjective
         or verb, and returns selected one of 5 types of information,
         it can be the full base form or other

Utilo: analizas fleksian nebazan formon de -eo- substantivo aux adjektivo
       aux verbo, kaj redonas elektitan unu el 5 tipoj de informo,
       tio povas esti la plena baza formo aux alia

Manfaat: menganalisis sebuah bentuk fleksi pada nomina atau adjektiva
         atau verba ...

Syfte: analyserar en boejningsform hos ett -eo- substantiv eller adjektiv
       eller verb, och levererar ...

Used by templates / Uzata far sxablonoj:
- only "form-eo" (not to be called from any other place)

Required submodules / Bezonataj submoduloj / Submodul yang diperlukan: none

This module is special in that it takes parameters both those sent
to itself (own frame) and those sent to the caller (caller's frame).
This module needs parameters that are additional to or different from
parameters submitted to the calling template.

The one hidden parameter can be on our own or on the caller's frame. If the
parameter is not found on our own frame, the caller's one is peeked. This
way we can avoid forwarding that does not work for non-existent parameters
(non-existent ie nil becomes empty string, not appreciated).

Parameters: * 1 anonymous obligatory parameter :
                type of information requested :
                * "B" for base form
                * "D" for description, or "T" for
                type, or "R" for root, or "F"
                anything else is an error
            * 1 hidden named parameter :
              * "pagenameoverridetestonly="

Returned: * full base form, or description, or flexion type ("OA" or
            "VE"), or root, or ending, or empty on error

This module is unbreakable (when called with correct module name
and function name).

Cxi tiu modulo estas nerompebla (kiam vokita kun gxustaj nomo de modulo
kaj nomo de funkcio).

: ---------------------------------------

* #T00 ("B", page "katoj")
* expected result: "kato"
* actual result: "{{#invoke:meoformo|ek|B|pagenameoverridetestonly=katoj}}"

::* #T01 ("D", page "katoj")
::* expected result: "plurala formo de substantivo"
::* actual result: "{{#invoke:meoformo|ek|D|pagenameoverridetestonly=katoj}}"

* #T02 ("B", page "atomojn")
* expected result: "atomo"
* actual result: "{{#invoke:meoformo|ek|B|pagenameoverridetestonly=atomojn}}"

::* #T03 ("D", page "atomojn")
::* expected result: "akuzativa plurala formo de substantivo"
::* actual result: "{{#invoke:meoformo|ek|D|pagenameoverridetestonly=atomojn}}"

* #T04 ("B", page "mojosaj")
* expected result: "mojosa"
* actual result: "{{#invoke:meoformo|ek|B|pagenameoverridetestonly=mojosaj}}"

::* #T05 ("D", page "mojosaj")
::* expected result: "plurala formo de adjektivo"
::* actual result: "{{#invoke:meoformo|ek|D|pagenameoverridetestonly=mojosaj}}"

* #T06 ("B", page "MOjosaj", bad but gives a result nevertheless)
* expected result: "MOjosa"
* actual result: "{{#invoke:meoformo|ek|B|pagenameoverridetestonly=MOjosaj}}"

: ---------------------------------------

* #T10 ("B", page "kato", error since base form)
* expected result: ""
* actual result: "{{#invoke:meoformo|ek|B|pagenameoverridetestonly=kato}}"

::* #T11 ("B", page "oj", error since root empty)
::* expected result: ""
::* actual result: "{{#invoke:meoformo|ek|B|pagenameoverridetestonly=oj}}"

* #T12 ("B", page "katuj", error since invalid form)
* expected result: ""
* actual result: "{{#invoke:meoformo|ek|B|pagenameoverridetestonly=katuj}}"

::* #T13 ("B", page "BANANOJ", error since root uppercase)
::* expected result: ""
::* actual result: "{{#invoke:meoformo|ek|B|pagenameoverridetestonly=BANANOJ}}"

* #T14 ("B|B", page "katoj", error due to excess parameter)
* expected result: ""
* actual result: "{{#invoke:meoformo|ek|B|B|pagenameoverridetestonly=katoj}}"

::* #T15 ("", page "katoj", error due to missing parameter)
::* expected result: ""
::* actual result: "{{#invoke:meoformo|ek|pagenameoverridetestonly=katoj}}"

* #T16 ("d", page "katoj", error due to invalid parameter)
* expected result: ""
* actual result: "{{#invoke:meoformo|ek|d|pagenameoverridetestonly=katoj}}"

: ---------------------------------------

* #T20 ("B", page "klopodas")
* expected result: "klopodi"
* actual result: "{{#invoke:meoformo|ek|B|pagenameoverridetestonly=klopodas}}"

::* #T21 ("D", page "klopodas")
::* expected result: "prezenca formo de verbo"
::* actual result: "{{#invoke:meoformo|ek|D|pagenameoverridetestonly=klopodas}}"

* #T22 ("B", page "klopodis")
* expected result: "klopodi"
* actual result: "{{#invoke:meoformo|ek|B|pagenameoverridetestonly=klopodis}}"

::* #T23 ("D", page "klopodis")
::* expected result: "pasinteca formo de verbo"
::* actual result: "{{#invoke:meoformo|ek|D|pagenameoverridetestonly=klopodis}}"

* #T24 ("D", page "klopodos")
* expected result: "futura formo de verbo"
* actual result: "{{#invoke:meoformo|ek|D|pagenameoverridetestonly=klopodos}}"

::* #T25 ("D", page "klopodu")
::* expected result: "imperativa formo de verbo"
::* actual result: "{{#invoke:meoformo|ek|D|pagenameoverridetestonly=klopodu}}"

: ---------------------------------------

* #T30 ("T", page "klopodu")
* expected result: "VE"
* actual result: "{{#invoke:meoformo|ek|T|pagenameoverridetestonly=klopodu}}"

::* #T31 ("R", page "klopodu")
::* expected result: "klopod"
::* actual result: "{{#invoke:meoformo|ek|R|pagenameoverridetestonly=klopodu}}"

* #T32 ("F", page "klopodu")
* expected result: "u"
* actual result: "{{#invoke:meoformo|ek|F|pagenameoverridetestonly=klopodu}}"

::* #T33 ("T", page "mojosajn")
::* expected result: "OA"
::* actual result: "{{#invoke:meoformo|ek|T|pagenameoverridetestonly=mojosajn}}"

: ---------------------------------------

]===]

local eoformo = {}

------------------------------------------------------------------------

---- CONSTANTS ----

------------------------------------------------------------------------

  local contabforms = {}
  contabforms[ 0] = {"on"  , "o" , "akuzativa formo de substantivo"}
  contabforms[ 1] = {"oj"  , "o" , "plurala formo de substantivo"}
  contabforms[ 2] = {"ojn" , "o" , "akuzativa plurala formo de substantivo"}
  contabforms[ 3] = {"an"  , "a" , "akuzativa formo de adjektivo"}
  contabforms[ 4] = {"aj"  , "a" , "plurala formo de adjektivo"}
  contabforms[ 5] = {"ajn" , "a" , "akuzativa plurala formo de adjektivo"}
  contabforms[ 6] = {"as"  , "i" , "prezenca formo de verbo"}
  contabforms[ 7] = {"is"  , "i" , "pasinteca formo de verbo"}
  contabforms[ 8] = {"os"  , "i" , "futura formo de verbo"}
  contabforms[ 9] = {"us"  , "i" , "kondicionala formo de verbo"}
  contabforms[10] = {"u"   , "i" , "imperativa formo de verbo"}

------------------------------------------------------------------------

---- MAIN EXPORTED FUNCTION ----

------------------------------------------------------------------------

function eoformo.ek (arxframent)

  -- general unknown type

  local vartmp = 0     -- variable without type

  -- special type "args" AKA "arx"

  local arxourown = 0  -- metaized "args" from our own "frame"
  local arxcaller = 0  -- metaized "args" from caller's "frame"

  -- general "str"

  local strpagename   = ""
  local strnebaza     = ""  -- & from table nebaza finajxo
  local strbazafinajx = ""  -- & from table baza finajxo
  local strpriskribo  = ""  -- & from table description
  local strrootradi   = ""
  local strtomp       = ""
  local strret        = ""  -- result string

  -- general "num"

  local numlopagena  = 0
  local numpanj      = 0
  local numindex3tab = 0

  -- general "boo"

  local booerr      = false
  local boohaveboob = false -- "B" or "D" or "T" or "R" or "F"
  local boohavedeed = false
  local boohavetipp = false
  local boohaveroot = false
  local boohavefina = false

  ---- GET THE ARX:ES ----

  arxourown = arxframent.args or {} -- "args" fr our own "frame"
  arxcaller = arxframent:getParent().args or {} -- "args" fr caller's "frame"

  ---- PROCESS ONE HIDDEN AND ONE OBLIGATORY ANONYMOUS PARAMETER ----

  strpagename = ''
  while (true) do -- fake loop
    booerr = true -- preliminary
    vartmp = arxourown['pagenameoverridetestonly']
    if (vartmp==nil) then
      vartmp = arxcaller['pagenameoverridetestonly']
    end--if
    if (type(vartmp)=="string") then
      numlopagena=string.len(vartmp)
      if ((numlopagena>=3 and numlopagena<=100)) then
        strpagename = vartmp -- no error possible here
      end--if
    end--if
    if (arxourown[2]~=nil) then -- undesirable
      break -- bad
    end--if
    vartmp = arxourown[1] -- "B" or "D" or "T" or "R" or "F"
    boohaveboob = (vartmp=="B")
    boohavedeed = (vartmp=="D")
    boohavetipp = (vartmp=="T")
    boohaveroot = (vartmp=="R")
    boohavefina = (vartmp=="F")
    booerr = ((not boohaveboob) and (not boohavedeed) and (not boohavetipp) and (not boohaveroot) and (not boohavefina))
    break -- good or bad
  end--while -- fake loop

  ---- SEIZE THE PAGENAME FROM MW AND CHECK IT ----

  -- must be 3...100 octet:s keep consistent with "pagenameoverridetestonly="

  -- ignore if type not "string", but otherwise do either buy it or brew error

  if ((not booerr) and (strpagename=='')) then
    vartmp = mw.title.getCurrentTitle().text -- without namespace prefix
    if (type(vartmp)=="string") then
      numlopagena = string.len(vartmp)
      if ((numlopagena>=3) and (numlopagena<=100)) then
        strpagename = vartmp
      else
        booerr = true
      end--if
    end--if
  end--if

  booerr = booerr or (strpagename=='')

  ---- CARRY OUT THE HARD WORK ----

  -- example entry {"us" , "i" , "kondicionala formo de verbo"} it is a table

  numindex3tab = 0
  numlopagena = string.len(strpagename) -- 3...100
  while (true) do -- genuine loop walking through the table
    if (booerr) then
      break -- bad start
    end--if
    vartmp = contabforms [numindex3tab]
    if (type(vartmp)~="table") then
      booerr = true
      break -- end of outer table, NOT found
    end--if
    strnebaza     = vartmp[1] -- can be "us"
    strbazafinajx = vartmp[2] -- can be "i"
    strpriskribo  = vartmp[3] -- can be "kondicionala formo de verbo"
    numpanj = string.len(strnebaza) -- 1...3
    if ((numpanj==0) or (numpanj>3)) then
      booerr = true
      break -- table is broken
    end--if
    if (numlopagena>numpanj) then
      strtomp = string.sub(strpagename,(numlopagena-numpanj+1),numlopagena)
      if (strtomp==strnebaza) then
        break -- found it
      end--if
    end--if
    numindex3tab = numindex3tab + 1
  end--while
  if (not booerr) then
    strrootradi = string.sub(strpagename,1,(numlopagena-numpanj)) -- nonempty
    if (boohaveboob) then -- "B" -- full base form
      strret = strrootradi .. strbazafinajx
    end--if
    if (boohavedeed) then -- "D"
      strret = strpriskribo
    end--if
    if (boohavetipp) then -- "T" -- type (VE vs (SB or AJ))
      strret = "OA" -- gluO mojosA
      if (strbazafinajx=="i") then
        strret = "VE" -- VErbo
      end--if
    end--if
    if (boohaveroot) then -- "R"
      strret = strrootradi
    end--if
    if (boohavefina) then -- "F"
      strret = strnebaza
    end--if
  end--if

  ---- RETURN THE JUNK STRING ----

  return strret -- can be empty

end--function

  ---- RETURN THE JUNK LUA TABLE ----

return eoformo