モジュール:ojp-headword
表示
このモジュールについての説明文ページを モジュール:ojp-headword/doc に作成できます
local m_ja = require("Module:ja")
local find = mw.ustring.find
local export = {}
local lang = require("Module:languages").getByCode("ojp")
local Latn = require("Module:scripts").getByCode("Latn")
local Japanese_symbols = '%ー・=?!。、'
local katakana_range = 'ァ-ヺーヽヾ'
local hiragana_range = 'ぁ-ゖーゞゝ'
local kana_range = katakana_range .. hiragana_range .. Japanese_symbols
local kanji_range = '一-鿌・々'
local Japanese_scripts_range = kana_range .. kanji_range
local katakana_pattern = '^[' .. katakana_range .. Japanese_symbols .. ']*$'
local hiragana_pattern = '^[' .. hiragana_range .. Japanese_symbols .. ']*$'
local kana_pattern = '^[' .. kana_range .. ']*$'
local kana_pattern_full = '^[、' .. kana_range .. '%s%.%-%^]*$'
local kana_pattern_char = '[、' .. kana_range .. '%s%.%-%^]'
-- get a kana form to use, in order of preference: unnamed, pagename
local function find_kana(args, PAGENAME)
for i,arg in ipairs(args) do
if args[i] and find(args[i], kana_pattern_full) then return args[i] end
end
if find(PAGENAME, kana_pattern_full) then return PAGENAME end
error("No kana detected in the unnamed parameters.")
end
local function find_kanji(args, PAGENAME, data)
for i, arg in ipairs(args) do
if args[i] and find(args[i], "[" .. kanji_range .. "]") then
table.insert(data.kanji, args[i])
end
end
end
-- go through args and build inflections by finding whatever kanas were given to us
local function find_inflections(args, data, PAGENAME)
local allkana,original = {},{}
for i,arg in ipairs(args) do
if arg and arg ~= "" and find(arg, kana_pattern_full) then table.insert(allkana, arg) end
end
if find(PAGENAME, kana_pattern_full) then
if #allkana == 0 then table.insert(allkana, PAGENAME) end
end
for i = 1, #allkana do
-- remove markup
table.insert(original,allkana[i])
allkana[i] = mw.ustring.gsub(allkana[i], '[%s%.%-%^]', '')
end
for i = 1, #allkana do
-- if this is not kana, blank it out
if allkana and not mw.ustring.match(allkana[i], kana_pattern_char) then
allkana[i] = ""
end
-- only if this kana is different from the page name
if allkana[i] ~= PAGENAME and allkana[i] ~= "" then
table.insert(data.translits, allkana[i])
end
end
end
-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)
local args = frame:getParent().args
PAGENAME = args["pagename"] or mw.title.getCurrentTitle().text
local poscat = frame.args[1] or error("Part of speech has not been specified. Please pass parameter 1 to the module invocation.")
local head = args["head"] or PAGENAME
local data = {lang = lang, sc = nil, pos_category = poscat, categories = {}, heads = {head}, inflections = {}, translits = {}, kanji = {}}
local kana = find_kana(args, PAGENAME)
find_kanji(args, PAGENAME, data)
-- sort out all the kanas and do the romanization business
find_inflections(args, data, PAGENAME)
-- ソートキーの付け方は日本語と同じ
local sort_key = m_ja.jsort(kana)
if sort_key ~= PAGENAME then
data.sort_key = sort_key
end
return
require("Module:headword").full_headword(data)
end
return export