1
0
forked from GitHub/gf-rgl

kind of working implementation of cardinal numbers

This commit is contained in:
Herbert Lange
2019-06-25 17:17:46 +02:00
parent a35809e130
commit b90e036472
3 changed files with 192 additions and 68 deletions

View File

@@ -1,4 +1,4 @@
concrete CatLat of Cat = CommonX-[Adv] ** open ResLat, ParamX, Prelude in { concrete CatLat of Cat = CommonX-[Adv,Voc] ** open ResLat, ParamX, Prelude in {
flags optimize=all_subs ; flags optimize=all_subs ;
@@ -60,7 +60,7 @@ concrete CatLat of Cat = CommonX-[Adv] ** open ResLat, ParamX, Prelude in {
-- --
---- Numeral ---- Numeral
-- --
Numeral = ResLat.Numeral ; Numeral = ResLat.TNumeral ;
Digits = {s : Str ; unit : Unit} ; Digits = {s : Str ; unit : Unit} ;
-- --
---- Structural ---- Structural

View File

@@ -1,77 +1,151 @@
concrete NumeralLat of Numeral = CatLat ** open ResLat,ParadigmsLat,Prelude in { concrete NumeralLat of Numeral = CatLat, ParamX[Number] ** open ParadigmsLat, Prelude, ResLat, Predef in {
lincat lincat
Digit = TDigit ; Digit = TDigit ;
Sub10 = Numeral ; Sub10 = TNumeral ;
Sub100 = Numeral ; Sub100 = TNumeral ;
Sub1000 = Numeral ; Sub1000 = TNumeral ;
Sub1000000 = Numeral ; Sub1000000 = TNumeral ;
lin lin
num x = x ; num x = x ;
n2 = lin Digit ( mkDigit "duo" "viginti" "ducenti" "secundus" ) ; n2 = lin Digit ( mkDigit "duo" "duodecim" "viginti" "ducenti" "secundus" "triginta" Yes ) ;
n3 = lin Digit ( mkDigit "tres" "triginta" "trecenti" "tertius" ) ; n3 = lin Digit ( mkDigit "tres" "tredecim" "triginta" "trecenti" "tertius" "quadraginta" Yes ) ;
n4 = lin Digit ( mkDigit "quattuor" "quadraginta" "quadringenti" "quartus" ) ; n4 = lin Digit ( mkDigit "quattuor" "quattuordecim" "quadraginta" "quadringenti" "quartus" "quinquaginta" Yes ) ;
n5 = lin Digit ( mkDigit "quinque" "quinquaginta" "quingenti" "quintus" ) ; n5 = lin Digit ( mkDigit "quinque" "quindecim" "quinquaginta" "quingenti" "quintus" "sexaginta" Yes ) ;
n6 = lin Digit ( mkDigit "sex" "sexaginta" "sescenti" "sextus" ) ; n6 = lin Digit ( mkDigit "sex" "sedecim" "sexaginta" "sescenti" "sextus" "septuaginta" Yes ) ;
n7 = lin Digit ( mkDigit "septem" "septuaginta" "septingenti" "septimus" ) ; n7 = lin Digit ( mkDigit "septem" "septendecim" "septuaginta" "septingenti" "septimus" "octoginta" Yes ) ;
n8 = lin Digit ( mkDigit "octo" "octoginta" "octingenti" "ocatvus" ) ; n8 = lin Digit ( mkDigit "octo" "duodeviginti" "octoginta" "octingenti" "ocatvus" "nonaginta" No8 ) ;
n9 = lin Digit ( mkDigit "novem" "nonaginta" "nongenti" "nonus") ; n9 = lin Digit ( mkDigit "novem" "undeviginti" "nonaginta" "nongenti" "nonus" "centum" No9 ) ;
-- 1 -- 1
pot01 = { s = n1.s ! one ; n = Sg } ; pot01 = { s = n1.s ! one ; d = n1.s ; n = singular ; below8 = n1.below8 } ;
-- d * 1 -- d * 1
pot0 d = { s = d.s ! one ; n = Pl } ; pot0 d = {
s = d.s ! one ;
d = table {
thousand => \\g,c => d.s ! one ! g ! c ++ d.s ! thousand ! g ! c ;
u => \\g,c => d.s ! u ! g ! c
} ;
n = plural ;
below8 = d.below8
} ;
-- 10 -- 10
pot110 = { s = n1.s ! ten ; n = Sg } ; pot110 = {
s = n1.s ! ten ;
d = table {
thousand => \\g,c => n1.s ! ten ! g ! c ++ n1.s ! thousand ! g ! c ;
u => \\g,c => n1.s ! u ! g ! c
} ;
n = singular ;
below8 = Yes
} ;
-- 11 -- 11
-- pot111 = pot1to19 pot01 ; pot111 = pot1to19 n1 ;
-- -- 10 + d -- 10 + d
-- -- pot1to19 d = mkNum "" "" "" "" ; -- {s = d.s ! teen} ** {n = Pl} ; pot1to19 d = {
s = d.s ! eleven ;
d = table {
thousand => \\g,c => d.s ! eleven ! g ! c ++ n1.s ! thousand ! g ! c ;
u => \\g,c => d.s ! u ! g ! c
} ;
n = plural ;
below8 = Ign
} ;
-- coercion of 1..9 -- coercion of 1..9
pot0as1 n = n ; pot0as1 n = n ;
-- d * 10 -- d * 10
pot1 d = {s = d.s ! ten ; n = Pl} ; pot1 d = {
s = d.s ! ten ;
d = table {
thousand => \\g,c => d.s ! ten ! g ! c ++ n1.s ! thousand ! g ! c ;
u => \\g,c => d.s ! u ! g ! c
} ;
n = plural ;
below8 = Yes
} ;
-- d * 10 + n -- d * 10 + n
-- pot1plus d e = { pot1plus d n =
-- s = \\c => d.s ! ten ++ "-" ++ e.s ! one ! c ; let
-- n = Pl} ; newS : Gender => Case => Str = \\g,c => case n.below8 of {
No8 => "duo" ++ Prelude.BIND ++ "-" ++ Prelude.BIND ++ "de" ++ Prelude.BIND ++ "-" ++ Prelude.BIND ++ d.tenNext ;
No9 => "un" ++ Prelude.BIND ++ "-" ++ Prelude.BIND ++ "de" ++ Prelude.BIND ++ "-" ++ Prelude.BIND ++ d.tenNext ;
_ => d.s ! ten ! g ! c ++ n.s ! g ! c
} in
{
s = newS ;
d = table {
thousand => \\g,c => newS ! g ! c ++ n1.s ! thousand ! g ! c ;
u => \\g,c => n.d ! u ! g ! c
} ;
below8 = Ign ;
n = plural
} ;
-- coercion of 1..99 -- coercion of 1..99
pot1as2 n = n ; pot1as2 n = n ;
-- m * 100 -- m * 100
-- pot2 d = {s = d.s ! hundred ; n = Pl} ; pot2 n = {
-- -- m * 100 + n s = n.d ! hundred ;
-- --lin pot2plus d e = { d = table {
-- -- s = \\c => d.s ! unit ! NCard ++ "hundred" ++ "and" ++ e.s ! c ; n = Pl} ; thousand => \\g,c => n.d ! hundred ! g ! c ++ n1.s ! thousand ! g ! c ;
u => \\g,c => n.d ! u ! g ! c
} ;
n = plural ;
below8 = Yes} ;
-- d * 100 + n
pot2plus d n =
let
newS : Gender => Case => Str = \\g,c => d.d ! hundred ! g ! c ++ "et" ++ n.s ! g ! c
in
{
s = newS ;
d = table {
thousand => \\g,c => newS ! g ! c ++ n1.s ! thousand ! g ! c ;
u => \\g,c => n.d ! u ! g ! c
} ;
below8 = Ign ;
n = plural
} ;
-- coercion of 1..999 -- coercion of 1..999
pot2as3 n = n ; pot2as3 n = n ;
-- -- m * 1000 -- m * 1000
-- --lin pot3 n = { pot3 n = {
-- -- s = \\c => n.s ! NCard ++ mkCard c "thousand" ; n = Pl} ; s = \\g,c => n.s ! g ! c ++ n.d ! thousand ! g ! c ;
-- -- m * 1000 + n d = table { thousand => \\g,c => n.s ! g ! c ++ n.d ! thousand ! g ! c ;
-- --lin pot3plus n m = { u => \\g,c => n.d ! u ! g ! c
-- -- s = \\c => n.s ! NCard ++ "thousand" ++ m.s ! c ; n = Pl} ; } ;
below8 = Ign ;
n = plural
} ;
-- d * 1000 + n
pot3plus d n = {
s = \\g,c => d.d ! thousand ! g ! c ++ "et" ++ n.s ! g ! c ;
d = n.d ;
below8 = Ign ;
n = plural
} ;
oper oper
n1 : Digit = lin Digit ( fullDigit "unus" "decem" "primus" "decimus" "centesimus" "millesimus" ) ; mkDigit : (ones, eleven, tens, hundreds, ord : Str) -> Str -> Below8 -> TDigit =
\ones, eleven, tens, hundreds, ord ->
mkDigit : (ones, tens, hundreds, ord : Str) -> TDigit =
\ones, tens, hundreds, ord ->
case <tens,hundreds> of { case <tens,hundreds> of {
<"decem",_> => fullDigit ones tens hundreds ord "decimus" "centesimus" ; <"decem",_> => fullDigit ones eleven tens hundreds ord "decimus" "centesimus" ;
<"viginti",_> => fullDigit ones tens hundreds ord "vicesimus" "ducentesimus" ; <"viginti",_> => fullDigit ones eleven tens hundreds ord "vicesimus" "ducentesimus" ;
<"triginta",_> => fullDigit ones tens hundreds ord "tricesimus" "trecentesimus" ; <"triginta",_> => fullDigit ones eleven tens hundreds ord "tricesimus" "trecentesimus" ;
<quadra + "ginta",quadringent + "i"> => fullDigit ones tens hundreds ord (quadra + "gesimus") (quadringent + "esimus") ; <quadra + "ginta",quadringent + "i"> => fullDigit ones eleven tens hundreds ord (quadra + "gesimus") (quadringent + "esimus") ;
_ => Predef.error "Invalid number" _ => Predef.error "Invalid number"
} ; } ;
fullDigit : (ones, tens, hundreds, ord1,ord10,ord100 : Str) -> TDigit = fullDigit : (ones, eleven, tens, hundreds, ord1,ord10,ord100, tenNext : Str) -> Below8 -> TDigit =
\ones, tens, hundreds, ord1,ord10,ord100 -> \ones, eleven, tens, hundreds, ord1,ord10,ord100,tenNext,b8 ->
{ s = table { one => cardFlex ones ; { s = table { one => cardFlex ones ;
eleven => cardFlex eleven ;
ten => cardFlex tens ; ten => cardFlex tens ;
hundred => cardFlex hundreds ; hundred => cardFlex hundreds ;
thousand => \\_,_ => nonExist ; thousand => cardFlex "milia" ;
ten_thousand => \\_,_ => nonExist ; ten_thousand => \\_,_ => nonExist ;
hundred_thousand => \\_,_ => nonExist } hundred_thousand => \\_,_ => nonExist
-- n = case ones of { "unus" => Sg ; _ => Pl } ; } ;
-- n = case ones of { "unus" => singular ; _ => plural } ;
-- ord = -- ord =
-- \\_,_ => [] ; -- \\_,_ => [] ;
-- -- table { one => (mkA ord1).s ! Posit; -- -- table { one => (mkA ord1).s ! Posit;
@@ -80,7 +154,11 @@ concrete NumeralLat of Numeral = CatLat ** open ResLat,ParadigmsLat,Prelude in {
-- -- thousand => \\_,_ => nonExist ; -- -- thousand => \\_,_ => nonExist ;
-- -- ten_thousand => \\_ => nonExist ; -- -- ten_thousand => \\_ => nonExist ;
-- -- hundred_thousand => \\_ => nonExist } ; -- -- hundred_thousand => \\_ => nonExist } ;
tenNext = tenNext ;
below8 = b8
} ; } ;
n1 : Digit = lin Digit ( fullDigit "unus" "decem" "undecim" "primus" "decimus" "centesimus" "millesimus" "viginti" Yes ) ;
-- numerals as sequences of digits -- numerals as sequences of digits
lincat lincat
@@ -94,30 +172,31 @@ concrete NumeralLat of Numeral = CatLat ** open ResLat,ParadigmsLat,Prelude in {
unit = inc i.unit unit = inc i.unit
} ; } ;
D_0 = mkDig "" "" "" "" "" "" ; D_0 = mkDig "" "" "" "" "" "" "" ;
D_1 = mkDig "I" "X" "C" "M" "(X)" "(C)" ; D_1 = mkDig "I" "XI" "X" "C" "M" "(X)" "(C)" ;
D_2 = mkDig "II" "XX" "CC" "MM" "(XX)" "(CC)" ; D_2 = mkDig "II" "XII" "XX" "CC" "MM" "(XX)" "(CC)" ;
D_3 = mkDig "III" "XXX" "CCC" "MMM" "(XXX)" "(CCC)" ; D_3 = mkDig "III" "XIII" "XXX" "CCC" "MMM" "(XXX)" "(CCC)" ;
D_4 = mkDig "IV" "XL" "CD" "(IV)" "(XL)" "(CD)" ; D_4 = mkDig "IV" "XIV" "XL" "CD" "(IV)" "(XL)" "(CD)" ;
D_5 = mkDig "V" "L" "D" "(V)" "(L)" "(D)" ; D_5 = mkDig "V" "XV" "L" "D" "(V)" "(L)" "(D)" ;
D_6 = mkDig "VI" "LX" "DC" "(VI)" "(LX)" "(DC)" ; D_6 = mkDig "VI" "XVI" "LX" "DC" "(VI)" "(LX)" "(DC)" ;
D_7 = mkDig "VII" "LXX" "DCC" "(VII)" "(LXX)" "(DCC)" ; D_7 = mkDig "VII" "XVII" "LXX" "DCC" "(VII)" "(LXX)" "(DCC)" ;
D_8 = mkDig "VIII" "LXXX" "DCCC" "(VIII)" "(LXXX)" "(DCCC)" ; D_8 = mkDig "VIII" "XVIII" "LXXX" "DCCC" "(VIII)" "(LXXX)" "(DCCC)" ;
D_9 = mkDig "IX" "XC" "CM" "(IX)" "(XC)" "(CM)" ; D_9 = mkDig "IX" "XIX" "XC" "CM" "(IX)" "(XC)" "(CM)" ;
oper oper
TDig = { TDig = {
s : Unit => Str s : Unit => Str
} ; } ;
mkDig : Str -> Str -> Str -> Str -> Str -> Str -> TDig = mkDig : Str -> Str -> Str -> Str -> Str -> Str -> Str -> TDig =
\one,ten,hundred,thousand,ten_thousand,hundred_thousand -> { \one,eleven,ten,hundred,thousand,ten_thousand,hundred_thousand -> {
s = table Unit [one;ten;hundred;thousand;ten_thousand;hundred_thousand] s = table Unit [one;eleven;ten;hundred;thousand;ten_thousand;hundred_thousand]
} ; } ;
inc : Unit -> Unit = \u -> inc : Unit -> Unit = \u ->
case u of { case u of {
one => ten ; one => ten ;
eleven => hundred ;
ten => hundred ; ten => hundred ;
hundred => thousand ; hundred => thousand ;
thousand => ten_thousand ; thousand => ten_thousand ;

View File

@@ -190,6 +190,50 @@ param
audaces audaces (audac + "ium") (audac + "ibus") audaces audaces (audac + "ium") (audac + "ibus")
g ; g ;
regAdj : Str -> Gender => Number => Case => Str = \s ->
case s of {
un + "us" => \\g,n,c => un + (regAdjSuffixes s g n c)
} ;
regAdjSuffixes : Str -> Gender -> Number -> Case -> Str = \str,g,n,c ->
case <g,n,c> of {
<Masc ,Sg,Nom> => "us" ;
<Masc ,Sg,Gen> => "i" ;
<Masc ,Sg,Dat> => "o" ;
<Masc ,Sg,Acc> => "um" ;
<Masc ,Sg,Abl> => "o" ;
<Masc ,Sg,Voc> => case str of { _ + "ius" => "i" ; _ => "e" } ;
<Masc ,Pl,Nom> => "i" ;
<Masc ,Pl,Gen> => "orum" ;
<Masc ,Pl,Dat> => "is" ;
<Masc ,Pl,Acc> => "os" ;
<Masc ,Pl,Abl> => "is" ;
<Masc ,Pl,Voc> => "i" ;
<Neutr,Sg,Nom> => "um" ;
<Neutr,Sg,Gen> => "i" ;
<Neutr,Sg,Dat> => "o" ;
<Neutr,Sg,Acc> => "um" ;
<Neutr,Sg,Abl> => "o" ;
<Neutr,Sg,Voc> => "um";
<Neutr,Pl,Nom> => "a" ;
<Neutr,Pl,Gen> => "orum" ;
<Neutr,Pl,Dat> => "is" ;
<Neutr,Pl,Acc> => "os" ;
<Neutr,Pl,Abl> => "is" ;
<Neutr,Pl,Voc> => "a" ;
<Fem ,Sg,Nom> => "a" ;
<Fem ,Sg,Gen> => "ae" ;
<Fem ,Sg,Dat> => "ae" ;
<Fem ,Sg,Acc> => "am" ;
<Fem ,Sg,Abl> => "a" ;
<Fem ,Sg,Voc> => "a";
<Fem ,Pl,Nom> => "ae" ;
<Fem ,Pl,Gen> => "arum" ;
<Fem ,Pl,Dat> => "is" ;
<Fem ,Pl,Acc> => "as" ;
<Fem ,Pl,Abl> => "is" ;
<Fem ,Pl,Voc> => "ae"
} ;
emptyAdj : Adjective = emptyAdj : Adjective =
{ s = \\_,_ => "" ; comp_adv = "" ; super_adv = "" ; adv = { s = \\_ => "" } } ; { s = \\_,_ => "" ; comp_adv = "" ; super_adv = "" ; adv = { s = \\_ => "" } } ;
@@ -1421,11 +1465,12 @@ oper
-- numerals -- numerals
param param
-- CardOrd = NCard | NOrd ; -- CardOrd = NCard | NOrd ;
Unit = one | ten | hundred | thousand | ten_thousand | hundred_thousand ; Unit = one | eleven | ten | hundred | thousand | ten_thousand | hundred_thousand ;
Below8 = Yes | No8 | No9 | Ign ;
oper oper
-- Numerals are by default cardinal numbers but have a field for ordinal numbers -- Numerals are by default cardinal numbers but have a field for ordinal numbers
TDigit : Type = { s : Unit => Gender => Case => Str } ; -- ord : Unit => Agr => Str } ; TDigit : Type = { s : Unit => Gender => Case => Str ; tenNext : Str ; below8 : Below8 } ; -- ord : Unit => Agr => Str } ;
Numeral : Type = { s : Gender => Case => Str ; n : Number } ; -- ord : Unit => Agr => Str } ; TNumeral : Type = { s : Gender => Case => Str ; d : Unit => Gender => Case => Str ; n : Number ; below8 : Below8 } ; -- ord : Unit => Agr => Str } ;
-- Inflection for cardinal numbers -- Inflection for cardinal numbers
cardFlex : Str -> Gender => Case => Str = cardFlex : Str -> Gender => Case => Str =
@@ -1442,9 +1487,9 @@ oper
<Neutr, Nom | Acc | Voc > => "tria" ; <_, Nom | Acc | Voc > => "tres" ; <Neutr, Nom | Acc | Voc > => "tria" ; <_, Nom | Acc | Voc > => "tres" ;
<_, Gen> => "trium" ; <_, Dat | Abl > => "tribus" <_, Gen> => "trium" ; <_, Dat | Abl > => "tribus"
} ; } ;
tre + "centi" => \\g,c => regAdj (tre + "centus") ! g ! Pl ! c ;
"milia" => table { "milia" => table {
Neutr => table Case [ "milia" ; "milia" ; "milium" ; "milibus" ; "milibus" ; "milia" ] ; _ => table Case [ "milia" ; "milia" ; "milium" ; "milibus" ; "milibus" ; "milia" ]
_ => \\_ => nonExist
} ; } ;
_ => \\_,_ => c _ => \\_,_ => c
} ; } ;