模組:PoS

嚟自維基辭典
跳去導覽 跳去搵嘢

呢個模組嘅解說可以喺模組:PoS/doc度開

local p = {}
local u = mw.ustring
local mlangs = require("Module:languages")
local poscode = {
	-- [1]: abbreviation; [2]: full name; [3]: parent; [4]: aliases
	n = {"名", "名詞", "n", {"nom"}}, -- nouns
	pn = {"專名", "專有名詞", "pn", {"proper"}}, -- proper nouns
	nc = {"可數名", "可數名詞", "n", {"n_count"}}, -- countable nouns
	nuc = {"不可數名", "不可數名詞", "n", {"nu", "n_uncount"}}, -- uncountable nouns
	nn = {"中名", "中性名詞", "n", {"n_n", "n_neu"}}, -- neutral nouns
	nm = {"陽名", "陽性名詞", "n", {"n_m", "n_mas"}}, -- masculine nouns
	nf = {"陰名", "陰性名詞", "n", {"n_f", "n_fem"}}, -- feminine nouns
	v = {"動", "動詞", "v", {"verbe"}}, -- verbs
	vi = {"不及動", "不及物動詞", "v", {"v_i"}}, -- intransitive verbs
	vt = {"及動", "及物動詞", "v", {"v_t"}}, -- transitive verbs
	vd = {"雙及動", "雙及物動詞", "v", {"v_d"}}, -- ditransitive verbs
	vaux = {"助動", "助動詞", "v", {"v_aux"}}, -- auxiliary verbs
	vmod = {"情態", "情態動詞", "v", {"v_mod"}}, -- modal verbs
	copula = {"繫", "聯繫詞", "copula", {}}, -- copulae
	art = {"冠", "冠詞", "art", {"article"}}, -- articles
	artdef = {"定冠", "定冠詞", "art", {"art_def", "artd", "art_d"}}, -- definite articles
	artindef = {"不定冠", "不定冠詞", "art", {"art_indef", "arti", "art_i"}}, -- indefinite articles
	adj = {"形", "形容詞", "adj", {"adjectif", "adjective"}}, -- adjectives
	adv = {"副", "副詞", "adv", {"adverb"}}, -- adverbs
	advinterro = {"問副", "疑問副詞", "adv", {"adv_i", "advi", "interroadv", "interro_adv"}}, -- interrogative adverbs
	pron = {"代", "代詞", "pron", {"pronoun", "pronom"}}, -- pronouns
	pronper = {"人稱代", "人稱代詞", "pron", {"pron_per", "prn_per"}}, -- personal pronouns
	pronpos = {"物主代", "物主代詞", "pron", {"pron_pos", "prn_pos"}}, -- possessive pronouns
	clf = {"量", "量詞", "clf", {"class", "classifier"}}, -- classifiers
	prep = {"前介", "前置介詞", "prep", {"preposition"}}, -- prepositions
	postp = {"後介", "後置介詞", "postp", {"postposition"}}, -- postpositions
	num = {"數", "數詞", "num", {"numeral", "number word"}}, -- numerals
	ono = {"聲", "擬聲詞", "ono", {"onomato", "onomatopoeia"}}, -- onomatopoeias
	interj = {"歎", "感歎詞", "interj", {"interject", "interjection"}}, -- interjections
	interro = {"問", "疑問詞", "interro", {"interrogatif", "interrogative", "interrogative word"}}, -- interrogative words
	prefix = {"前綴", "前綴", "prefix", {"préfix"}}, -- prefixes
	suffix = {"後綴", "後綴", "suffix", {"suffixe"}}, -- suffixes
	transfix = {"插綴", "插綴", "transfix", {}}, -- transfixes
	infix = {"中綴", "中綴", "infix", {}}, -- infixes
	circumfix = {"環綴", "環綴", "circumfix", {}}, -- circumfixes
	conj = {"連", "連接詞", "conj", {"conjunction"}} -- conjunctions
}
local abbr = {}
for code, data in pairs(poscode) do
	abbr[code] = code
	abbr[data[1]] = code
	if not abbr[data[2]] then
		abbr[data[2]] = code
	end
	for _, alias in pairs(data[4]) do
		if not abbr[alias] then
			abbr[alias] = code
		end
	end
end
function p.main(frame)
	local args = frame:getParent().args
	if args['lang'] == nil or args['lang'] == "" then
		return "<span class=\"error\">PoS模出錯:無提供語言代碼</span>"
	end
	local lang = mlangs.getByCode(args['lang'])
	local pos = args[1] or args["pos"] or args["PoS"]
	local lemma
	if args["lemma"] ~= nil then
		if args["lemma"] == "true" then
			lemma = "詞元"
		else
			lemma = "非詞元形式"
		end
	else
		lemma = ""
	end
	pos = abbr[pos] --n,nc,nuc,v etc.
	local morecat = "[[Category:" .. lang:getCanonicalName() .. poscode[poscode[pos][3]][2].."]]"
	return "【" .. poscode[pos][1] .. "】[[Category:" .. lang:getCanonicalName() .. lemma .. "]]" .. morecat .. "[[Category:" .. lang:getCanonicalName() .. poscode[pos][2].."]]"
end

return p