לדלג לתוכן

יחידה:כותרת: הבדלים בין גרסאות בדף

מתוך ויקיטקסט, מאגר הטקסטים החופשי
[גרסה לא בדוקה][גרסה לא בדוקה]
תוכן שנמחק תוכן שנוסף
מאין תקציר עריכה
מאין תקציר עריכה
שורה 101: שורה 101:
{5, 4, 4, 4, 3},
{5, 4, 4, 4, 3},
['מעשר שני'] =
['מעשר שני'] =
{3, 4, 6, 6, 5}
{3, 4, 6, 6, 5},
['חלה'] =
{6, 3, 5, 5},
},
},
['בבלי'] = {
['בבלי'] = {

גרסה מ־11:31, 29 באוקטובר 2013

היחידה מאפשרת לשלוף את שם הספר, המסכת והפרק.

שם הספר מוגדר כמילה אחת בלי רווחים, וכך גם שם הפרק.

לעומת זאת, בשם המסכת יכולים להיות רווחים.

שימוש ביחידה זו - בתבנית:ניווט משנה, וגם בתבנית:כותרת לפרק במסכת ובתבנית:כותרת לסעיף בפרק.

להדגמה, ראו ירושלמי פסחים א, ירושלמי בבא קמא א, ירושלמי פאה ו ג.

היחידה משתמשת בפונקציות מתוך יחידה:גימטריה.


local gimatria = require('יחידה:גימטריה');
local haqodem = gimatria.haqodem;
local haba = gimatria.haba;
local otiot2mispar = gimatria.gimatria;
local mispar2otiot = gimatria.mispar_lotiot;

local p = {}

-- חלוקה לשלושה חלקים: ספר (מילה אחת בלי רווחים), מסכת (עם או בלי רווחים), ופרק.
local PATTERN_PEREQ = '^([א-ת]+)%s+([ א-ת]+)%s+([א-ת]+)$';

-- חלוקה לארבעה חלקים: ספר (מילה אחת בלי רווחים), מסכת  (עם או בלי רווחים), פרק, וסעיף.
local PATTERN_SEIF = '^([א-ת]+)%s+([ א-ת]+)%s+([א-ת]+)%s+([א-ת]+)$';

-- חלוקה לשלושה חלקים: ספר (עם או בלי רווחים), פרק, וסעיף.
local PATTERN_SEIF_BSEFER = '^([ א-ת]+)%s+([א-ת]+)%s+([א-ת]+)$';

p["ספר"] = function (frame)
    local title = frame.args[1]
    local result, _, _ = string.match(title, PATTERN_PEREQ);
    return result
end

p["מסכת"] = function (frame)
    local title = frame.args[1]
    local _, result, _ = string.match(title, PATTERN_PEREQ);
    return result
end

p["פרק"] = function (frame)
    local title = frame.args[1]
    local _, _, result = string.match(title, PATTERN_PEREQ);
    return result
end

-- הפוקנציה מקבלת שם של דף, מפרקת אותו לשלושה
-- חלקים (ספר, פרק וסעיף), ומכניסה
-- את החלקים האלה לתבנית הנתונה.
p["כותרת לסעיף בספר"] = function (frame)
    local title = frame.args[1]
    local template = frame.args[2]
    return p.koteret_lseif_bsefer(title, template)
end

p.koteret_lseif_bsefer =  function (title, template)
    local sefer, pereq, seif = string.match(title, PATTERN_SEIF_BSEFER)
    local seif_qodem = haqodem(seif);
    local seif_haba  = haba(seif);
    template = template:gsub('<ספר>', sefer);
    template = template:gsub("<פרק>", pereq);
    template = template:gsub("<סעיף>", seif);
    template = template:gsub("<סעיף קודם>",  seif_qodem);
    template = template:gsub("<סעיף הבא>",  seif_haba);
    return template
end


-- הפוקנציה מקבלת שם של דף, מפרקת אותו לשלושה חלקים (ספר, מסכת ופרק), ומכניסה את החלקים האלה לתבנית הנתונה.
-- למשל: אם שם הדף הוא "ירושלמי בבא קמא א",
-- והתבנית היא: "אאא <ספר> בבב <מסכת> גגג <פרק<"
-- אז הפונקציה תחזיר: "אאא ירושלמי בבב בבא קמא גגג א"
p["כותרת לפרק"] = function (frame)
    local title = frame.args[1]
    local template = frame.args[2]
    local sefer, maseket, pereq = string.match(title, PATTERN_PEREQ)
    local pereq_qodem = haqodem(pereq);
    local pereq_haba  = haba(pereq);
    template = template:gsub('<ספר>', sefer);
    template = template:gsub("<מסכת>", maseket);
    template = template:gsub("<פרק>", pereq);
    template = template:gsub("<פרק קודם>", pereq_qodem);
    template = template:gsub("<פרק הבא>", pereq_haba);
    return template
end

-- בטבלה זו, בכל כניסה בטבלה, צריכה להיות רשימה של מספרי המשניות בכל פרק במסכת.
-- למשל, במסכת פאה, בפרק א, יש 5 משניות, וכן הלאה.
local mispar_mishnayot_bepereq = {
    ['משנה'] = {
        ['פאה'] = 
            {5, 5, 7, 7, 7, 8, 7, 8},
        ['ברכות'] = 
            {6, 9, 6, 6, 5, 8, 5, 8,5},
        ['שקלים'] = 
            {7, 5, 3, 5, 4, 4, 3, 4},
    },
    ['ירושלמי'] = {
        ['פאה'] = 
            {5, 5, 7, 7, 7, 8, 7, 8},
        ['ברכות'] = 
            {6, 9, 6, 6, 5, 8, 5, 8,5},
        ['שקלים'] = 
            {7, 5, 3, 5, 4, 4, 3, 4},
        ['כלאים'] = 
            {9, 8, 6, 6, 7, 4, 6, 4, 6},
        ['שביעית'] =
            {6, 7, 7, 8, 4, 4, 2, 8, 6, 4},
        ['תרומות'] =     	
          	{5, 3, 5, 8, 3, 3, 3, 4, 3, 6, 5},
        ['מעשרות'] = 
            {5, 4, 4, 4, 3},
        ['מעשר שני'] =
            {3, 4, 6, 6, 5},
        ['חלה'] = 
            {6, 3, 5, 5},
           
    },
    ['בבלי'] = {
        ['פאה'] = 
            {0, 0, 0, 0, 0, 0, 0, 0},
        ['ברכות'] = 
            {6, 9, 6, 6, 5, 8, 5, 8,5},
        ['שקלים'] = 
            {7, 5, 3, 5, 4, 4, 3, 4},
    },
}

p.koteret_lseif =  function (title, template)
    local sefer, maseket, pereq, seif = string.match(title, PATTERN_SEIF)
    local pereq_mispar = otiot2mispar(pereq)
    local seif_mispar = otiot2mispar(seif)
    local pereq_qodem = mispar2otiot(pereq_mispar-1)
    local pereq_haba  = mispar2otiot(pereq_mispar+1)
    local seif_qodem = mispar2otiot(seif_mispar-1)
    local seif_haba  = mispar2otiot(seif_mispar+1)
    
    local mispar_mishanyot = mispar_mishnayot_bepereq[sefer]
    if (mispar_mishanyot~=nil) then
        mispar_mishanyot = mispar_mishanyot[maseket]
    end

    -- חישוב פרק וסעיף קודם
    local pereq_wseif_qodem = pereq.." "..seif_qodem
    if seif_mispar==1 then
        if pereq_mispar==1 then  -- תחילת מסכת
            pereq_wseif_qodem = ""
        elseif mispar_mishanyot~=nil and mispar_mishanyot[pereq_mispar-1]~=nil then
            pereq_wseif_qodem = pereq_qodem.." "..mispar2otiot(mispar_mishanyot[pereq_mispar-1])
        end
    end

    -- חישוב פרק וסעיף הבא
    local pereq_wseif_haba  = pereq.." "..seif_haba
    if mispar_mishanyot~=nil and seif_mispar==mispar_mishanyot[pereq_mispar] and mispar_mishanyot[pereq_mispar]~=nil then
        if mispar_mishanyot[pereq_mispar+1]==nil then  -- סוף מסכת
            pereq_wseif_haba = ""
        else
            pereq_wseif_haba = pereq_haba.." ".."א"
        end
    end
    
    template = template:gsub('<ספר>', sefer);
    template = template:gsub("<מסכת>", maseket);
    template = template:gsub("<פרק>", pereq);
    template = template:gsub("<פרק קודם>", pereq_qodem);
    template = template:gsub("<פרק הבא>", pereq_haba);
    template = template:gsub("<סעיף>", seif);
    template = template:gsub("<סעיף קודם>", seif_qodem);
    template = template:gsub("<סעיף הבא>", seif_haba);
    template = template:gsub("<פרק וסעיף קודם>", pereq_wseif_qodem);
    template = template:gsub("<פרק וסעיף הבא>", pereq_wseif_haba);
    
    return template
end


-- הפוקנציה מקבלת שם של דף, מפרקת אותו לארבעה חלקים (ספר, מסכת, פרק, וסעיף/הלכה/משנה), ומכניסה את החלקים האלה לתבנית הנתונה.
-- למשל: אם שם הדף הוא "ירושלמי בבא קמא א ב",
-- והתבנית היא: "אאא <ספר> בבב <מסכת> גגג <פרק<"
-- אז הפונקציה תחזיר: "אאא ירושלמי בבב בבא קמא גגג א"
p["כותרת לסעיף"] = function (frame)
    local title = frame.args[1]
    local template = frame.args[2]
    return p.koteret_lseif(title, template)
end


-- קלט: כותרת של דף של סעיף, למשל "ירושלמי בבא קמא א ב". וכן ספר אחר, לדוגמה "בבלי".
-- פלט: התבנית הנתונה בקלט, עם הנתונים של סעיף זה בספר המקביל, לדוגמה: "בבלי בבא קמא א ב".
-- אבל רק אם הסעיף המקביל אכן נמצא בספר השני. אם הסעיף לא נמצא - תוחזר מחרוזת ריקה.
p.seif_maqbil = function(title, template, sefer)
    local _, maseket, pereq, seif = string.match(title, PATTERN_SEIF)
    local pereq_mispar = otiot2mispar(pereq)
    local seif_mispar = otiot2mispar(seif)
    
    local mispar_mishanyot = mispar_mishnayot_bepereq[sefer]
    if (mispar_mishanyot~=nil) then
        mispar_mishanyot = mispar_mishanyot[maseket]
    end
    if (mispar_mishanyot~=nil) then
        mispar_mishnayot = mispar_mishanyot[pereq_mispar]
    end

    if (mispar_mishnayot~=nil and seif_mispar > mispar_mishnayot) then
        return "" -- הסעיף לא קיים בספר השני
    else
        template = template:gsub('<ספר>', sefer)
        template = template:gsub("<מסכת>", maseket)
        template = template:gsub("<פרק>", pereq)
        template = template:gsub("<סעיף>", seif)
        return template
    end
end

p["סעיף מקביל"] = function (frame)
    return p.seif_maqbil(frame.args[1], frame.args[2], frame.args[3])
end


return p