Module:R:he:HWSSRoot

Hello, you have come here looking for the meaning of the word Module:R:he:HWSSRoot. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:R:he:HWSSRoot, but we will also tell you about its etymology, its characteristics and you will know how to say Module:R:he:HWSSRoot in singular and plural. Everything you need to know about the word Module:R:he:HWSSRoot you have here. The definition of the word Module:R:he:HWSSRoot will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:R:he:HWSSRoot, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.

This module implements the reference template {{R:he:HWSSRoot}}.


local p = {}

local list = require("Module:R:he:HWSSRoot/data")

local hebrew_letters = {
	 = "ʾ",
	 = "B",
	 = "G",
	 = "D",
	 = "H",
	 = "W",
	 = "Z",
	 = "X",
	 = "7",
	 = "Y",
	"] = "K",
	 = "L",
	"] = "M",
	"] = "N",
	 = "S",
	 = "&",
	"] = "P",
	"] = "C",
	 = "Q",
	 = "R",
	 = "ʃ",
	 = "T",
}

local function cleanup(value)
	return value:gsub("/.", ""):gsub("%(.*", ""):gsub("$", ""):gsub(" ", " "):gsub("(.)%1$","%1"):gsub("(.)%1 ","%1 ")
end

function p.hebrew_to_normalized_latin(term)
	local normalized = term:gsub("שׁ" ,"ש"):gsub("שׂ", "ש"):gsub("־", "")
	for k, v in pairs(hebrew_letters) do
		normalized = mw.ustring.gsub(normalized, k, v)
	end
	return cleanup(normalized)
end

function p.latin_to_hebrew_for_sorting(term)
	local normalized = term
	for k, v in pairs(hebrew_letters) do
		if mw.ustring.find(k, "%[") then
			normalized = mw.ustring.gsub(normalized, v, mw.ustring.sub(k, 2, 2))
		else
			normalized = mw.ustring.gsub(normalized, v, k)
		end
	end
	return normalized
end

function p.simple_latin(frame)
	return hebrew_to_normalized_latin(frame.args)
end

function p.page_number(frame)
	local value = p.hebrew_to_normalized_latin(frame.args)
	value = p.latin_to_hebrew_for_sorting(value)
    local low = 1
    local high = #list
    local mid = 0
    while high - low > 1 do
        mid = math.floor((low+high)/2)
        local midval = p.latin_to_hebrew_for_sorting(cleanup(list))
        if midval == value then return 78 + mid
        elseif midval < value then low = mid
        elseif midval > value then high = mid - 1
        end
    end

    if p.latin_to_hebrew_for_sorting(list) <= value then return 78 + high
    else return 78 + low
    end
end

return p