Module:form of: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 9: Line 9:
local form_of_functions_module = "Module:form of/functions"
local form_of_functions_module = "Module:form of/functions"
local form_of_lang_data_module_prefix = "Module:form of/lang-data/"
local form_of_lang_data_module_prefix = "Module:form of/lang-data/"
local form_of_pos_module = "Module:form of/pos"
local function_module = "Module:fun"
local function_module = "Module:fun"
local headword_data_module = "Module:headword/data"
local headword_data_module = "Module:headword/data"
Line 19: Line 18:
local string_utilities_module = "Module:string utilities"
local string_utilities_module = "Module:string utilities"
local table_module = "Module:table"
local table_module = "Module:table"
local table_deep_equals_module = "Module:table/deepEquals"
local utilities_module = "Module:utilities"
local utilities_module = "Module:utilities"


Line 60: Line 60:


local function deep_equals(...)
local function deep_equals(...)
deep_equals = require(table_module).deepEquals
deep_equals = require(table_deep_equals_module)
return deep_equals(...)
return deep_equals(...)
end
end
Line 196: Line 196:
local m_pos_data
local m_pos_data
local function get_m_pos_data()
local function get_m_pos_data()
m_pos_data, get_m_pos_data = load_data(form_of_pos_module), nil
m_pos_data, get_m_pos_data = load_data(headword_data_module).pos_aliases, nil
return m_pos_data
return m_pos_data
end
end
Line 217: Line 217:
* [[Module:form of/cats]] is a data-only file listing the language-specific categories that are added when the
* [[Module:form of/cats]] is a data-only file listing the language-specific categories that are added when the
   appropriate combinations of tags are seen for a given language.
   appropriate combinations of tags are seen for a given language.
* [[Module:form of/pos]] is a data-only file listing the recognized parts of speech and their abbreviations, used for
  categorization. FIXME: This should be unified with the parts of speech listed in [[Module:links]].
* [[Module:form of/functions]] contains functions for use with [[Module:form of/data/1]] and [[Module:form of/cats]].
* [[Module:form of/functions]] contains functions for use with [[Module:form of/data/1]] and [[Module:form of/cats]].
   They are contained in this module because data-only modules can't contain code. The functions in this file are of two
   They are contained in this module because data-only modules can't contain code. The functions in this file are of two
Line 277: Line 275:


local function wrap_in_span(text, classes)
local function wrap_in_span(text, classes)
return ("<span class='%s'>%s</span>"):format(classes, text)
if classes then
return ("<span class='%s'>%s</span>"):format(classes, text)
else
return text
end
end
end


Line 294: Line 296:
   text.
   text.
