Module:headword: Difference between revisions

Jump to navigation Jump to search
no edit summary
m (Undo revision 374670 by Учхљёная (talk) It did not.)
Tag: Undo
No edit summary
Line 2: Line 2:


-- Named constants for all modules used, to make it easier to swap out sandbox versions.
-- Named constants for all modules used, to make it easier to swap out sandbox versions.
local debug_track_module = "Module:debug/track"
local gender_and_number_module = "Module:getn"
local gender_and_number_module = "Module:getn"
local headword_data_module = "Module:headword/data"
local headword_data_module = "Module:headword/data"
Line 46: Line 47:
return (rsubn(term, foo, bar))
return (rsubn(term, foo, bar))
end
end
-- Add a tracking category to track entries with certain (unusually undesirable) properties. `track_id` is an identifier
-- for the particular property being tracked and goes into the tracking page. Specifically, this adds a link in the
-- page text to [[Wiktionary:Tracking/headword/TRACK_ID]], meaning you can find all entries with the `track_id` property
-- by visiting [[Special:WhatLinksHere/Wiktionary:Tracking/headword/TRACK_ID]].
--
-- If `lang` (a language object) is given, an additional tracking page [[Wiktionary:Tracking/headword/TRACK_ID/CODE]] is
-- linked to where CODE is the language code of `lang`, and you can find all entries in the combination of `track_id`
-- and `lang` by visiting [[Special:WhatLinksHere/Wiktionary:Tracking/headword/TRACK_ID/CODE]]. This makes it possible to
-- isolate only the entries with a specific tracking property that are in a given language. Note that if `lang`
-- references at etymology-only language, both that language's code and its full parent's code are tracked.
local function track(track_id, lang)
local tracking_page = "headword/" .. track_id
local m_debug_track = require(debug_track_module)
if lang and lang:hasType("etymology-only") then
m_debug_track{tracking_page, tracking_page .. "/" .. lang:getCode(),
tracking_page .. "/" .. lang:getFullCode()}
elseif lang then
m_debug_track{tracking_page, tracking_page .. "/" .. lang:getCode()}
else
m_debug_track(tracking_page)
end
return true
end


local function text_in_script(text, script_code)
local function text_in_script(text, script_code)
Line 243: Line 269:
else
else
head_parts = concat(head_parts)
head_parts = concat(head_parts)
end
if has_manual_translits then
-- [[Special:WhatLinksHere/Wiktionary:Tracking/headword/has-manual-translit]]
-- [[Special:WhatLinksHere/Wiktionary:Tracking/headword/has-manual-translit/LANGCODE]]
track("has-manual-translit", data.lang)
end
end


Line 347: Line 379:
-- right into the 'data' table to disable inflection links of the entire headword
-- right into the 'data' table to disable inflection links of the entire headword
-- when inflected forms aren't entry-worthy, e.g.: in Vulgar Latin
-- when inflected forms aren't entry-worthy, e.g.: in Vulgar Latin
local nolinkinfl = data.nolinkinfl
local nolinkinfl = part.face == "hypothetical" or (part.nolink and track("nolink") or part.nolinkinfl) or (
data.nolink and track("nolink") or data.nolinkinfl)


local formatted
local formatted
Line 593: Line 626:


local langcode = data.lang:getCode()
local langcode = data.lang:getCode()
local full_langcode = langcode
local full_langcode = data.lang:getFullCode()
local langname = data.lang:getCanonicalName()
local langname = data.lang:getCanonicalName()
local full_langname = langname
local full_langname = data.lang:getFullName()


local raw_pagename, page = data.pagename
local raw_pagename, page = data.pagename
Line 623: Line 656:
-- convert old-style `heads`, `translits` and `transcriptions` to new-style
-- convert old-style `heads`, `translits` and `transcriptions` to new-style
local maxind = math.max(
local maxind = math.max(
init_and_find_maximum_index(data, "heads", true),
init_and_find_maximum_index(data, "heads"),
init_and_find_maximum_index(data, "translits", true),
init_and_find_maximum_index(data, "translits", true),
init_and_find_maximum_index(data, "transcriptions", true)
init_and_find_maximum_index(data, "transcriptions", true)
Line 643: Line 676:
------------ 4. Initialize and validate `data.categories` and `data.whole_page_categories`, and determine `pos_category` if not given, and add basic categories. ------------
------------ 4. Initialize and validate `data.categories` and `data.whole_page_categories`, and determine `pos_category` if not given, and add basic categories. ------------


init_and_find_maximum_index(data, "categories", true)
init_and_find_maximum_index(data, "categories")
init_and_find_maximum_index(data, "whole_page_categories", true)
init_and_find_maximum_index(data, "whole_page_categories")
local pos_category_already_present = false
local pos_category_already_present = false
if #data.categories > 0 then
if #data.categories > 0 then
local escaped_langname = pattern_escape(full_langname)
local escaped_langname = pattern_escape(full_langname)
local matches_lang_pattern = "^" .. escaped_langname .. " "
local matches_lang_pattern = "^" .. escaped_langname .. " "
for _, cat in ipairs(data.categories) do
-- Does the category begin with the language name? If not, tag it with a tracking category.
if not cat:find(matches_lang_pattern) then
-- [[Special:WhatLinksHere/Wiktionary:Tracking/headword/no lang category]]
-- [[Special:WhatLinksHere/Wiktionary:Tracking/headword/no lang category/LANGCODE]]
track("no lang category", data.lang)
end
end


-- If `pos_category` not given, try to infer it from the first specified category. If this doesn't work, we
-- If `pos_category` not given, try to infer it from the first specified category. If this doesn't work, we
Line 679: Line 720:
-- add an appropriate category.
-- add an appropriate category.
local postype = export.pos_lemma_or_nonlemma(data.pos_category)
local postype = export.pos_lemma_or_nonlemma(data.pos_category)
if not data.noposcat then
if not postype then
-- We don't know what this category is, so tag it with a tracking category.
-- [[Special:WhatLinksHere/Wiktionary:Tracking/headword/unrecognized pos]]
-- [[Special:WhatLinksHere/Wiktionary:Tracking/headword/unrecognized pos/LANGCODE]]
track("unrecognized pos", data.lang)
-- [[Special:WhatLinksHere/Wiktionary:Tracking/headword/unrecognized pos/POS]]
-- [[Special:WhatLinksHere/Wiktionary:Tracking/headword/unrecognized pos/POS/LANGCODE]]
track("unrecognized pos/pos/" .. data.pos_category, data.lang)
elseif not data.noposcat then
insert(data.categories, 1, full_langname .. " " .. postype .. "s")
insert(data.categories, 1, full_langname .. " " .. postype .. "s")
end
end
Line 725: Line 774:
if head_term:sub(1, 1) ~= "*" then
if head_term:sub(1, 1) ~= "*" then
error("The headword '"  .. head_term .. "' must begin with '*' to indicate that it is reconstructed.")
error("The headword '"  .. head_term .. "' must begin with '*' to indicate that it is reconstructed.")
end
end
------ 6b. Try to detect the script(s) if not provided. If a per-head script is provided, that takes precedence,
------    otherwise fall back to the overall script if given. If neither given, autodetect the script.
local auto_sc = data.lang:findBestScript(head.term)
if (
auto_sc:getCode() == "None" and
require(scripts_module).findBestScriptWithoutLang(head.term):getCode() ~= "None"
) then
insert(data.categories, full_langname .. " terms in nonstandard scripts")
end
if not (head.sc or data.sc) then -- No script code given, so use autodetected script.
head.sc = auto_sc
else
if not head.sc then -- Overall script code given.
head.sc = data.sc
end
-- Track uses of sc parameter.
if head.sc:getCode() == auto_sc:getCode() then
insert(data.categories, full_langname .. " terms with redundant script codes")
else
insert(data.categories, full_langname .. " terms with non-redundant manual script codes")
end
end
end
end
Line 851: Line 924:


------------ 8. Insert additional categories. ------------
------------ 8. Insert additional categories. ------------
if data.force_cat_output then
-- [[Special:WhatLinksHere/Wiktionary:Tracking/headword/force cat output]]
track("force cat output")
end


if has_redundant_head_param then
if has_redundant_head_param then
Line 1,075: Line 1,153:
if page.namespace == "" and not data.lang:hasType("reconstructed") then
if page.namespace == "" and not data.lang:hasType("reconstructed") then
local m_links = require(links_module)
local m_links = require(links_module)
for _, head in ipairs(data.heads) do
if page.full_raw_pagename ~= m_links.get_link_page(remove_links(head.term), data.lang, head.sc) then
-- [[Special:WhatLinksHere/Wiktionary:Tracking/headword/pagename spelling mismatch]]
-- [[Special:WhatLinksHere/Wiktionary:Tracking/headword/pagename spelling mismatch/LANGCODE]]
track("pagename spelling mismatch", data.lang)
break
end
end
end
end


Navigation menu