انتقل إلى المحتوى

وحدة:Past Participle

من ويكاموس، القاموس الحر
local p = {}

-- A table of common irregular verbs and their past participle forms
local irregularVerbs = {
    ["be"] = "been",
    ["become"] = "become",
    ["begin"] = "begun",
    ["break"] = "broken",
    ["bring"] = "brought",
    ["build"] = "built",
    ["buy"] = "bought",
    ["catch"] = "caught",
    ["choose"] = "chosen",
    ["come"] = "come",
    ["do"] = "done",
    ["drink"] = "drunk",
    ["eat"] = "eaten",
    ["fall"] = "fallen",
    ["feel"] = "felt",
    ["find"] = "found",
    ["fly"] = "flown",
    ["forget"] = "forgotten",
    ["get"] = "gotten",
    ["give"] = "given",
    ["go"] = "gone",
    ["have"] = "had",
    ["know"] = "known",
    ["leave"] = "left",
    ["make"] = "made",
    ["meet"] = "met",
    ["put"] = "put",
    ["read"] = "read", -- Note: past participle is pronounced as 'red'
    ["ride"] = "ridden",
    ["ring"] = "rung",
    ["run"] = "run",
    ["say"] = "said",
    ["see"] = "seen",
    ["sell"] = "sold",
    ["send"] = "sent",
    ["sing"] = "sung",
    ["sit"] = "sat",
    ["speak"] = "spoken",
    ["spend"] = "spent",
    ["take"] = "taken",
    ["teach"] = "taught",
    ["tell"] = "told",
    ["think"] = "thought",
    ["understand"] = "understood",
    ["win"] = "won",
    ["write"] = "written"
}

-- Function to check if a string contains only English letters and optional spaces or apostrophes
local function isEnglishText(text)
    return text:match("^[A-Za-z '%-]+$") ~= nil
end

-- Function to get the present and past participle forms of a verb
function p.main(frame)
    -- Get the verb from the arguments or use the page name
    local verb = frame.args[1] or frame:getTitle():getText()

    -- Check if the verb is valid English text
    if not isEnglishText(verb) then
        return "<span style='color:red; font-weight:bold;'>خطأ: يجب أن يكون الإدخال نصًا باللغة الإنجليزية فقط.</span>"
    end

    -- Check for irregular verbs
    if irregularVerbs[verb] then
        return irregularVerbs[verb]
    end

    -- Handle regular verbs (adding -ing and -ed)
    local presentParticiple = verb .. "ing"
    local pastParticiple

    if verb:sub(-1) == "e" then
        pastParticiple = verb .. "d"
    elseif verb:sub(-1) == "y" and not (verb:sub(-2, -2):match("[aeiou]")) then
        pastParticiple = verb:sub(1, -2) .. "ied"
    else
        pastParticiple = verb .. "ed"
    end

    return pastParticiple
end

return p