aboutsummaryrefslogtreecommitdiff
path: root/lib/plurals.nom
blob: da0fa4d3cefc1f749a40cd63eab08e4554841998 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
require "lib/core.nom"
require "lib/secrets.nom"

# Plurals
with secrets:
    lua block ".."
        |local endings = setmetatable({x="es",c="es",s="es"}, {__index=function() return "s"; end});
        |secrets.plurals = setmetatable({}, {__index=function(self,key)
        |    return key..endings[key:sub(-1)];
        |end});
        |secrets.singulars = setmetatable({}, {__index=function(self,key)
        |    if key:sub(-2) == "es" and rawget(endings, key:sub(-3,-3)) then; return key:sub(1,-3); end;
        |    if key:sub(-1) == "s" then; return key:sub(1,-2); end;
        |    return key;
        |end});
        |secrets.canonicals = setmetatable({}, {__index=function(self,key)
        |    if key:sub(-1) == "s" then; return secrets.singulars[key]; end;
        |    return key;
        |end});

    rule [the plural of %singular is %plural] =:
        (secret %plurals)->%singular = %plural
        (secret %singulars)->%plural = %singular
        (secret %canonicals)->%plural = %singular

    rule [singular %plural] =:
        %plural in (secret %singulars)

    rule [plural %singular] =:
        %singular in (secret %plurals)

    rule [canonicalize %item_name] =:
        %item_name in (secret %canonicals)

    rule [rules that change plurals] =: ["the plural of % is %"]