45,333
edits
No edit summary |
No edit summary |
||
Line 148: | Line 148: | ||
table.insert(parts, "</span>") | table.insert(parts, "</span>") | ||
return table.concat(parts) | return table.concat(parts) | ||
end | |||
-- Add tracking category for PAGE when called from {{inflection of}} or | |||
-- similar TEMPLATE. The tracking category linked to is | |||
-- [[Template:tracking/inflection of/PAGE]]. | |||
local function infl_track(page) | |||
require("Module:debug").track("inflection of/" .. | |||
-- avoid including links in pages (may cause error) | |||
page:gsub("%[", "("):gsub("%]", ")"):gsub("|", "!")) | |||
end | end | ||
Line 202: | Line 212: | ||
if not expansion then | if not expansion then | ||
return tag | return tag | ||
end | |||
-- Maybe track the expansion if it's not the same as the raw tag. | |||
if do_track and expansion ~= tag and type(expansion) == "string" then | |||
infl_track("tag/" .. tag) | |||
end | end | ||
return expansion | return expansion | ||
Line 234: | Line 248: | ||
end | end | ||
tag = expansion | tag = expansion | ||
if not export.lookup_tag(tag) and do_track then | |||
-- If after all expansions and normalizations we don't recognize | |||
-- the canonical tag, track it. | |||
infl_track("unknown") | |||
infl_track("unknown/" .. tag) | |||
end | |||
return tag | return tag | ||
end | end | ||
Line 267: | Line 287: | ||
local normtags = {} | local normtags = {} | ||
for _, component in ipairs(components) do | for _, component in ipairs(components) do | ||
if do_track then | |||
-- There are multiple components; track each of the individual | |||
-- raw tags. | |||
infl_track("tag/" .. component) | |||
end | |||
table.insert(normtags, normalize_single_tag(component, do_track)) | table.insert(normtags, normalize_single_tag(component, do_track)) | ||
end | end | ||
Line 310: | Line 335: | ||
local normtags = {} | local normtags = {} | ||
for _, single_tag in ipairs(split_tags) do | for _, single_tag in ipairs(split_tags) do | ||
if do_track then | |||
-- If the tag was a multipart tag, track each of individual raw tags. | |||
infl_track("tag/" .. single_tag) | |||
end | |||
table.insert(normtags, normalize_multipart_component(single_tag, | table.insert(normtags, normalize_multipart_component(single_tag, | ||
recombine_multitags, do_track)) | recombine_multitags, do_track)) | ||
Line 335: | Line 364: | ||
-- form, i.e. as canonical-form tags joined by "//" and/or ":". | -- form, i.e. as canonical-form tags joined by "//" and/or ":". | ||
function export.normalize_tags(tags, recombine_multitags, do_track) | function export.normalize_tags(tags, recombine_multitags, do_track) | ||
-- We track usage of shortcuts, normalized forms and (in the case of | |||
-- multipart tags or list tags) intermediate forms. For example, | |||
-- if the tags 1s|mn|gen|indefinite are passed in, we track the following: | |||
-- [[Template:tracking/inflection of/tag/1s]] | |||
-- [[Template:tracking/inflection of/tag/1]] | |||
-- [[Template:tracking/inflection of/tag/s]] | |||
-- [[Template:tracking/inflection of/tag/first-person]] | |||
-- [[Template:tracking/inflection of/tag/singular]] | |||
-- [[Template:tracking/inflection of/tag/mn]] | |||
-- [[Template:tracking/inflection of/tag/m//n]] | |||
-- [[Template:tracking/inflection of/tag/m]] | |||
-- [[Template:tracking/inflection of/tag/n]] | |||
-- [[Template:tracking/inflection of/tag/masculine]] | |||
-- [[Template:tracking/inflection of/tag/neuter]] | |||
-- [[Template:tracking/inflection of/tag/gen]] | |||
-- [[Template:tracking/inflection of/tag/genitive]] | |||
-- [[Template:tracking/inflection of/tag/indefinite]] | |||
local ntags = {} | local ntags = {} | ||
for _, tag in ipairs(tags) do | for _, tag in ipairs(tags) do | ||
if do_track then | |||
-- Track the raw tag. | |||
infl_track("tag/" .. tag) | |||
end | |||
-- Expand the tag, which may generate a new tag (either a | -- Expand the tag, which may generate a new tag (either a | ||
-- fully canonicalized tag, a multipart tag, or a list of tags). | -- fully canonicalized tag, a multipart tag, or a list of tags). | ||
Line 342: | Line 392: | ||
if type(tag) == "table" then | if type(tag) == "table" then | ||
for _, t in ipairs(tag) do | for _, t in ipairs(tag) do | ||
if do_track then | |||
-- If the tag expands to a list of raw tags, track each of | |||
-- those. | |||
infl_track("tag/" .. t) | |||
end | |||
table.insert(ntags, normalize_tag(t, recombine_multitags, | table.insert(ntags, normalize_tag(t, recombine_multitags, | ||
do_track)) | do_track)) | ||
Line 479: | Line 534: | ||
normtag = "[[w:" .. data.glossary .. "|" .. normtag .. "]]" | normtag = "[[w:" .. data.glossary .. "|" .. normtag .. "]]" | ||
else | else | ||
normtag = "[[ | normtag = "[[Appendix:Glossary#" .. mw.uri.anchorEncode(data.glossary) .. "|" .. normtag .. "]]" | ||
end | end | ||
end | end | ||
Line 775: | Line 830: | ||
function export.tagged_inflections(data, terminfo, notext, capfirst, posttext, joiner) | function export.tagged_inflections(data, terminfo, notext, capfirst, posttext, joiner) | ||
if not data.tags then | if not data.tags then | ||
error("First argument must now be a table of arguments") | error("First argument must now be a table of arguments") |