Jump to content

Module:Alhatorah and Module:Alhatorah/sandbox: Difference between pages

(Difference between pages)
Page 1
Page 2
Content deleted Content added
No edit summary
 
No edit summary
 
Line 4: Line 4:
--possible book inputs, based on Chicago Manual
--possible book inputs, based on Chicago Manual
local book_aliases = {
local book_aliases = {
['Bereshit'] = {'breishit', 'genesis', 'gen', 'gn'},
['Bereshit'] = {'genesis', 'gen', 'gn'},
['Shemot'] = {'exodus', 'exod', 'ex'},
['Shemot'] = {'exodus', 'exod', 'ex'},
['Vayikra'] = {'leviticus', 'lev', 'lv'},
['Vayikra'] = {'leviticus', 'lev', 'lv'},
['Bemidbar'] = {'bamidbar', 'numbers', 'num', 'nm'},
['Bemidbar'] = {'numbers', 'num', 'nm'},
['Devarim'] = {'deuteronomy', 'deut', 'dt'},
['Devarim'] = {'deuteronomy', 'deut', 'dt'},
['Yehoshua'] = {'joshua', 'josh' , 'jo'},
['Yehoshua'] = {'joshua', 'josh' , 'jo'},
['Shofetim'] = {'shoftim', 'judges', 'judg', 'jgs'},
['Shofetim'] = {'judges', 'judg', 'jgs'},
['Shemuel I'] = {'shemueli', 'shemuel1', 'shmueli', 'shmuel1', 'shmueli', '1shmuel', 'ishmuel', '1sam', '1sm', 'isamuel'},
['Shemuel I'] = {'1_samuel', '1sam', '1sm', 'I_samuel'},
['Shemuel II'] = {'shemuelii', 'shemuel2', 'shmuelii', 'shmuel2', 'shmuelii','2shmuel', 'iishmuel', '2sam', '2sm', 'iisamuel'},
['Shemuel II'] = {'2_samuel', '2sam', '2sm', 'II_samuel'},
['Melakhim I'] = {'melachim1', 'melachimi', 'melakhim1', 'melakhimi', '1kings', 'imelachim', '1kgs','ikings'},
['Melakhim I'] = {'1_kings', '1kgs', 'I_kings'},
['Melakhim II'] = {'melachim2', 'melachimii', 'melakhim2', 'melakhimii', '2kings', 'iimelachim', '2kgs','iikings'},
['Melakhim II'] = {'2_kings', '2kgs', 'II_kings'},
['Yeshayahu'] = {'isaiah', 'isa', 'is'},
['Yeshayahu'] = {'isaiah', 'isa', 'is'},
['Yirmeyahu'] = {'yirmiyahu', 'jeremiah', 'jer'},
['Yirmeyahu'] = {'jeremiah', 'jer'},
['Yechezkel'] = {'ezekiel', 'ezek', 'ez'},
['Yechezkel'] = {'ezekiel', 'ezek', 'ez'},
['Hoshea'] = {'hosea', 'hos'},
['Hoshea'] = {'hosea', 'hos'},
['Yoel'] = {'joel', 'jl'},
['Yoel'] = {'joel', 'jl'},
['Amos'] = {'amos', 'am'},
['Amos'] = {'amos', 'am'},
['Ovadyah'] = {'ovadiah', 'obadiah', 'obad', 'ob'},
['Ovadyah'] = {'obadiah', 'obad', 'ob'},
['Yonah'] = {'jonah', 'jon'},
['Yonah'] = {'jonah', 'jon'},
['Mikhah'] = {'michah', 'micah', 'mic', 'mi'},
['Mikhah'] = {'micah', 'mic', 'mi'},
['Nachum'] = {'nahum', 'nah', 'na'},
['Nachum'] = {'nahum', 'nah', 'na'},
['Chavakkuk'] = {'habakkuk', 'hab', 'hb'},
['Chavakkuk'] = {'habakkuk', 'hab', 'hb'},
['Zephanyah'] = {'tzefaniah', 'zephaniah', 'zeph', 'zep'},
['Zephanyah'] = {'zephaniah', 'zeph', 'zep'},
['Chaggai'] = {'haggai', 'hag', 'hg'},
['Chaggai'] = {'haggai', 'hag', 'hg'},
['Zekharyah'] = {'zechariah', 'zech', 'zec'},
['Zekharyah'] = {'zechariah', 'zech', 'zec'},
Line 33: Line 33:
['Mishlei'] = {'proverbs', 'prov', 'prv'},
['Mishlei'] = {'proverbs', 'prov', 'prv'},
['Kohelet'] = {'ecclesiastes', 'eccles', 'eccl', 'qoheleth'},
['Kohelet'] = {'ecclesiastes', 'eccles', 'eccl', 'qoheleth'},
['Shir HaShirim'] = {'shirhashirim', 'songofsolomon', 'songofsol', 'songofsongs', 'song', 'sg', 'canticles', 'canticleofcanticles'},
['Shir HaShirim'] = {'song_of_solomon', 'songofsol', 'songofsongs', 'song', 'sg', 'canticles', 'canticleofcanticles'},
['Eikhah'] = {'lamentations', 'lam'},
['Eikhah'] = {'lamentations', 'lam'},
['Rut'] = {'ruth', 'ru'},
['Rut'] = {'ruth', 'ru'},
Line 39: Line 39:
['Iyyov'] = {'job', 'jb'},
['Iyyov'] = {'job', 'jb'},
['Daniel'] = {'daniel', 'dan', 'dn'},
['Daniel'] = {'daniel', 'dan', 'dn'},
['Divrei HaYamim I'] = {'divreihayamimi', 'divreihayamim1', 'ichronicles', '1chronicles', '1chron', '1chr'},
['Divrei HaYamim I'] = {'1_chronicles', '1chron', '1chr', 'I_chronicles'},
['Divrei HaYamim II'] = {'divreihayamimii', 'divreihayamim2', 'iichronicles', '2chronicles', '2chron', '2chr'},
['Divrei HaYamim II'] = {'2_chronicles', '2chron', '2chr', 'II_chronicles'},
['Ezra'] = {'ezra', 'ezr'},
['Ezra'] = {'ezra', 'ezr'},
['Nechemyah'] = {'nechemiah', 'nehemiah', 'neh'},
['Nechemyah'] = {'nehemiah', 'neh'},
}
}


