Module:User:Benwing2/category tree/poscatboiler/data/lang-specific/ja-ryu

local export = {}

local Hira = require("Module:scripts").getByCode("Hira") local m_numeric = require("Module:ConvertNumeric") local rmatch = mw.ustring.match

function export.add_labels(labels, lang) labels["adnominals"] = { description = " . Modifies nouns, doesn’t conjugate, and doesn’t predicate.", parents = , }

labels["hiragana"] = { description = "The hiragana (平仮名, ひらがな) form of " .. (lang:getCode == "ryu" and "an" or "a") .. " word is a phonetic representation of that word. " .. "Wiktionary represents -language segments in three ways: in normal form (with kanji, if appropriate), in hiragana " .. "form (this differs from kanji form only when the segment contains kanji), and in romaji form.", additional = (lang:getCode == "ja" and "For more information, see Japanese language.\n\n" or "") .. "See also Category: katakana", toc_template = "categoryTOC-hiragana", parents = { {name = "", raw = true}, "Category:Hiragana script characters", }	}

labels["historical hiragana"] = { description = " historical hiragana.", additional = "See also Category: historical katakana", toc_template = "categoryTOC-hiragana", parents = { "hiragana", {name = "", raw = true}, "Category:Hiragana script characters", }	}

labels["katakana"] = { description = " words and terms with katakana forms, sorted by conventional katakana sequence. Katakana is used primarily for transliterations of foreign words, including old Chinese Hanzi not used in shinjitai.", additional = "Entries in this category are made by POS templates, Template:-noun, etc.", toc_template = "categoryTOC-katakana", parents = { {name = "", raw = true}, "Category:Katakana script characters", }	}

labels["terms spelled with mixed kana"] = { description = " terms which combine hiragana and katakana characters, potentially with kanji too.", parents = { {name = "", raw = true}, "hiragana", "katakana", },	}

labels["honorifics"] = { intro = "", description = " honorifics.", parents = , }

labels["humble language"] = { description = " humble terms, or, which is a type of honorific speech in that lowers the speaker in relation to the listener.", parents = "honorifics", }

labels["respectful language"] = { description = " respectful terms, or, which is a type of honorific speech in that elevates the listener in relation to the speaker.", parents = "honorifics", }

labels["kanji by reading"] = { description = " kanji categorized by reading.", parents = , }

labels["terms by kanji readings"] = { description = " categories grouped with regard to the readings of the kanji with which they are spelled.", parents = , }

labels["terms by reading pattern"] = { description = " categories with terms grouped by their reading patterns.", parents = , }

for reading_pattern, link in pairs { ["jukujikun"] = "", ["jūbakoyomi"] = ", a reading pattern in compounds where kanji read with on'yomi are followed by kanji read with kun'yomi", ["kun'yomi"] = "", ["nanori"] = "", ["on'yomi"] = "", ["yutōyomi"] = ", a reading pattern in compounds where kanji read with kun'yomi are followed by kanji read with on'yomi", } do labels["terms read with " .. reading_pattern] = { description = " terms exhibiting " .. link .. ".",			breadcrumb = reading_pattern, parents = , }	end

labels["terms by kanji reading type"] = { description = " categories with terms grouped with regard to the types of readings of the kanji with which " .. "they are spelled, broadly those of Chinese origin (on readings) and those of origin (kun readings).", parents = , }

local on_continuation = [=[

Categories of terms with more specific types of on readings can be found in the following categories: * Category: terms spelled with kanji with goon readings * Category: terms spelled with kanji with kan'yōon readings * Category: terms spelled with kanji with kan'on readings * Category: terms spelled with kanji with tōon readings ]=]

local on_desc = ", which is a type of or  reading" for reading_type, reading_desc in pairs { ["goon"] = "a reading" .. on_desc, ["kan'on"] = "a reading" .. on_desc, ["kan'yōon"] = "a reading" .. on_desc, ["kun"] = "a or  reading", ["nanori"] = "a reading, which is a type of reading used for people and places", ["on"] = "an or  reading", ["tōon"] = "a reading" .. on_desc, ["sōon"] = "a reading" .. on_desc, } do labels["terms spelled with kanji with " .. reading_type .. " readings"] = { description = " categories with terms that are spelled with one or more kanji which exhibit " .. reading_desc .. ".",			additional = reading_type == "on" and on_continuation, breadcrumb = reading_type, parents = , }	end

labels["terms spelled with ateji"] = { intro = "", description = " terms containing one or more ateji, which are kanji used to represent sounds rather than meanings (though meaning may have some influence on which kanji are chosen).", parents = , }

labels["terms spelled with jukujikun"] = { description = " terms containing one or more jukujikun, which are kanji used to represent meanings rather than sounds.", parents = , }

labels["words with multiple readings"] = { description = " words with multiple pronunciations (hence multiple kana spellings).", parents = , }

labels["kanji readings by number of morae"] = { description = " categories grouped with regard to the number of morae in their kanji readings.", parents = , } end

function export.add_handlers(handlers, lang, m_lang, m_lang_kanji_readings) -- FIXME: Only works for 0 through 19. local word_to_number = {} for k, v in pairs(m_numeric.ones_position) do		word_to_number[v] = k	end

local kana_capture = "([-ぁ-ー𛀁𛀆]+)"

local periods = { historical = true, ancient = true, }

local function get_period_text_and_reading_type_link(period, reading_type) period = period ~= "" and period or nil if period and not periods[period] then return nil end local period_text = period and period .. " " or nil

-- Allow periods (historical or ancient) by themselves; they will parse as reading types. if not period and periods[reading_type] then return nil, reading_type end

local reading_label = m_lang_kanji_readings.accented_labels_to_labels[reading_type] if not reading_label then return nil end reading_label = m_lang_kanji_readings.labels[reading_label] local reading_type_link = "" .. mw.ustring.lower(reading_label.text) .. "" return period_text, reading_type_link end local function get_tagged_reading(reading) return require("Module:script utilities").tag_text(reading, lang, m_lang_kanji_readings.get_script(reading)) end

local function get_reading_link(reading, historical) return m_lang_kanji_readings.plain_link { term = reading, tr = m_lang.kana_to_romaji(string.gsub(reading, '%-', ''), historical and { hist = true }) }	end

local function is_on_subtype(reading_type) return reading_type:find(".on$") end

table.insert(handlers, function(data)		local count, plural = data.label:match("^terms written with (.+) Han script character(s?)$")		if count then			-- Make sure 'one' goes with singular and other numbers with plural.			if (count == "one") ~= (plural == "") then				return nil			end			local num = word_to_number[count]			if not num then				return nil			end			return {				description = " terms written with " .. count .. " Han script character" .. plural .. " (also known as kanji).",				breadcrumb = num,				parents = ,			}		end	end)

table.insert(handlers, function(data)		local count, plural = data.label:match("^kanji readings with (.+) mora(e?)$")		if count then			-- Make sure 'one' goes with singular and other numbers with plural.			if (count == "one") ~= (plural == "") then				return nil			end			local num = word_to_number[count]			if not num then				return nil			end			return {				description = " kanji readings containing " .. count .. " mora" .. plural .. ".",				breadcrumb = num,				parents = ,			}		end	end)

table.insert(handlers, function(data)		local label_pref, period, reading_type, reading = rmatch(data.label, "^(kanji with ([a-z]-) ?([%a']+) reading )" .. kana_capture .. "$")		if period then			local period_text, reading_type_link = get_period_text_and_reading_type_link(period, reading_type)			if not reading_type_link then				return nil			end

-- Compute parents. local parents = { {name = "kanji by " .. (period_text or "") .. reading_type .. " reading", sort = m_lang.jsort(reading)} }			if is_on_subtype(reading_type) then table.insert(parents, {name = "kanji with " .. (period_text or "") .. "on reading " .. reading, sort = reading_type}) elseif period_text then table.insert(parents, {name = "kanji with " .. period_text .. "reading " .. reading, sort = reading_type}) end if not period_text then table.insert(parents, {name = "kanji read as " .. reading, sort = reading_type}) end

local tagged_reading = get_tagged_reading(reading) return { description = " kanji with the " .. (period_text or "") .. reading_type_link .. " reading " .. get_reading_link(reading, period_text) .. ".",				displaytitle = " " .. label_pref .. tagged_reading, breadcrumb = tagged_reading, parents = parents, }		end end)

table.insert(handlers, function(data)		local period, reading_type = rmatch(data.label, "^kanji by ([a-z]-) ?([%a']+) reading$")		if period then			local period_text, reading_type_link = get_period_text_and_reading_type_link(period, reading_type)			if not reading_type_link then				return nil			end

-- Compute parents. local parents = { is_on_subtype(reading_type) and {name = "kanji by " .. (period_text or "") .. "on reading", sort = reading_type} or period_text and {name = "kanji by " .. reading_type .. " reading", sort = period} or				{name = "kanji by reading", sort = reading_type} }			if period_text then table.insert(parents, {name = "kanji by " .. period_text .. "reading", sort = reading_type}) end

-- Compute description. local description = " kanji categorized by " .. (period_text or "") .. reading_type_link .. " reading." return { description = description, breadcrumb = (period_text or "") .. reading_type, parents = parents, }		end end)

table.insert(handlers, function(data)		local label_pref, reading = rmatch(data.label, "^(kanji read as )" .. kana_capture .. "$")		if reading then			local parents =

local tagged_reading = get_tagged_reading(reading) return { description = " kanji read as " .. get_reading_link(reading, period_text) .. ".",				displaytitle = " " .. label_pref .. tagged_reading, breadcrumb = tagged_reading, parents = parents, }		end end)

table.insert(handlers, function(data)		local label_pref, reading = rmatch(data.label, "^(terms spelled with kanji read as )" .. kana_capture .. "$")		if reading then			-- Compute parents.			local sort_key = m_lang.jsort(reading)			local mora_count = m_lang.count_morae(reading)			local mora_count_words = m_numeric.spell_number(tostring(mora_count))			local parents = {				{name = "terms by kanji readings", sort = sort_key},				{name = "kanji readings with " .. mora_count_words .. " mora" .. (mora_count > 1 and "e" or ""), sort = sort_key},				{name = "kanji read as " .. reading, sort = " "},			}

local tagged_reading = get_tagged_reading(reading) return { description = " terms that contain kanji that exhibit a reading of " .. get_reading_link(reading) .. " in those terms prior to any sound changes.", displaytitle = " " .. label_pref .. tagged_reading, breadcrumb = tagged_reading, parents = parents, }		end end)

table.insert(handlers, function(data)		local kanji, reading = rmatch(data.label, "^terms spelled with (.) read as " .. kana_capture .. "$")		if not kanji then			return nil		end		local params = {			[4] = {list = true},		}		local args = require("Module:parameters").process(data.args, params)		if #args[4] == 0 then			error("For categories of the form \"" .. data.lang:getCanonicalName ..				" terms spelled with KANJI read as READING\", at least one reading type (e.g. \"kun\" or \"on\") must be specified using 1=, 2=, 3=, etc.")		end		local reading_types = {}		for _, reading_type in ipairs(args[4]) do			table.insert(reading_types, "''" .. reading_type .. "'' reading")		end		reading_types = require("Module:table").serialCommaJoin(reading_types, {conj = "or"})

local parents = { {name = "terms spelled with " .. kanji, sort = m_lang.jsort(reading)}, -- FIXME, using the kanji directly as the sort key is what it did before but maybe we should call Module:zh-sortkey -- to get the radical/stroke sort key {name = "terms spelled with kanji read as " .. reading, sort = kanji}, }		for _, reading_type in ipairs(args[4]) do table.insert(parents, {name = "terms spelled with kanji with " .. reading_type .. " readings", sort = m_lang.jsort(reading)}) end local tagged_kanji = get_tagged_reading(kanji) local tagged_reading = get_tagged_reading(reading) return { description = " terms spelled with with its " .. reading_types .. " of " .. get_reading_link(reading) .. ".",			displaytitle = " terms spelled with " .. tagged_kanji .. " read as " .. tagged_reading, breadcrumb = "read as " .. tagged_reading, parents = parents, }, true end) end

return export