模組:PoS
掇要
編輯{{#invoke:PoS|main}}
p.test()
說明
編輯呢個模組係用來指定詞性(part of speech),正常係透過 「詞性」 模間接叫用。
模組有兩個公開函數,當中 main 係正常介面,正常情形下由 「詞性」 模間接叫用;test 係測試函數,載入分模 /testcases 之後執行分模嘅 test 函數,測試函數正常係由模組編輯介面嘅 debug console 執行,測試成功冇輸出,測試失敗會產生 assertion failed 錯誤。
追蹤分類
編輯遇到某嘅唔正常情況,模組會選擇繼續運作但係將篇文加入追蹤分類,呢啲追蹤分類暫時係呢啲:
-- vi: set sw=4 ts=4 ai sm :
require 'strict';
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
pnm = {"陽專名", "陽性專有名詞", "pnm", {}}, -- masculine proper nouns
pnf = {"陰專名", "陰性專有名詞", "pnf", {}}, -- feminine 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", {'verb', "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
phrase = {"短語", "短語", "phrase", {}} -- phrases
}
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
error('PoS模出錯:無提供語言代碼');
end
local lang = mlangs.getByCode(args['lang'])
local pos = args[1] or args["pos"] or args["PoS"]
local lemma
if not pos then
error('PoS模出錯:冇指定詞性(pos、PoS 或者參數一)');
end
if args["lemma"] ~= nil then
if args["lemma"] == "true" then
lemma = "詞元"
else
lemma = "非詞元形式"
end
else
lemma = ""
end
local lang_name = lang:getCanonicalName();
local main_cats = "[[Category:" .. lang_name .. lemma .. "]]";
-- 如果係已知詞性,轉做英文代號
if abbr[pos] then
pos = abbr[pos] --n,nc,nuc,v etc.
end
-- 如果有指定詞性但係唔知係乜,照出但係加入追縱分類
local it;
if not poscode[pos] then
it = '【' .. pos .. '】';
it = it .. main_cats;
it = it .. '[[Category:PoS模用咗未知詞性|' .. pos .. ']]';
-- 正常情形(已知詞性)
else
it = "【" .. poscode[pos][1] .. "】";
it = it .. main_cats;
local parent_pos = poscode[pos][3];
if parent_pos and parent_pos ~= pos and poscode[parent_pos] then
it = it .. "[[Category:" .. lang_name .. poscode[parent_pos][2].."]]"
end
it = it .. "[[Category:" .. lang_name .. poscode[pos][2].."]]"
end
return it;
end
function p.test()
return require('Module:PoS/testcases').test();
end
return p