Line 48: Line 48:
local no_chapters = {
local no_chapters = {
['obadiah'] = true,
['obadiah'] = true,
}

--changes to the version name to be used in urls, only if necessary
local site_version_tbl = {
mechon_mamre = {
he = 'p/pt/pt',
jps = 'e/et/et',
},
}
}


Line 64: Line 72:
end
end
return false
return false
end

local function titlecase(arg)
-- http://grammar.yourdictionary.com/capitalization/rules-for-capitalization-in-titles.html
-- recommended by The U.S. Government Printing Office Style Manual:
-- 'Capitalize all words in titles of publications and documents,
-- except a, an, the, at, by, for, in, of, on, to, up, and, as, but, or, and nor.'
local alwayslower = {
['a'] = true, ['an'] = true, ['the'] = true,
['and'] = true, ['but'] = true, ['or'] = true, ['for'] = true,
['nor'] = true, ['on'] = true, ['in'] = true, ['at'] = true, ['to'] = true,
['from'] = true, ['by'] = true, ['of'] = true, ['up'] = true,
}
local words = mw.text.split(mw.text.trim(arg or ''), '_')
for i, s in ipairs(words) do
s = string.lower(s)
if i > 1 then
if not alwayslower[s] then
s = mw.getContentLanguage():ucfirst(s)
end
else
s = mw.getContentLanguage():ucfirst(s)
end
words[i] = s
end
return table.concat(words, '_')
end
end


Line 72: Line 106:
args[param] = trimArg(targs[param])
args[param] = trimArg(targs[param])
end
end
local default_version = 'nrsv'
local input_book = ''
local input_book = ''
local ref = ''
local ref = ''
Line 77: Line 112:
local text = ''
local text = ''
local mainspace = mw.title.getCurrentTitle():inNamespaces(0)
local mainspace = mw.title.getCurrentTitle():inNamespaces(0)
--analyze arguments
if args[1] == nil or args[2] == nil or tonumber(args[1]) ~= nil then
if args[1] == nil or args[2] == nil or tonumber(args[1]) ~= nil then
-- first argument is a numeric prefix and second is book name
-- first argument is a numeric prefix and second is book name
Line 84: Line 117:
ref = args[3] or ''
ref = args[3] or ''
commentary = args[4] or ''
commentary = args[4] or ''
text = args[5] or trimArg((input_book .. ' ' .. ref))
text = args[5] or trimArg((commentary .. ' to ' .. input_book .. ' ' .. ref))
else
else
-- first argument is the whole book name
-- first argument is the whole book name
Line 90: Line 123:
ref = args[2] or ''
ref = args[2] or ''
commentary = args[3] or ''
commentary = args[3] or ''
text = args[4] or (input_book .. ' ' .. ref)
text = args[4] or (commentary .. ' to ' .. input_book .. ' ' .. ref)
end
end
if args.nobook == 'yes' then
if args.nobook == 'yes' then
text = ref
text = ref
end
end
text = text:gsub('-', '–') --change hyphens to en dashes (3:2-5 → 3:2–5)

--analyze book (for URL)
local book = input_book:gsub('%p', ''):gsub(' ', '_')
local book = input_book:gsub('%p', ''):gsub(' ', '_')
book_lower = mw.ustring.lower(book)
book = mw.ustring.lower(book)

book_lower = book_lower:gsub('_', '')
local book_found = false
local book_found = false
local standard = book:gsub('_', '')
for full_book, aliases in pairs(book_aliases) do
for full_book, aliases in pairs(book_aliases) do
if book_lower == mw.ustring.lower(full_book:gsub(' ', '_')) or valueExists(aliases, book_lower) then
if standard == full_book:gsub('_', '') or valueExists(aliases, standard) then
book = full_book:gsub(' ', '_')
book = full_book
book_found = true
book_found = true
break
break
Line 109: Line 143:
end
end


local urlpat = 'https://mg.alhatorah.org/Dual/_commentary/_book/_schap._svers#m7e3n7'
--analyze verse

local split_ref = mw.text.split(ref, '[-–—]') --split the ref into the part before and after the dash/hyphen
local split_ref = mw.text.split(ref, '[-–—]') --split the ref into the part before and after the dash/hyphen
local s_ref = mw.text.split(split_ref[1], '%p') --any punctuation can be used to separate chapter from verse
local s_ref = mw.text.split(split_ref[1], '%p') --any punctuation can be used to separate chapter from verse
Line 116: Line 151:
for i, v in ipairs(s_ref) do s_ref[i] = v:gsub('%D', '') end --remove any non-numeric character (such as f)
for i, v in ipairs(s_ref) do s_ref[i] = v:gsub('%D', '') end --remove any non-numeric character (such as f)
for i, v in ipairs(e_ref) do e_ref[i] = v:gsub('%D', '') end
for i, v in ipairs(e_ref) do e_ref[i] = v:gsub('%D', '') end

local s_chap, s_vers
local e_chap, e_vers, s_chap, s_vers
local chapter_only = not s_ref[2]
local chapter_only = not s_ref[2]
if no_chapters[book] then
if no_chapters[book] then
Line 122: Line 158:
s_chap = 1
s_chap = 1
s_vers = s_ref[2] or s_ref[1] or 1 --verse 3 can be specified as "3" or "1:3"
s_vers = s_ref[2] or s_ref[1] or 1 --verse 3 can be specified as "3" or "1:3"
e_chap = 1
e_vers = e_ref[2] or e_ref[1] or 1
else
else
s_chap = s_ref[1] or 1
s_chap = s_ref[1] or 1
s_vers = s_ref[2] or 1
s_vers = s_ref[2] or 1
if e_ref[2] or not s_ref[2] then --chapter-chapter or chapter(:verse)?-chapter:verse
e_chap = e_ref[1] or s_chap
else --chapter:verse-verse
e_chap = s_chap
end
e_vers = e_ref[2] or e_ref[1] or s_vers
end
book = titlecase(book) --title case looks better at oremus where they display the input

local v_range
if chapter_only then
if e_chap == s_chap then
v_range = s_chap
else
v_range = s_chap .. '–' .. e_chap
end
else
if e_chap == s_chap and e_vers == s_vers then
v_range = s_chap ..':' .. s_vers
elseif e_chap == s_chap then
v_range = s_chap .. ':' .. s_vers .. '–' .. e_vers
else
v_range = s_chap .. ':' .. s_vers .. '–' .. e_chap .. ':' .. e_vers
end
end
end


--build URL
commentary = commentary:gsub(' ', '_') --must be outside URL command
local urlpat = 'https://mg.alhatorah.org/Dual/_commentary/_book/_schap._svers#m7e3n7'
local url = urlpat:gsub('_%l+', { --get the components into the url
local url = urlpat:gsub('_%l+', { --get the components into the url
_commentary = commentary,
_book = book,
_book = book,
_schap = s_chap,
_schap = s_chap,
_svers = s_vers,
_svers = s_vers,
_echap = e_chap,
_evers = e_vers,
_vrange = v_range,
_commentary = commentary,
})
})


--build text
text = text:gsub('-', '–') --change hyphens to en dashes (3:2-5 → 3:2–5)
text = commentary:gsub('_', ' ') .. ', ' .. text
local fulllink
local fulllink
fulllink = '[' .. url .. ' ' .. text .. ']'
fulllink = '[' .. url .. ' ' .. text .. ']'

if mainspace then
if mainspace then
if not book_found then
if not book_found then
Line 152: Line 211:
end
end
end
end
return fulllink --.. table.concat(errors)
return fulllink --.. table.concat(errors)
end
end