* `.lemma_face`: "Face" to use when displaying the lemma objects. Usually should be set to {"term"}.
* `.lemma_face`: "Face" to use when displaying the lemma objects. Usually should be set to {"term"}.
* `.conj`: Conjunction or separator to use when joining multiple lemma objects. Defaults to {"and"}.
* `.enclitics`: List of enclitics to display after the lemmas, in parens.
* `.enclitics`: List of enclitics to display after the lemmas, in parens.
* `.enclitic_conj`: Conjunction or separator to use when joining multiple enclitics. Defaults to {"and"}.
* `.base_lemmas`: List of base lemmas to display after the lemmas, in the case where the lemmas in `.lemmas` are
* `.base_lemmas`: List of base lemmas to display after the lemmas, in the case where the lemmas in `.lemmas` are
   themselves forms of another lemma (the base lemma), e.g. a comparative, superlative or participle. Each object is of
   themselves forms of another lemma (the base lemma), e.g. a comparative, superlative or participle. Each object is of
   the form { { paramobj = PARAM_OBJ, lemmas = {LEMMA_OBJ, LEMMA_OBJ, ...} }} where PARAM_OBJ describes the properties
   the form { { paramobj = PARAM_OBJ, lemmas = {LEMMA_OBJ, LEMMA_OBJ, ...}, conj = "CONJ" }} where PARAM_OBJ describes
  of the base lemma parameter (i.e. the relationship between the intermediate and base lemmas) and LEMMA_OBJ is an
  the properties of the base lemma parameter (i.e. the relationship between the intermediate and base lemmas);
  object suitable to be passed to {full_link()} in [[Module:links]]. PARAM_OBJ is of the format
  LEMMA_OBJ is an object suitable to be passed to {full_link()} in [[Module:links]]; and CONJ is the conjunction to
  join multiple lemmas with, defaulting to {"and"}. PARAM_OBJ is of the format
   { { param = "PARAM", tags = {"TAG", "TAG", ...} } where PARAM is the name of the parameter to {{tl|inflection of}}
   { { param = "PARAM", tags = {"TAG", "TAG", ...} } where PARAM is the name of the parameter to {{tl|inflection of}}
   etc. that holds the base lemma(s) of the specified relationship and the tags describe the relationship, such as
   etc. that holds the base lemma(s) of the specified relationship and the tags describe the relationship, such as
   { {"comd"}} or { {"past", "part"}}.
   { {"comd"}} or { {"past", "part"}}.
* `.text_classes`: CSS classes used to wrap the tag text and lemma links. Default is {"form-of-definition use-with-mention"}
* `.text_classes`: CSS classes used to wrap the tag text and lemma links. Default is
  for the tag text and lemma links, and additionally {"form-of-definition-link"} specifically for the lemma links.
  {"form-of-definition use-with-mention"}. Use `false` for no wrapping.
   (FIXME: Should separate out the lemma links into their own field.)
* `.lemma_classes`: Additional CSS classes used to wrap the lemma links. Default is {"form-of-definition-link"}.
   Use `false` for no wrapping.
* `.posttext`: Additional text to display after the lemma links.]==]
* `.posttext`: Additional text to display after the lemma links.]==]
function export.format_form_of(data)
function export.format_form_of(data)
Line 311: Line 317:
error("Internal error: First argument must now be a table of arguments")
error("Internal error: First argument must now be a table of arguments")
end
end
local text_classes = data.text_classes or "form-of-definition use-with-mention"
local text_classes = data.text_classes
local lemma_classes = data.text_classes or "form-of-definition-link"
if text_classes == nil then
text_classes = "form-of-definition use-with-mention"
end
local lemma_classes = data.lemma_classes
if lemma_classes == nil then
lemma_classes = "form-of-definition-link"
end
local parts = {}
local parts = {}
insert(parts, "<span class='" .. text_classes .. "'>")
if text_classes then
insert(parts, "<span class='" .. text_classes .. "'>")
end
insert(parts, data.text)
insert(parts, data.text)
if data.text ~= "" and data.lemmas then
if data.text ~= "" and data.lemmas then
Line 326: Line 340:
for _, lemma in ipairs(data.lemmas) do
for _, lemma in ipairs(data.lemmas) do
insert(formatted_terms, wrap_in_span(
insert(formatted_terms, wrap_in_span(
full_link(lemma, data.lemma_face), lemma_classes
full_link(lemma, data.lemma_face, nil, "show qualifiers"), lemma_classes
))
))
end
end
insert(parts, serial_comma_join(formatted_terms))
insert(parts, serial_comma_join(formatted_terms, {conj = data.conj or "and"}))
end
end
end
end
Line 335: Line 349:
-- The outer parens need to be outside of the text_classes span so they show in upright instead of italic, or
-- The outer parens need to be outside of the text_classes span so they show in upright instead of italic, or
-- they will clash with upright parens generated by link annotations such as transliterations and pos=.
-- they will clash with upright parens generated by link annotations such as transliterations and pos=.
insert(parts, "</span>")
if text_classes then
insert(parts, "</span>")
end
local formatted_terms = {}
local formatted_terms = {}
for _, enclitic in ipairs(data.enclitics) do
for _, enclitic in ipairs(data.enclitics) do
Line 345: Line 361:
insert(parts, " (")
insert(parts, " (")
insert(parts, wrap_in_span("with enclitic" .. (#data.enclitics > 1 and "s" or "") .. " ", text_classes))
insert(parts, wrap_in_span("with enclitic" .. (#data.enclitics > 1 and "s" or "") .. " ", text_classes))
insert(parts, serial_comma_join(formatted_terms))
insert(parts, serial_comma_join(formatted_terms, {conj = data.enclitic_conj or "and"}))
insert(parts, ")")
insert(parts, ")")
insert(parts, "<span class='" .. text_classes .. "'>")
if text_classes then
insert(parts, "<span class='" .. text_classes .. "'>")
end
end
end
if data.base_lemmas and #data.base_lemmas > 0 then
if data.base_lemmas and #data.base_lemmas > 0 then
for _, base_lemma in ipairs(data.base_lemmas) do
for _, base_lemma in ipairs(data.base_lemmas) do
insert(parts, ", the </span>")
insert(parts, ", the ")
insert(parts, (tagged_inflections{
if text_classes then
insert(parts, "</span>")
end
insert(parts, (tagged_inflections {
lang = base_lemma.lemmas[1].lang,
lang = base_lemma.lemmas[1].lang,
tags = base_lemma.paramobj.tags,
tags = base_lemma.paramobj.tags,
lemmas = base_lemma.lemmas,
lemmas = base_lemma.lemmas,
conj = base_lemma.conj or "and",
lemma_face = data.lemma_face,
lemma_face = data.lemma_face,
no_format_categories = true,
no_format_categories = true,
Line 361: Line 383:
text_classes = data.text_classes,
text_classes = data.text_classes,
}))
}))
insert(parts, "<span class='" .. text_classes .. "'>")
if text_classes then
insert(parts, "<span class='" .. text_classes .. "'>")
end
end
end
end
end
Line 369: Line 393:
insert(parts, data.posttext)
insert(parts, data.posttext)
end
end
insert(parts, "</span>")
if text_classes then
insert(parts, "</span>")
end
return concat(parts)
return concat(parts)
end
end
Line 439: Line 465:
return tag
return tag
end
end
 
return expansion
return expansion
end
end
Line 479: Line 505:
end
end
tag = expansion
tag = expansion
return tag
return tag
end
end
Line 507: Line 534:
end
end
local normtags = {}
local normtags = {}
for _, component in ipairs(components) do
for _, component in ipairs(components) do
insert(normtags, normalize_single_tag(component, lang, do_track))
insert(normtags, normalize_single_tag(component, lang, do_track))
Line 540: Line 566:
local normtags = {}
local normtags = {}
for _, single_tag in ipairs(split_tags) do
for _, single_tag in ipairs(split_tags) do
insert(normtags, normalize_multipart_component(single_tag, lang, do_track))
insert(normtags, normalize_multipart_component(single_tag, lang, do_track))
end
end
Line 586: Line 611:


for _, tag in ipairs(tag_set) do
for _, tag in ipairs(tag_set) do
-- Expand the tag, which may generate a new tag (either a fully canonicalized tag, a multipart tag, or a list
-- Expand the tag, which may generate a new tag (either a fully canonicalized tag, a multipart tag, or a list
-- of tags).
-- of tags).
Line 599: Line 623:


for _, t in ipairs(tag) do
for _, t in ipairs(tag) do
insert(output_tag_set, normalize_tag(t, lang, do_track))
insert(output_tag_set, normalize_tag(t, lang, do_track))
end
end
Line 614: Line 637:
output_tag_set = {}
output_tag_set = {}
for i, tag in ipairs(tag_set) do
for i, tag in ipairs(tag_set) do
-- Expand the tag, which may generate a new tag (either a fully canonicalized tag, a multipart tag, or a list
-- Expand the tag, which may generate a new tag (either a fully canonicalized tag, a multipart tag, or a list
-- of tags).
-- of tags).
Line 728: Line 750:
display = "[[w:" .. normtag .. "|" .. display .. "]]"
display = "[[w:" .. normtag .. "|" .. display .. "]]"
elseif glossary == m_data.APPENDIX then
elseif glossary == m_data.APPENDIX then
display = "[[wikt:Appendix:Glossary#" .. anchor_encode(normtag) .. "|" .. display .. "]]"
display = "[[Appendix:Glossary#" .. anchor_encode(normtag) .. "|" .. display .. "]]"
elseif type(glossary) ~= "string" then
elseif type(glossary) ~= "string" then
error(("Internal error: Wrong type %s for glossary value %s for tag %s"):format(
error(("Internal error: Wrong type %s for glossary value %s for tag %s"):format(
Line 744: Line 766:
end
end
if not link then
if not link then
display = "[[wikt:Appendix:Glossary#" .. anchor_encode(glossary) .. "|" .. display .. "]]"
display = "[[Appendix:Glossary#" .. anchor_encode(glossary) .. "|" .. display .. "]]"
end
end
end
end
Line 1,202: Line 1,224:
   {{tl|inflection of}}.
   {{tl|inflection of}}.
* `.pagename`: Page name of "current" page or nil to use the actual page title; for testing purposes.
* `.pagename`: Page name of "current" page or nil to use the actual page title; for testing purposes.
* `.conj`: Conjunction or separator to use when joining multiple lemma objects. Defaults to {"and"}.
* `.enclitics`: List of enclitics to display after the lemmas, in parens.
* `.enclitics`: List of enclitics to display after the lemmas, in parens.
* `.enclitic_conj`: Conjunction or separator to use when joining multiple enclitics. Defaults to {"and"}.
* `.no_format_categories`: If true, don't format the categories derived from the inflection tags; just return them.
* `.no_format_categories`: If true, don't format the categories derived from the inflection tags; just return them.
* `.sort`: Sort key for formatted categories. Ignored when `.no_format_categories` = {true}.
* `.sort`: Sort key for formatted categories. Ignored when `.no_format_categories` = {true}.
Line 1,211: Line 1,235:
* `.posttext`: Additional text to display after the lemma links.
* `.posttext`: Additional text to display after the lemma links.
* `.text_classes`: CSS classes used to wrap the tag text and lemma links. Default is
* `.text_classes`: CSS classes used to wrap the tag text and lemma links. Default is
  {"form-of-definition use-with-mention"} for the tag text, {"form-of-definition-link"} for the lemma links. (FIXME:
  {"form-of-definition use-with-mention"}.
  Should separate out the lemma links into their own field.)
* `.lemma_classes`: Additional CSS classes used to wrap the lemma links. Default is {"form-of-definition-link"}.
`.joiner`: Override the joiner (normally a slash) used to join multipart tags. You should normally not specify this.
`.joiner`: Override the joiner (normally a slash) used to join multipart tags. You should normally not specify this.


Line 1,310: Line 1,334:
format_data.posttext = (data.posttext or "") .. ":"
format_data.posttext = (data.posttext or "") .. ":"
local link = format_form_of(format_data)
local link = format_form_of(format_data)
local text_classes = data.text_classes or "form-of-definition use-with-mention"
local text_classes = data.text_classes
if text_classes == nil then
text_classes = "form-of-definition use-with-mention"
end
for i, inflection in ipairs(inflections) do
for i, inflection in ipairs(inflections) do
inflections[i] = "\n## " .. format_labels(inflection.labels, data, false) ..
inflections[i] = "\n## " .. format_labels(inflection.labels, data, false) ..
"<span class='" .. text_classes .. "'>" .. inflection.infl_text .. "</span>"
wrap_in_span(inflection.infl_text, text_classes)
end
end
formatted_text = link .. concat(inflections)
formatted_text = link .. concat(inflections)
Line 1,342: Line 1,369:
export.form_of_functions_module = form_of_functions_module
export.form_of_functions_module = form_of_functions_module
export.form_of_lang_data_module_prefix = form_of_lang_data_module_prefix
export.form_of_lang_data_module_prefix = form_of_lang_data_module_prefix
export.form_of_pos_module = form_of_pos_module
export.headword_data_module = headword_data_module -- so all form-of modules stay in sync


return export
return export