Module:ar-nominals: difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
No edit summary |
No edit summary |
||
(One intermediate revision by the same user not shown) | |||
Line 54: | Line 54: | ||
-- Singular |
-- Singular |
||
data.forms["nom_sg_ind"] = {stem .. UN} |
data.forms["nom_sg_ind"] = {stem .. UN} |
||
data.forms["acc_sg_ind"] = {stem .. AN} |
data.forms["acc_sg_ind"] = {stem .. AN .. ALIF} |
||
data.forms["gen_sg_ind"] = {stem .. IN} |
data.forms["gen_sg_ind"] = {stem .. IN} |
||
data.forms["nom_sg_def"] = {"ال" .. stem .. U} |
data.forms["nom_sg_def"] = {"ال" .. stem .. U} |
||
Line 82: | Line 82: | ||
plstem = mw.ustring.gsub(stem, A .. TA .. "$", A .. ALIF .. TA) |
plstem = mw.ustring.gsub(stem, A .. TA .. "$", A .. ALIF .. TA) |
||
data.forms[" |
data.forms["nom_pl_ind"] = {plstem .. UN} |
||
data.forms[" |
data.forms["acc_pl_ind"] = {plstem .. IN .. ALIF} |
||
data.forms[" |
data.forms["gen_pl_ind"] = {plstem .. IN} |
||
data.forms[" |
data.forms["nom_pl_def"] = {"ال" .. plstem .. U} |
||
data.forms[" |
data.forms["acc_pl_def"] = {"ال" .. plstem .. I} |
||
data.forms[" |
data.forms["gen_pl_def"] = {"ال" .. plstem .. I} |
||
data.forms[" |
data.forms["nom_pl_con"] = {plstem .. U} |
||
data.forms[" |
data.forms["acc_pl_con"] = {plstem .. I} |
||
data.forms[" |
data.forms["gen_pl_con"] = {plstem .. I} |
||
elseif mw.ustring.find(stem, A .. ALIF .. TA .. "$") then |
elseif mw.ustring.find(stem, A .. ALIF .. TA .. "$") then |
||
plstem = mw.ustring.gsub(stem, A .. ALIF .. TA .. "$", A .. YA .. A .. ALIF .. TA) |
plstem = mw.ustring.gsub(stem, A .. ALIF .. TA .. "$", A .. YA .. A .. ALIF .. TA) |
||
local plstem2 = mw.ustring.gsub(stem, A .. ALIF .. TA .. "$", A .. WAW .. A .. ALIF .. TA) |
local plstem2 = mw.ustring.gsub(stem, A .. ALIF .. TA .. "$", A .. WAW .. A .. ALIF .. TA) |
||
data.forms[" |
data.forms["nom_pl_ind"] = {plstem .. UN, plstem2 .. UN} |
||
data.forms[" |
data.forms["acc_pl_ind"] = {plstem .. IN, plstem2 .. IN .. ALIF} |
||
data.forms[" |
data.forms["gen_pl_ind"] = {plstem .. IN, plstem2 .. IN} |
||
data.forms[" |
data.forms["nom_pl_def"] = {"ال" .. plstem .. U, "ال" .. plstem2 .. U} |
||
data.forms[" |
data.forms["acc_pl_def"] = {"ال" .. plstem .. I, "ال" .. plstem2 .. I} |
||
data.forms[" |
data.forms["gen_pl_def"] = {"ال" .. plstem .. I, "ال" .. plstem2 .. I} |
||
data.forms[" |
data.forms["nom_pl_con"] = {plstem .. U, plstem2 .. U} |
||
data.forms[" |
data.forms["acc_pl_con"] = {plstem .. I, plstem2 .. I} |
||
data.forms[" |
data.forms["gen_pl_con"] = {plstem .. I, plstem2 .. I} |
||
else |
else |
||
data.forms["nom_pl_ind"] = {stem .. U .. WAW .. NUN .. A} |
data.forms["nom_pl_ind"] = {stem .. U .. WAW .. NUN .. A} |
||
data.forms["acc_pl_ind"] = {stem .. I .. YA .. NUN .. A} |
data.forms["acc_pl_ind"] = {stem .. I .. YA .. NUN .. A .. ALIF} |
||
data.forms["gen_pl_ind"] = {stem .. I .. YA .. NUN .. A} |
data.forms["gen_pl_ind"] = {stem .. I .. YA .. NUN .. A} |
||
data.forms["nom_pl_def"] = {"ال" .. stem .. U .. WAW .. NUN .. A} |
data.forms["nom_pl_def"] = {"ال" .. stem .. U .. WAW .. NUN .. A} |
||
Line 120: | Line 120: | ||
data.forms["nom_pl_ind"] = {plstem .. UN} |
data.forms["nom_pl_ind"] = {plstem .. UN} |
||
data.forms["acc_pl_ind"] = {plstem .. AN} |
data.forms["acc_pl_ind"] = {plstem .. AN .. ALIF} |
||
data.forms["gen_pl_ind"] = {plstem .. IN} |
data.forms["gen_pl_ind"] = {plstem .. IN} |
||
data.forms["nom_pl_def"] = {"ال" .. plstem .. U} |
data.forms["nom_pl_def"] = {"ال" .. plstem .. U} |
Revision as of 01:40, 29 November 2014
- The following documentation is located at Module:ar-nominals/documentation. [edit] Categories were auto-generated by Module:module categorization. [edit]
- Useful links: subpage list • links • transclusions • testcases • sandbox
This module implements template {{ar-decl-noun}}
, {{ar-decl-adj}}
, {{ar-decl-coll-noun}}
, {{ar-decl-sing-noun}}
, {{ar-decl-gendered-noun}}
, and {{ar-decl-numeral}}
.
For testcases, see Module:ar-nominals/testcases.
Functions
show_noun(frame)
- Main entry point for implementing
{{ar-decl-noun}}
.
show_adj(frame)
- Main entry point for implementing
{{ar-decl-adj}}
.
show_coll_noun(frame)
- Main entry point for implementing
{{ar-decl-coll-noun}}
.
show_sing_noun(frame)
- Main entry point for implementing
{{ar-decl-sing-noun}}
.
show_gendered_noun(frame)
- Main entry point for implementing
{{ar-decl-gendered-noun}}
.
show_numeral(frame)
- Main entry point for implementing
{{ar-decl-numeral}}
.
detect_type(stem, isfem, num)
- Detect declension of noun or adjective stem or lemma. We allow triptotes, diptotes and sound plurals to either come with ʾiʿrāb or not. We detect some cases where vowels are missing, when it seems fairly unambiguous to do so.
isfem
is true if we are dealing with a feminine form (only for adjectives).num
is sg, du or pl depending on the intended number of the noun or adjective.
stem_and_type(word, sg, sgtype, isfem, num)
- Return stem and declension of an argument given the singular form and declension type, whether this is a feminine form (only for adjectives), and the intended number of the noun or adjective (sg, du or pl). Singular form and type only used when inferring plural based on singular (e.g. when argument is a bare plural declension type such as 'sfp' for the sound feminine plural).
local m_utilities = require("Module:utilities")
local m_links = require("Module:links")
local lang = require("Module:languages").getByCode("ar")
local u = mw.ustring.char
local ALIF = u(0x0627)
local TA = u(0x0637)
local NUN = u(0x0646)
local WAW = u(0x0648)
local YA = u(0x064A)
local A = u(0x064E) -- fatḥah
local AN = u(0x064B) -- fatḥatan
local U = u(0x064F) -- ḍammah
local UN = u(0x064C) -- ḍammatan
local I = u(0x0650) -- kasrah
local IN = u(0x064D) -- kasratan
local SUKUN = u(0x0652)
local export = {}
-- Functions that do the actual inflecting by creating the forms of a basic term.
local inflections = {}
-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)
local infl_type = frame.args[1] or error("Inflection type has not been specified. Please pass parameter 1 to the module invocation")
local args = frame:getParent().args
if not inflections[infl_type] then
error("Unknown inflection type '" .. infl_type .. "'")
end
local data = {forms = {}, title = nil, categories = {}}
-- Generate the forms
inflections[infl_type](args, data)
return make_table(data) .. m_utilities.format_categories(data.categories, lang)
end
-- Inflection functions
inflections["triptote"] = function(args, data)
local stem = args[1] or (mw.title.getCurrentTitle().nsText == "Template" and "{{{1}}}") or ""; if stem == "" then error("Parameter 1 (singular stem) may not be empty.") end
local plstem = args[2] or (mw.title.getCurrentTitle().nsText == "Template" and "{{{1}}}") or ""; if plstem == "" then error("Parameter 2 (plural stem) may not be empty.") end
data.title = "regular triptote"
table.insert(data.categories, lang:getCanonicalName() .. " regular triptote nouns")
-- Singular
data.forms["nom_sg_ind"] = {stem .. UN}
data.forms["acc_sg_ind"] = {stem .. AN .. ALIF}
data.forms["gen_sg_ind"] = {stem .. IN}
data.forms["nom_sg_def"] = {"ال" .. stem .. U}
data.forms["acc_sg_def"] = {"ال" .. stem .. A}
data.forms["gen_sg_def"] = {"ال" .. stem .. I}
data.forms["nom_sg_con"] = {stem .. U}
data.forms["acc_sg_con"] = {stem .. A}
data.forms["gen_sg_con"] = {stem .. I}
-- Dual
data.forms["nom_du_ind"] = {stem .. A .. ALIF .. NUN .. I}
data.forms["acc_du_ind"] = {stem .. A .. YA .. SUKUN .. NUN .. I}
data.forms["gen_du_ind"] = {stem .. A .. YA .. SUKUN .. NUN .. I}
data.forms["nom_du_def"] = {"ال" .. stem .. A .. ALIF .. NUN .. I}
data.forms["acc_du_def"] = {"ال" .. stem .. A .. YA .. SUKUN .. NUN .. I}
data.forms["gen_du_def"] = {"ال" .. stem .. A .. YA .. SUKUN .. NUN .. I}
data.forms["nom_du_con"] = {stem .. A .. ALIF}
data.forms["acc_du_con"] = {stem .. A .. YA .. SUKUN}
data.forms["gen_du_con"] = {stem .. A .. YA .. SUKUN}
-- Plural
if plstem == "-" then
-- Sound plural
data.title = data.title .. ", sound plural"
if mw.ustring.find(stem, A .. TA .. "$") then
plstem = mw.ustring.gsub(stem, A .. TA .. "$", A .. ALIF .. TA)
data.forms["nom_pl_ind"] = {plstem .. UN}
data.forms["acc_pl_ind"] = {plstem .. IN .. ALIF}
data.forms["gen_pl_ind"] = {plstem .. IN}
data.forms["nom_pl_def"] = {"ال" .. plstem .. U}
data.forms["acc_pl_def"] = {"ال" .. plstem .. I}
data.forms["gen_pl_def"] = {"ال" .. plstem .. I}
data.forms["nom_pl_con"] = {plstem .. U}
data.forms["acc_pl_con"] = {plstem .. I}
data.forms["gen_pl_con"] = {plstem .. I}
elseif mw.ustring.find(stem, A .. ALIF .. TA .. "$") then
plstem = mw.ustring.gsub(stem, A .. ALIF .. TA .. "$", A .. YA .. A .. ALIF .. TA)
local plstem2 = mw.ustring.gsub(stem, A .. ALIF .. TA .. "$", A .. WAW .. A .. ALIF .. TA)
data.forms["nom_pl_ind"] = {plstem .. UN, plstem2 .. UN}
data.forms["acc_pl_ind"] = {plstem .. IN, plstem2 .. IN .. ALIF}
data.forms["gen_pl_ind"] = {plstem .. IN, plstem2 .. IN}
data.forms["nom_pl_def"] = {"ال" .. plstem .. U, "ال" .. plstem2 .. U}
data.forms["acc_pl_def"] = {"ال" .. plstem .. I, "ال" .. plstem2 .. I}
data.forms["gen_pl_def"] = {"ال" .. plstem .. I, "ال" .. plstem2 .. I}
data.forms["nom_pl_con"] = {plstem .. U, plstem2 .. U}
data.forms["acc_pl_con"] = {plstem .. I, plstem2 .. I}
data.forms["gen_pl_con"] = {plstem .. I, plstem2 .. I}
else
data.forms["nom_pl_ind"] = {stem .. U .. WAW .. NUN .. A}
data.forms["acc_pl_ind"] = {stem .. I .. YA .. NUN .. A .. ALIF}
data.forms["gen_pl_ind"] = {stem .. I .. YA .. NUN .. A}
data.forms["nom_pl_def"] = {"ال" .. stem .. U .. WAW .. NUN .. A}
data.forms["acc_pl_def"] = {"ال" .. stem .. I .. YA .. NUN .. A}
data.forms["gen_pl_def"] = {"ال" .. stem .. I .. YA .. NUN .. A}
data.forms["nom_pl_con"] = {stem .. U .. WAW}
data.forms["acc_pl_con"] = {stem .. I .. YA}
data.forms["gen_pl_con"] = {stem .. I .. YA}
end
else
-- Broken plural
data.title = data.title .. ", broken plural"
data.forms["nom_pl_ind"] = {plstem .. UN}
data.forms["acc_pl_ind"] = {plstem .. AN .. ALIF}
data.forms["gen_pl_ind"] = {plstem .. IN}
data.forms["nom_pl_def"] = {"ال" .. plstem .. U}
data.forms["acc_pl_def"] = {"ال" .. plstem .. A}
data.forms["gen_pl_def"] = {"ال" .. plstem .. I}
data.forms["nom_pl_con"] = {plstem .. U}
data.forms["acc_pl_con"] = {plstem .. A}
data.forms["gen_pl_con"] = {plstem .. I}
end
end
-- Make the table
function make_table(data)
local function show_form(form)
if not form then
return "—"
elseif type(form) ~= "table" then
error("a non-table value was given in the list of inflected forms.")
end
local ret = {}
for key, subform in ipairs(form) do
local translit = lang:transliterate(subform)
if subform:find("{{{") then
table.insert(ret, m_links.full_link(nil, subform, lang, nil, nil, nil, {tr = "-"}, false) .. (translit and "<br/><span style=\"color: #888\">" .. translit .. "</span>" or ""))
else
table.insert(ret, m_links.full_link(subform, nil, lang, nil, nil, nil, {tr = "-"}, false) .. (translit and "<br/><span style=\"color: #888\">" .. translit .. "</span>" or ""))
end
end
return table.concat(ret, "<br/>")
end
local function repl(param)
if param == "lemma" then
return m_links.full_link(nil, mw.title.getCurrentTitle().text, lang, nil, "term", nil, {tr = "-"}, false)
elseif param == "info" then
return data.title and " (" .. data.title .. ")" or ""
else
return show_form(data.forms[param])
end
end
local wikicode = [=[<div class="NavFrame" style="width: 40%">
<div class="NavHead">Inflection of {{{lemma}}}{{{info}}}</div>
<div class="NavContent">
{| class="inflection-table" style="border-width: 1px; border-collapse: collapse; background:#F9F9F9; text-align:center; width:100%;"
|-
! style="background: #CDCDCD; width:25%;" | Singular
! style="background: #CDCDCD; width:25%;" | Indefinite
! style="background: #CDCDCD; width:25%;" | Definite
! style="background: #CDCDCD; width:25%;" | Construct
|-
! style="background: #EFEFEF;" | Nominative
| {{{nom_sg_ind}}}
| {{{nom_sg_def}}}
| {{{nom_sg_con}}}
|-
! style="background: #EFEFEF;" | Accusative
| {{{acc_sg_ind}}}
| {{{acc_sg_def}}}
| {{{acc_sg_con}}}
|-
! style="background: #EFEFEF;" | Genitive
| {{{gen_sg_ind}}}
| {{{gen_sg_def}}}
| {{{gen_sg_con}}}
|-
! style="background: #CDCDCD;" | Dual
! style="background: #CDCDCD;" | Indefinite
! style="background: #CDCDCD;" | Definite
! style="background: #CDCDCD;" | Construct
|-
! style="background: #EFEFEF;" | Nominative
| {{{nom_du_ind}}}
| {{{nom_du_def}}}
| {{{nom_du_con}}}
|-
! style="background: #EFEFEF;" | Accusative
| {{{acc_du_ind}}}
| {{{acc_du_def}}}
| {{{acc_du_con}}}
|-
! style="background: #EFEFEF;" | Genitive
| {{{gen_du_ind}}}
| {{{gen_du_def}}}
| {{{gen_du_con}}}
|-
! style="background: #CDCDCD;" | Plural
! style="background: #CDCDCD;" | Indefinite
! style="background: #CDCDCD;" | Definite
! style="background: #CDCDCD;" | Construct
|-
! style="background: #EFEFEF;" | Nominative
| {{{nom_pl_ind}}}
| {{{nom_pl_def}}}
| {{{nom_pl_con}}}
|-
! style="background: #EFEFEF;" | Accusative
| {{{acc_pl_ind}}}
| {{{acc_pl_def}}}
| {{{acc_pl_con}}}
|-
! style="background: #EFEFEF;" | Genitive
| {{{gen_pl_ind}}}
| {{{gen_pl_def}}}
| {{{gen_pl_con}}}
|}
</div>
</div>]=]
return mw.ustring.gsub(wikicode, "{{{([a-z_]+)}}}", repl)
end
return export