Editing Module:D'ni Tools

From Guild of Archivists
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 10: Line 10:
local args = {}
local args = {}
local origArgs
local origArgs
local root


local output = ''
local output = ''


-- Local Functions
-- Local Functions
local function num2dnum(str,sep)
        str = str or ''
str = mw.text.trim(str)
if (sep == nil or sep == '') then
sep = "|"
end
local output = "nil"
local num = tonumber(str)
if (num ~= nil and num >= 0) then
output = num % 25
while (num >= 25) do
num = math.floor(num / 25)
output = tostring(num % 25)..sep..output
end
end
return output
end
local function dnum2num(str,sep)
  str = str or ''
  sep = sep or ''
  local output = mw.text.trim(str)
  output = mw.ustring.gsub(output,"%d%d",  {["24"] = "O",
                                ["23"] = "N",
                                ["22"] = "M",
                                ["21"] = "L",
                                ["20"] = "K",
                                ["19"] = "J",
                                ["18"] = "I",
                                ["17"] = "H",
                                ["16"] = "G",
                                ["15"] = "F",
                                ["14"] = "E",
                                ["13"] = "D",
                                ["12"] = "C",
                                ["11"] = "B",
                                ["10"] = "A"
                                })
                               
    output = mw.ustring.gsub(output,sep,"")
   
    output = tonumber(output,25)
   
    return output
                             
end
local function dnum2dnifont(str,min,use25,useWrap)
    str = str or ""
    min = min or 0
    use25 = use25 or false
    useWarp = useWrap or false
    local output = mw.text.trim(str)
   
    if str == "25" and use25 then output = "|"
    elseif str == "0" and useWrap then output = "="
    else
      output = mw.ustring.gsub(output,"%d%d",  {["24"] = "}",
                                ["23"] = "{",
                                ["22"] = "\\",
                                ["21"] = "]",
                                ["20"] = "[",
                                ["19"] = "(",
                                ["18"] = "*",
                                ["17"] = "&",
                                ["16"] = "^",
                                ["15"] = "%",
                                ["14"] = "$",
                                ["13"] = "#",
                                ["12"] = "@",
                                ["11"] = "!",
                                ["10"] = ")"
                                })
      output = mw.ustring.gsub(output,"%|","")
      if #output < min then output = string.rep("0", (min - #output))..output end
    end
    return output
end
local function dnifont2dnum(str,sep)
    str = mw.text.trim(str)
   
    local chars = mw.text.split(str,'')
   
    local output = table.concat(chars,sep)
   
   
    output = mw.ustring.gsub(output,"%S",  {["}"] = "24" ,
                                ["{"] = "23",
                                ["\\"] = "22",
                                ["]"] = "21",
                                ["["] = "20",
                                ["("] = "19",
                                ["*"] = "18",
                                ["&"] = "17",
                                ["^"] = "16",
                                ["%"] = "15",
                                ["$"] = "14",
                                ["#"] = "13",
                                ["@"] = "12",
                                ["!"] = "11",
                                [")"] = "10"
                                })
    return output
end


local function dnifont2ots(str)
local function dnifont2ots(str)
Line 173: Line 48:
                                 ["O"] = "ó",  
                                 ["O"] = "ó",  
                                 ["c"] = "ç",  
                                 ["c"] = "ç",  
                                 ["E"] = "í",  
                                 ["E"] = "i",  
                                 ["A"] = "é",  
                                 ["A"] = "é",  
                                 ["U"] = "ú",
                                 ["U"] = "ú",
Line 190: Line 65:




local function parseDniWord(input,count)
local function parseDniWord(input)


     local output  
     local output  
    local name = 'quote'..count


     local word = mw.text.trim(input)
     local word = mw.text.trim(input)
Line 206: Line 79:
         suffix = prefix
         suffix = prefix
     end  
     end  


     if (word == '') then
     if (word == '') then
Line 216: Line 88:
     elseif (first == '-') then
     elseif (first == '-') then
         output = prefix..'[[Dictionary:'..word..'|'..mw.ustring.sub(word,2,-1)..']]'..suffix
         output = prefix..'[[Dictionary:'..word..'|'..mw.ustring.sub(word,2,-1)..']]'..suffix
        mw.smw.subobject('ContainsTerm=Dictionary:'..word,name)
     elseif (last == '-') then
     elseif (last == '-') then
         output = prefix..'[[Dictionary:'..word..'|'..mw.ustring.sub(word,1,-2)..']]'..suffix
         output = prefix..'[[Dictionary:'..word..'|'..mw.ustring.sub(word,1,-2)..']]'..suffix
        mw.smw.subobject('ContainsTerm=Dictionary:'..word,name)
     elseif (first == '.' or first == '!' or first == '?' or first == ',') then
     elseif (first == '.' or first == '!' or first == '?' or first == ',') then
         output = first..prefix..'[[Dictionary:'..mw.ustring.sub(word,2,-1)..'|'..mw.ustring.sub(word,2,-1)..']]'..suffix
         output = first..prefix..'[[Dictionary:'..mw.ustring.sub(word,2,-1)..'|'..mw.ustring.sub(word,2,-1)..']]'..suffix
        mw.smw.subobject('ContainsTerm=Dictionary:'..mw.ustring.sub(word,1,-2),name)
     elseif (last == ',') then
     elseif (last == ',') then
         output = prefix..'[[Dictionary:'..mw.ustring.sub(word,1,-2)..'|'..mw.ustring.sub(word,1,-2)..']]'..suffix..last
         output = prefix..'[[Dictionary:'..mw.ustring.sub(word,1,-2)..'|'..mw.ustring.sub(word,1,-2)..']]'..suffix..last
        mw.smw.subobject('ContainsTerm=Dictionary:'..mw.ustring.sub(word,1,-2),name)
     else
     else
         output = prefix..'[[Dictionary:'..word..'|'..word..']]'..suffix
         output = prefix..'[[Dictionary:'..word..'|'..word..']]'..suffix
        mw.smw.subobject('ContainsTerm=Dictionary:'..word,name)
     end
     end




     return output
     return output
end
local function preprocessSingleArg(argName)
    -- If the argument exists and isn't blank, add it to the argument table.
    -- Blank arguments are treated as nil to match the behaviour of ParserFunctions.
    if origArgs[argName] and origArgs[argName] ~= '' then
        args[argName] = origArgs[argName]
    end
end
end


Line 250: Line 109:
     else
     else
         origArgs = frame.args
         origArgs = frame.args
    end
    count=0
    if (frame:callParserFunction('#varexists:count') ~= '1') then
        frame:callParserFunction('#vardefine:count','0')
    else
        count = tonumber(frame:callParserFunction('#var:count'))
        count = count + 1
        frame:callParserFunction('#vardefine:count',count)
     end
     end


     for word in ipairs(origArgs) do
     for word in ipairs(origArgs) do
         output = output..parseDniWord(origArgs[word],count)
         output = output..parseDniWord(origArgs[word])
     end
     end
    name='quote'..count
    quote=string.gsub(output,'%|','{{!}}')
--    quote=mw.text.nowiki(output)
    mw.smw.subobject('ContainsQuote='..quote,name)


     return output
     return output
end
-- For call by other Modules
function p._num2dnum(str,sep)
  return num2dnum(str,sep)
end
function p._dnum2num(str,sep)
  return dnum2num(str,sep)
end
function p._dnum2dnifont(str,min,use25,useWrap)
  return dnum2dnifont(str,min,use25,useWrap)
end
function p._dnifont2dnum(str,sep)
  return dnifont2dnum(str,sep)
end
function p._num2dnifont(str,min,use25,useWrap)
  return dnum2dnifont(num2dnum(str),min,use25,useWrap)
end
end


function p.dnifont2ots(frame)
function p.dnifont2ots(frame)
    return dnifont2ots(frame.args[1])
end
function p.dnifont2nts(frame)
    return dnifont2nts(frame.args[1])
end
function p.num2dnum(frame)
     -- If called via #invoke, use the args passed into the invoking template.
     -- If called via #invoke, use the args passed into the invoking template.
     -- Otherwise, for testing purposes, assume args are being passed directly in.
     -- Otherwise, for testing purposes, assume args are being passed directly in.
Line 311: Line 124:
         origArgs = frame:getParent().args
         origArgs = frame:getParent().args
     else
     else
         origArgs = frame.args
         origArgs = frame
     end
     end


     preprocessSingleArg(1)
     return origArgs['1']
    preprocessSingleArg('val')
    preprocessSingleArg('format')
    preprocessSingleArg('sep')
 
    local output
 
    local val = args['val'] or args[1]
if (args['format'] == 'dnifont') then
output = dnum2dnifont(num2dnum(val))
else
output = num2dnum(val,args['sep'])
end
    return output
end
end


function p.dnifont2dnum(frame)
function p.dnifont2nts(frame)
 
     -- If called via #invoke, use the args passed into the invoking template.
     -- If called via #invoke, use the args passed into the invoking template.
     -- Otherwise, for testing purposes, assume args are being passed directly in.
     -- Otherwise, for testing purposes, assume args are being passed directly in.
Line 341: Line 136:
         origArgs = frame:getParent().args
         origArgs = frame:getParent().args
     else
     else
         origArgs = frame.args
         origArgs = frame
     end
     end


     preprocessSingleArg(1)
     return dnifont2nts(origArgs[1])
    preprocessSingleArg('sep')
 
return dnifont2dnum(args[1],args['sep'])
end
end


function p.dnum2num(frame)


    -- If called via #invoke, use the args passed into the invoking template.
    -- Otherwise, for testing purposes, assume args are being passed directly in.
    if frame == mw.getCurrentFrame() then
        origArgs = frame:getParent().args
    else
        origArgs = frame.args
    end
    preprocessSingleArg(1)
    preprocessSingleArg('sep')
return dnum2num(args[1],args['sep'])
end


return p
return p
Please note that all contributions to Guild of Archivists may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see GoArch:Copyrights for details). Do not submit copyrighted work without permission!
Cancel Editing help (opens in new window)

Template used on this page: