Code: Select all
function matRLT(iptr, ix)
local ix = ix or 1
tblRLT = tblRLT or {}
cwrlt = cwrlt or 0
--[[ relationship ]]
local rlt = ''
--[[ pre = pre replacement ]]
local pre = ''
--[[ pst = post replacement ]]
local pst = ''
--[[ rpl = replacement area ]]
local rpl = ''
--[[ tho = throw away parts ]]
local tho = ''
rlt = fhCallBuiltInFunction('Relationship', ptrRoot, iptr, 'TEXT', ix)
if rlt == '' then
return rlt
end
-- correct rltdata
rlt = rlt:gsub( '%-removed', ' removed' ) -- fix error (removed and -removed 1st cousins
rlt = rlt:gsub( 'once', '1 times' ) -- text to numeric
rlt = rlt:gsub( 'twice','2 times' ) -- text to numeric
rlt = rlt:gsub( '^(%d[^%d])(.*)', ' %1%2' ) -- align leading numerics
rlt = rlt:gsub( '%(x(%d)%)', '(x0%1)' ) -- (xd) padded to (x0d)
rlt = rlt:gsub( 'great great%-', 'great (x02) ' ) -- reduce great great-
pre, rpl, pst = string.match(rlt, '(.*[^%d])(%d+ times)(.*)') -- d or dd times to (xdd)
if rpl ~= nil then
rpl = tonumber(string.match(rpl, '(%d+)'))
if rpl < 10 then
rpl = ('0'..rpl)
end
rlt = (pre .. '(x'.. rpl .. ')' .. pst)
end
pre, rpl, tho, pst = string.match(rlt, '(.*) %(x(%d+)%) (great%-)(.*)') -- remove great- add 1 to x(dd)
if tho ~= nil then
rpl = (tonumber(rpl) + 1)
if rpl < 10 then
rpl = ('0'.. rpl)
end
rpl = '(x' .. rpl .. ')'
rlt = pre .. ' ' .. rpl .. ' ' .. pst
end
rlt = rlt:gsub( 'great%-', 'great ' ) -- change great- to great
rlt = rlt:gsub( 'great', 'Great' ) -- change great- to great
rlt = rlt:gsub( 'grand', 'Grand' ) -- change great- to great
rlt = rlt:gsub( 'uncle', 'Uncle' ) -- change great- to great
rlt = rlt:gsub( 'aunt', 'Aunt' ) -- change great- to great
return rlt
end --fn matRLT
tblRLT:
[4th cousin once removed], [ 4th cousin (x01) removed]
...
...
I suppose I could add a counter of how often I see the relation, sort it descending, at end of program so
for k, v in pairs(tblRLT) does an even faster lookup
so, the closest thing I can find that does that, is Map Life Facts.
I got tablex is needed for loading and saving.
local Folder = fhGetContextInfo('CI_APP_DATA_FOLDER') -- global to all projects
local Filename = Folder .. '\\Plugin Data\\tblRLT.dat'
local tblRLT = { 'grandfather', 'Grandfather' } and so on.
table.save(tblRLT, Filename) -- save the table to file
tblRLT = table.load(Filename) -- load the table from file
(thats all the simple part....)
Now the one program I know does this and does it in a way I want it to is that Map Life Facts.
I cannot find the logic (because the program is too advanced for me) if the table does not exist, make it, and load it. if it exists, use it, and update as necessary. sort of condensed so I can make small feeding functions to matRLT.
where is that simple logic condensed in some snippet or program?