re-implementing in another language is often helpful
I thought lua’s tables should lend themselves to the
structure we have here, so I tried another approach –
and found another quirk:
your solution depends on the order of entry
I had to add lines 50, 106–109 incl., and change
lines 61 and 277 in order to get the correct results.
Am 08.01.21 um 07:56 schrieb Hauke Rehr:
> … and here’s a J implementation (and output)
> but I stumbled upon another aspect that didn’t
> match the specification as I understood it:
>
> consider the first example 13510:
> your solution contains SIMUL which is 13509
> so I implemented that whenever either of them
> has a 0, they match. I think that’s wrong.
> The query may be more general but not more
> specific than the things we want it to match.
>
> In my D implementation, it’s in the function
> match in lines 105 through 117, (I already
> wondered if it’s wrong but didn’t check again
> after I found I got your ‘correct’ results);
> in the J script, it’s where the comment says
> what’s superfluous.
>
> … and I edited the 0 : 0 content (added an LF)
> in order to not have to do too much parsing
>
> cheers,
> Hauke
>
>
> Am 08.01.21 um 04:41 schrieb Hauke Rehr:
>> I jotted down a q&d-implementation in D.
>> When I found out that your example doesn’t
>> fit the hierarcical layout (multiple instances
>> for 11, for example, so 11 isn’t a category
>> even though there are things like 111),
>> I ripped out the code depending on the hierarchy.
>>
>> The results agree with your results so I think
>> this should be a correct re-implementation.
>>
>> Am 08.01.21 um 00:30 schrieb Hauke Rehr:
>>> That post was written too soon.
>>> Now that I’ve taken a look at what ordinal fractions
>>> are meant to be, it looks to me more like what I think
>>> I first came to know when learning some prolog.
>>> I try to write down my new understanding of ordinal fractions,
>>> in a more old-fashioned lingo of enums (concepts)
>>> with their elements, and tagging data with them:
>>>
>>> there is an a priori given set of hierarchical enums
>>> where subordinate ones’ range and meaning may depend
>>> on superordinate ones
>>> you tag any data by at most one element of each enum
>>> where the elements themselves are part of the data
>>> (and are tagged by themselves only)
>>> any data with an incomplete set of tags is a category
>>> all “leaf data” if thought of the hierarchy as a tree
>>> is given a full set of tags.
>>> then you just do some matching where everything matches unless
>>> there is an enum the things to be matched both have an entry of
>>> and where the entries don’t agree
>>>
>>> @bo: Is this “translation” of the concept of ordinal fractions adequate?
>>>
>>>
>>>
>>
>
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
--
----------------------
mail written using NEO
neo-layout.org
do
local pop = function(t)
local res = t[#t]
t[#t] = nil
return res
end
local register = function(where, what, at)
local here = where[at] or {}
here[#here+1] = what
where[at] = here
end
local getall
getall = function(node, names)
local names = names or {}
if node.names then
for _,v in ipairs(node.names) do
names[#names+1] = v
end
end
for k = 0, 9 do
if node[k] then
getall(node[k], names)
end
end
return names
end
local getdigits = function(where)
local digits = {}
if type(where) == "string" then
for k = where:len(), 1, -1 do
digits[#digits+1] = tonumber(where:sub(k, k))
end
else
repeat
tmp = where % 10
digits[#digits+1] = tmp
where = (where - tmp)/10
until where == 0
end
return digits
end
ofmt = {}
ofmt.__index = ofmt
ofmt.create = function()
local instance = {}
setmetatable(instance, ofmt)
return instance
end
function ofmt:add(what, where)
self.N = (self.N or 0) + 1
local digits = getdigits(where)
local current = self
local tmp
local at = pop(digits)
while at do
tmp = current[at] or {}
current[at] = tmp
current = tmp
at = pop(digits)
end
register(current, { what, self.N }, "names")
end
function ofmt:query(where)
local digits = getdigits(where)
local tzs = 0 -- in case digits is { 0 }
for k,v in ipairs(digits) do
if v > 0 then tzs = k-1 break end
end
for k = 1, #digits do
digits[k] = digits[k+tzs]
end
local matching = { self }
local at = pop(digits)
local all, m
local names = {}
repeat
all = at == 0
m = {}
for _,v in ipairs(matching) do
if v.names then
for i,w in ipairs(v.names) do
names[#names+1] = w
end
end
if v[0] then
m[#m+1] = v[0]
end
if not all and v[at] then
m[#m+1] = v[at]
else
for k = 1, 9 do
if v[k] then
m[#m+1] = v[k]
end
end
end
end
matching = m
at = pop(digits)
until not at
for _,v in ipairs(matching) do
for _,w in ipairs(getall(v)) do
names[#names+1] = w
end
end
sorter = function(a, b)
return a[2] < b[2]
end
table.sort(names, sorter)
return names
end
end
credoOf = ofmt.create()
credoOf:add("CREDO", 1)
credoOf:add("IN", 11)
credoOf:add("UNUM", 111)
credoOf:add("DEUM", 11)
credoOf:add("PATREM", 112)
credoOf:add("OMNIPOTENTEM", 1121)
credoOf:add("FACTOREM", 113)
credoOf:add("CÆLI", 1131)
credoOf:add("ET", 1139)
credoOf:add("TERRÆ", 1132)
credoOf:add("VISIBILIUM", 11331)
credoOf:add("OMNIUM", 1133)
credoOf:add("ET", 11339)
credoOf:add("INVISIBILIUM", 11332)
credoOf:add("ET", 19)
credoOf:add("IN", 12)
credoOf:add("UNUM", 1211)
credoOf:add("DOMINUM", 1211)
credoOf:add("JESUM", 12)
credoOf:add("CHRISTUM", 1211)
credoOf:add("FILIUM", 1212)
credoOf:add("DEI", 1212)
credoOf:add("UNIGENITUM", 12121)
credoOf:add("ET", 1219)
credoOf:add("EX", 1213)
credoOf:add("PATRE", 1213)
credoOf:add("NATUM", 1213)
credoOf:add("ANTE", 12131)
credoOf:add("OMNIA", 121311)
credoOf:add("SÆCULA", 12131)
credoOf:add("DEUM", 1221)
credoOf:add("DE", 12211)
credoOf:add("DEO", 12211)
credoOf:add("LUMEN", 1222)
credoOf:add("DE", 12221)
credoOf:add("LUMINE", 12221)
credoOf:add("DEUM", 1223)
credoOf:add("VERUM", 12231)
credoOf:add("DE", 12232)
credoOf:add("DEO", 12232)
credoOf:add("VERO", 122321)
credoOf:add("GENITUM", 1231)
credoOf:add("NON", 12311)
credoOf:add("FACTUM", 12311)
credoOf:add("CONSUBSTANTIALEM", 1232)
credoOf:add("PATRI", 1232)
credoOf:add("PER", 12321)
credoOf:add("QUEM", 12321)
credoOf:add("OMNIA", 12321)
credoOf:add("FACTA", 12321)
credoOf:add("SUNT", 12321)
credoOf:add("QUI", 124)
credoOf:add("PROPTER", 124101)
credoOf:add("NOS", 124101)
credoOf:add("HOMINES", 12410101)
credoOf:add("ET", 124109)
credoOf:add("PROPTER", 124102)
credoOf:add("NOSTRAM", 12410201)
credoOf:add("SALUTEM", 124102)
credoOf:add("DESCENDIT", 12411)
credoOf:add("DE", 1241101)
credoOf:add("CÆLIS", 1241101)
credoOf:add("ET", 12419)
credoOf:add("INCARNATUS EST", 12412)
credoOf:add("DE", 1241201)
credoOf:add("SPIRITU", 1241201) credoOf:add("SANCTO", 124120101)
credoOf:add("EX", 1241202)
credoOf:add("MARIA", 1241202)
credoOf:add("VIRGINE", 124120201)
credoOf:add("ET", 12419)
credoOf:add("HOMO", 1241301)
credoOf:add("FACTUS EST ", 12413)
credoOf:add("CRUCIFIXUS", 124211)
credoOf:add("ETIAM", 1242101)
credoOf:add("PRO", 1242101)
credoOf:add("NOBIS", 1242101)
credoOf:add("SUB", 1242102)
credoOf:add("PONTIO", 1242102)
credoOf:add("PILATO", 1242102)
credoOf:add("PASSUS", 124212)
credoOf:add("ET", 124219)
credoOf:add("SEPULTUS", 124213)
credoOf:add("EST", 12421)
credoOf:add("ET", 12429)
credoOf:add("RESURREXIT", 12422)
credoOf:add("TERTIA", 124221)
credoOf:add("DIE", 124221)
credoOf:add("SECUMDUM", 124222)
credoOf:add("SCRIPTURAS", 124222)
credoOf:add("ET", 12429)
credoOf:add("ASCENDIT", 12423)
credoOf:add("IN", 124231)
credoOf:add("CÆLUM", 124231)
credoOf:add("SEDET", 12424)
credoOf:add("AD", 124241)
credoOf:add("DEXTERAM", 124241)
credoOf:add("PATRIS", 124241)
credoOf:add("ET", 12429)
credoOf:add("ITERUM", 124251)
credoOf:add("VENTURUS EST", 12425)
credoOf:add("CUM", 124252)
credoOf:add("GLORIA", 124252)
credoOf:add("JUDICARE", 124253)
credoOf:add("VIVOS", 1242531)
credoOf:add("ET", 1242539)
credoOf:add("MORTUOS", 1242532)
credoOf:add("CUJUS", 125)
credoOf:add("REGNI", 125)
credoOf:add("NON ERIT", 125)
credoOf:add("FINIS", 125)
credoOf:add("ET", 19)
credoOf:add("IN", 13)
credoOf:add("SPIRITUM", 13)
credoOf:add("SANCTUM", 131)
credoOf:add("DOMINUM", 132)
credoOf:add("ET", 139)
credoOf:add("VIVIFICANTEM", 133)
credoOf:add("QUI", 134)
credoOf:add("EX", 134)
credoOf:add("PATRE", 1341)
credoOf:add("FILIO", 1342)
credoOf:add("QUE", 1349)
credoOf:add("PROCEDIT", 134)
credoOf:add("QUI", 135)
credoOf:add("CUM", 135)
credoOf:add("PATRE", 13501)
credoOf:add("ET", 13509)
credoOf:add("FILIO", 13502)
credoOf:add("SIMUL", 13509)
credoOf:add("ADORATUR", 1351)
credoOf:add("ET", 1359)
credoOf:add("GLORIFICATUR", 1352)
credoOf:add("QUI", 136)
credoOf:add("LOCUTUS EST", 136)
credoOf:add("PER", 1361)
credoOf:add("PROPHETAS", 1361)
credoOf:add("ET", 19)
credoOf:add("UNAM", 141)
credoOf:add("SANCTAM", 142)
credoOf:add("CATHOLICAM", 143)
credoOf:add("ET", 149)
credoOf:add("APOSTOLICAM", 144)
credoOf:add("ECCLESIAM", 14)
credoOf:add("CONFITEOR", 2)
credoOf:add("UNUM", 211)
credoOf:add("BAPTISMA", 21)
credoOf:add("IN", 212)
credoOf:add("REMISSIONEM", 212)
credoOf:add("PECCATORUM", 2121)
credoOf:add("ET", 9)
credoOf:add("EXPECTO", 3)
credoOf:add("RESURRECTIONEM", 31)
credoOf:add("MORTUORUM", 311)
credoOf:add("ET", 39)
credoOf:add("VITAM", 32)
credoOf:add("VENTURI", 3211)
credoOf:add("SÆCULI", 321)
credoOf:add("AMEN", 0)
testdata = { 13510, 13520, 13501, 13502, 13511, 13512, 13521, 13522 }
for _,v in ipairs(testdata) do
io.write(v)
for _,w in ipairs(credoOf:query(v)) do
io.write(" " .. w[1])
end
print()
end
13510 CREDO IN SPIRITUM QUI CUM PATRE ET FILIO SIMUL ADORATUR AMEN
13520 CREDO IN SPIRITUM QUI CUM PATRE ET FILIO SIMUL GLORIFICATUR AMEN
13501 CREDO IN SPIRITUM QUI CUM PATRE ADORATUR ET GLORIFICATUR AMEN
13502 CREDO IN SPIRITUM QUI CUM FILIO ADORATUR ET GLORIFICATUR AMEN
13511 CREDO IN SPIRITUM QUI CUM PATRE ADORATUR AMEN
13512 CREDO IN SPIRITUM QUI CUM FILIO ADORATUR AMEN
13521 CREDO IN SPIRITUM QUI CUM PATRE GLORIFICATUR AMEN
13522 CREDO IN SPIRITUM QUI CUM FILIO GLORIFICATUR AMEN
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm