The part where I beg for programming help.
So, paradigms.
A paradigm can have some number of features (or more mathily, “dimensions”). You can chart the paradigm with columns and rows. If there are two dimensions, it’s easy:
let data = [
["masculine", "neuter", "feminine"],
["singular", "plural"]
]
That will just be:
masculine | neuter | feminine | |
---|---|---|---|
singular | M.Sg | N.Sg | F.Sg |
plural | M.Pl | N.Pl | F.Pl |
You build that by mapping the first array onto the second, thuslywise:
let genders = ["masculine", "neuter", "feminine"]
let numbers = ["singular", "plural"]
genders.map(gender => numbers.map(number => [gender, number]))
And then you get an array of arrays like ["masculine", "singular"]
, which is what we want, for instance, if we want to build a table like the one above. (Actually of course, you would put inflections or something else that has those features in the cells, but all I’m concerned with here is generating a matrix of the combinations of the features.)
[
[
[ "masculine", "singular" ], [ "masculine", "plural" ]
],
[
[
"neuter", "singular" ], [ "neuter", "plural" ]
],
[
[ "feminine", "singular" ], [ "feminine", "plural" ]
]
]
Once this is in place, rendering a table or whatever is quite easy.
But here’s what I want to do: I want to write a function that does this for any number of dimensions.
So maybe it’s number
, case
, gender
. If there are 8 cases that will be 2 * 3 * 8 = 48
combinations in all, and it as a table it will have number as rows, case as columns, and gender as “sub-columns” (which is actually a rather weird layout, but again, whatevs).
For sure this requires some kind of thing with recurisive mapping, but I just can’t seem to get it to work as a general function:
let genders = ["masculine", "neuter", "feminine"]
let cases = [ "nominative", "accusative", "genitive", "dative", "instrumental", "ablative", "locative" ]
let numbers = ["singular", "plural"]
genders.map(gender => numbers.map(number => cases.map(kase => [gender, number, kase])))
And you get this beast:
[
[
[
[ "masculine", "singular", "nominative" ],
[ "masculine", "singular", "accusative" ],
[ "masculine", "singular", "genitive" ],
[ "masculine", "singular", "dative" ],
[ "masculine", "singular", "instrumental" ],
[ "masculine", "singular", "ablative" ],
[ "masculine", "singular", "locative" ]
],
[
[ "masculine", "plural", "nominative" ],
[ "masculine", "plural", "accusative" ],
[ "masculine", "plural", "genitive" ],
[ "masculine", "plural", "dative" ],
[ "masculine", "plural", "instrumental" ],
[ "masculine", "plural", "ablative" ],
[ "masculine", "plural", "locative" ]
]
],
[
[
[ "neuter", "singular", "nominative" ],
[ "neuter", "singular", "accusative" ],
[ "neuter", "singular", "genitive" ],
[ "neuter", "singular", "dative" ],
[ "neuter", "singular", "instrumental" ],
[ "neuter", "singular", "ablative" ],
[ "neuter", "singular", "locative" ]
],
[
[ "neuter", "plural", "nominative" ],
[ "neuter", "plural", "accusative" ],
[ "neuter", "plural", "genitive" ],
[ "neuter", "plural", "dative" ],
[ "neuter", "plural", "instrumental" ],
[ "neuter", "plural", "ablative" ],
[ "neuter", "plural", "locative" ]
]
],
[
[
[ "feminine", "singular", "nominative" ],
[ "feminine", "singular", "accusative" ],
[ "feminine", "singular", "genitive" ],
[ "feminine", "singular", "dative" ],
[ "feminine", "singular", "instrumental" ],
[ "feminine", "singular", "ablative" ],
[ "feminine", "singular", "locative" ]
],
[
[ "feminine", "plural", "nominative" ],
[ "feminine", "plural", "accusative" ],
[ "feminine", "plural", "genitive" ],
[ "feminine", "plural", "dative" ],
[ "feminine", "plural", "instrumental" ],
[ "feminine", "plural", "ablative" ],
[ "feminine", "plural", "locative" ]
]
]
]
So want to write:
let combine = dimensions => {
}
Such that it will work with:
combine(gender, number)
or
combine(gender, case, number)
…or whatever.
Thus ends my docling Stackoverflow question.