From 0ba049daed6e4b5d01f83d236f3178747bf849cb Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Sat, 4 Sep 2021 10:43:01 +0200 Subject: Transform the letter e into eu or E --- src/lib/modifiers/e.ml | 15 +++++++++++++++ src/lib/modifiers/modifiers.ml | 1 + src/lib/modifiers/mute.ml | 10 ++++------ src/lib/modifiers/nasal.ml | 19 +++++++++---------- src/lib/modifiers/sig.ml | 6 +++--- src/lib/modifiers/vocalize.ml | 18 ++++++++---------- src/lib/parser.mly | 34 +++++++++++++++++----------------- src/lib/process.ml | 27 ++++++++++++++------------- src/lib/prononciation.mly | 6 +++--- src/lib/repr/default.ml | 3 ++- src/lib/sounds/sig.ml | 3 ++- src/lib/sounds/sounds.ml | 15 ++++++++------- src/lib/sounds/sounds.mli | 4 ++-- src/lib/tokens.mly | 1 + src/test/test.ml | 9 ++++++--- 15 files changed, 95 insertions(+), 76 deletions(-) create mode 100644 src/lib/modifiers/e.ml diff --git a/src/lib/modifiers/e.ml b/src/lib/modifiers/e.ml new file mode 100644 index 0000000..8fd65bf --- /dev/null +++ b/src/lib/modifiers/e.ml @@ -0,0 +1,15 @@ +(** Transform the e into eu or E *) +let process + : 'a Sig.modifier + = fun init -> + let ((v2, c) , ending) = init in + + match ending with + | None when v2 = Sounds.schwa -> + (* If there is no more consononant in the syllabe, change the e + into eu, like in sera *) + ((Sounds.eu `Closed, c) , ending) + | Some _ when v2 = Sounds.schwa -> + (* If there is an ending consonant, change the e into E like essai *) + ((Sounds.e `Opened, c) , ending) + | _ -> init diff --git a/src/lib/modifiers/modifiers.ml b/src/lib/modifiers/modifiers.ml index 89e9485..3a9ecd6 100644 --- a/src/lib/modifiers/modifiers.ml +++ b/src/lib/modifiers/modifiers.ml @@ -3,3 +3,4 @@ module Sig = Sig let nasal = Nasal.process let vocalize_s = Vocalize.process let mute_consonant = Mute.process +let e = E.process diff --git a/src/lib/modifiers/mute.ml b/src/lib/modifiers/mute.ml index 331ed1a..e23965f 100644 --- a/src/lib/modifiers/mute.ml +++ b/src/lib/modifiers/mute.ml @@ -1,18 +1,16 @@ open StdLabels -module T = Sounds - (** Mute the last consonant if there is no voyel in the syllabus. This modifier is only applied in the first step, and not repeated anymore. *)let process : 'a Sig.modifier = fun init -> - let (((v1, v2), c) , ending) = init in - let is_voyel = T.is_voyel v1 && T.is_voyel v2 in + let ((v, c) , ending) = init in + let is_voyel = Sounds.is_voyel v in match is_voyel, c with | false, Some c -> - let c = { c with Sig.opening = List.map ~f:T.muted c.Sig.opening } in - (((v1, v2), Some c) , ending) + let c = { c with Sig.opening = List.map ~f:Sounds.muted c.Sig.opening } in + ((v, Some c) , ending) | _ -> init diff --git a/src/lib/modifiers/nasal.ml b/src/lib/modifiers/nasal.ml index 57a3235..cc29efc 100644 --- a/src/lib/modifiers/nasal.ml +++ b/src/lib/modifiers/nasal.ml @@ -1,14 +1,13 @@ -module T = Sounds (* Remove the ending consonant, and transform the voyel into the nasal form *) let transform : Sounds.t Sig.consonants option -> Sounds.t Sig.t -> Sounds.t Sig.t = fun c init -> - let (((v1, v2), _) , _) = init in + let ((v, _) , _) = init in - begin match T.nasal v1, T.nasal v2 with - | Some t1, Some t2 -> - ( ( (t1, t2) + begin match Sounds.nasal v with + | Some t -> + ( ( t , c ) , None ) | _ -> init @@ -22,14 +21,14 @@ let transform let process : 'a Sig.modifier = fun init -> - let (((v1, v2), c) , ending) = init in + let ((v, c) , ending) = init in let ending = Option.bind ending (fun x -> x) in let opening = Option.map (fun v -> v.Sig.opening) c in - let is_voyel = T.is_voyel v1 && T.is_voyel v2 in + let is_voyel = Sounds.is_voyel v in match ending, is_voyel, opening with - | Some ending, _, _ when T.is_nasal ending -> + | Some ending, _, _ when Sounds.is_nasal ending -> transform c init - | None, false, Some (opening::tl) when T.is_nasal opening -> + | None, false, Some (opening::tl) when Sounds.is_nasal opening -> (* If there is no voyel here, transform the opening consonant as an ending consonant for the next syllabus *) let c = Option.map @@ -38,7 +37,7 @@ let process Sig.opening = tl ; Sig.ending = (Some (Some opening)) }) c in - ( ( (v1, v2) + ( ( v , c ) , None ) | _ -> diff --git a/src/lib/modifiers/sig.ml b/src/lib/modifiers/sig.ml index bcc4af2..5f82620 100644 --- a/src/lib/modifiers/sig.ml +++ b/src/lib/modifiers/sig.ml @@ -1,12 +1,12 @@ -type 'a voyel = ('a * 'a) +type voyel = Sounds.t type 'a consonants = { ending : 'a option option ; opening : 'a list ; following : 'a option } -type 'a group = 'a voyel * 'a consonants option +type 'a group = voyel * 'a consonants option type 'a t = 'a group * 'a option option -type 'a modifier = 'a t -> 'a t +type 'a modifier = Sounds.t t -> Sounds.t t diff --git a/src/lib/modifiers/vocalize.ml b/src/lib/modifiers/vocalize.ml index 1014642..068279d 100644 --- a/src/lib/modifiers/vocalize.ml +++ b/src/lib/modifiers/vocalize.ml @@ -1,25 +1,23 @@ -module T = Sounds - (** Transform the S into Z if the S is the opening consonant and there is no ending consonant before *) let process : 'a Sig.modifier = fun init -> - let (((v1, v2), c) , ending) = init in + let ((v, c) , ending) = init in match c with | None -> init | Some op -> (* The voyel may be none in case of ending word. In such case, we shall not transform the S into Z *) - let is_voyel = T.is_voyel v1 && T.is_voyel v2 in + let is_voyel = Sounds.is_voyel v in match is_voyel, op.Sig.opening, op.Sig.ending with - | true, hd::[], None when hd = T.sz -> - let c = Some { op with opening = [T.z] } in - (((v1, v2), c) , ending) - | true, hd::n::[], None when hd = T.sz && T.is_voyel n-> + | true, hd::[], None when hd = Sounds.sz -> + let c = Some { op with opening = [Sounds.z] } in + ((v, c) , ending) + | true, hd::n::[], None when hd = Sounds.sz && Sounds.is_voyel n-> (* The s is followed by a semi-voyel *) - let c = Some { op with opening = [T.z; n] } in - (((v1, v2), c) , ending) + let c = Some { op with opening = [Sounds.z; n] } in + ((v, c) , ending) | _ -> init diff --git a/src/lib/parser.mly b/src/lib/parser.mly index a207329..e5e6773 100644 --- a/src/lib/parser.mly +++ b/src/lib/parser.mly @@ -12,7 +12,6 @@ See [1] for the theory behind the analysis %{ - module P = Process %} %start main @@ -77,24 +76,25 @@ opening_consonant: (* Each voyel as two associated sounds, depending there is a followng sound or not *) voyels: - | A { Sounds.a , Sounds.a } - | A I { Sounds.voyel_ai , Sounds.voyel_ai } - | E I { Sounds.e `Opened , Sounds.e `Opened } - | I { Sounds.i , Sounds.i } - | E { Sounds.e `Opened , Sounds.schwa () } - | E_ACUTE E? { Sounds.e `Closed , Sounds.e `Closed } - | E_AGRAVE { Sounds.e `Opened , Sounds.e `Opened } - | E U { Sounds.eu , Sounds.eu } - | O { Sounds.o , Sounds.o } - | U { Sounds.voyel_y , Sounds.voyel_y } - | OU { Sounds.voyel_u , Sounds.voyel_u } - | W A { Sounds.diphtongue Sounds.semi_voyel_w Sounds.a, Sounds.diphtongue Sounds.semi_voyel_w Sounds.a} - | W I { Sounds.diphtongue Sounds.semi_voyel_w Sounds.i, Sounds.diphtongue Sounds.semi_voyel_w Sounds.i} - | I E { Sounds.diphtongue Sounds.i (Sounds.e `Opened), Sounds.diphtongue Sounds.i (Sounds.e `Opened)} + | A { Sounds.a } + | A I { Sounds.voyel_ai } + | E I { Sounds.e `Opened } + | I { Sounds.i } + | E { Sounds.schwa } + | E_ACUTE E? { Sounds.e `Closed } + | E_AGRAVE { Sounds.e `Opened } + | E U { Sounds.eu `Opened } + | O { Sounds.o } + | U { Sounds.voyel_y } + | OU { Sounds.voyel_u } + | W A { Sounds.diphtongue Sounds.semi_voyel_w Sounds.a} + | W I { Sounds.diphtongue Sounds.semi_voyel_w Sounds.i} + | I E { Sounds.diphtongue Sounds.i (Sounds.e `Opened) } ending_consonant: + | Nothing { Some (Sounds.none) } | B { Some (Sounds.b ) } - | T { None } + | T { Some (Sounds.t )} | K { Some (Sounds.k)} | liquid { Some $1 } | nasal { Some $1 } @@ -145,7 +145,7 @@ syllables: word: - | Sep? syllables consonant_group? EOL { P.rebuild $3 $2 } + | Sep? syllables consonant_group? EOL { Process.rebuild $3 $2 } main: | word { $1 } diff --git a/src/lib/process.ml b/src/lib/process.ml index 463701c..f85853f 100644 --- a/src/lib/process.ml +++ b/src/lib/process.ml @@ -1,6 +1,6 @@ open StdLabels -type voyel = Sounds.t Modifiers.Sig.voyel +type voyel = Sounds.t type group = voyel * Sounds.t Modifiers.Sig.consonants option type modifier = Sounds.t Modifiers.Sig.modifier @@ -19,13 +19,6 @@ let apply_modifiers ~init:e ~f:(fun e f -> f e) -let change_voyel - = fun init -> - let (((v1, v2), _) , ending) = init in - match ending with - | None -> v2 - | Some _ -> v1 - let rec _rebuild ~(m:modifier list) acc ending_consonant : group list -> Sounds.t list = function | [] -> acc @@ -37,7 +30,6 @@ let rec _rebuild ~(m:modifier list) acc ending_consonant : group list -> Sounds. apply_modifiers (hd, ending_consonant) modifier in - let voyel = change_voyel ((voyel, consonants), ending_consonant) in (* Add the last consonant and the voyel *) let acc = match ending_consonant with @@ -49,8 +41,17 @@ let rec _rebuild ~(m:modifier list) acc ending_consonant : group list -> Sounds. | Some s -> voyel :: s::acc in + (* Apply the modifiers to the previous syllabus. + + Only transform the e into eu / E if there is previous syllabus with + voyel. *) + let modifiers = if voyel = Sounds.none then + [] + else + [Modifiers.e] in + match consonants with - | None -> _rebuild ~m:[] acc None tl + | None -> _rebuild ~m:modifiers acc None tl | Some {ending; opening; following} -> let acc = match following with @@ -58,8 +59,8 @@ let rec _rebuild ~(m:modifier list) acc ending_consonant : group list -> Sounds. | Some s -> s::acc in match opening with - | [] ->_rebuild ~m:[] acc ending tl - | opening -> _rebuild ~m:[] (opening @ acc) ending tl + | [] ->_rebuild ~m:modifiers acc ending tl + | opening -> _rebuild ~m:modifiers (opening @ acc) ending tl (** Rebuild the list in the normal order @@ -78,6 +79,6 @@ let rebuild = fun ending elems -> let elems' = match ending with | None -> elems - | Some _ -> ((Sounds.none, Sounds.none), ending)::elems in + | Some _ -> (Sounds.none, ending)::elems in _rebuild ~m:[Modifiers.mute_consonant] [] None elems' diff --git a/src/lib/prononciation.mly b/src/lib/prononciation.mly index 7162b09..fdb1298 100644 --- a/src/lib/prononciation.mly +++ b/src/lib/prononciation.mly @@ -98,8 +98,7 @@ letters | J { J :: [] } | K { K :: [] } - | E L { letter_e $1 :: L :: [] } - | E L L { E_AGRAVE :: L :: [] } + | L L { Nothing :: L :: [] } | I L { I :: L :: [] } | I L L { I :: Y :: [] } | L { L :: [] } @@ -118,9 +117,10 @@ letters | R { R :: [] } | S { SZ :: [] } - | S S { S :: [] } + | S S { Nothing :: S :: [] } | S H { X :: [] } | T { T :: [] } + | T T { Nothing :: T :: [] } | V { V :: [] } | W { W :: [] } diff --git a/src/lib/repr/default.ml b/src/lib/repr/default.ml index e8cc091..4110679 100644 --- a/src/lib/repr/default.ml +++ b/src/lib/repr/default.ml @@ -11,7 +11,8 @@ and e_opened = "E" and e_closed = "e" and schwa = "°" -and eu = "9" +and eu_opened = "9" +and eu_closed = "2" and o = "o" and o_nasal = "§" diff --git a/src/lib/sounds/sig.ml b/src/lib/sounds/sig.ml index 512abdc..5322a12 100644 --- a/src/lib/sounds/sig.ml +++ b/src/lib/sounds/sig.ml @@ -10,7 +10,8 @@ module type REPR = sig val e_closed : t val schwa : t - val eu : t + val eu_closed : t + val eu_opened : t val o : t val o_nasal : t diff --git a/src/lib/sounds/sounds.ml b/src/lib/sounds/sounds.ml index a8c9ce9..afaf110 100644 --- a/src/lib/sounds/sounds.ml +++ b/src/lib/sounds/sounds.ml @@ -17,7 +17,8 @@ type code = | Voyel_U (* OU like in Ouvrir *) | Voyel_Y (* U like in Unique *) | Voyel_AI - | Voyel_EU + | Voyel_EU_Closed + | Voyel_EU_Opened | SemiVoyel_W | SemiVoyel_Y | Consonant_P @@ -82,13 +83,12 @@ let e = function | `Closed -> { voyel with code = E_Closed } | `Opened -> { voyel with code = E_Opened } -let eu = - { voyel with - code = Voyel_EU - } +let eu = function + | `Closed -> { voyel with code = Voyel_EU_Closed } + | `Opened -> { voyel with code = Voyel_EU_Opened } -let schwa () = +let schwa = { voyel with code = Voyel_E } @@ -264,7 +264,8 @@ let repr | Voyel_U, _ -> Repr.u | Voyel_Y, false -> Repr.y | Voyel_Y, true -> Repr.y_nasal - | Voyel_EU, _ -> Repr.eu + | Voyel_EU_Closed, _ -> Repr.eu_closed + | Voyel_EU_Opened, _ -> Repr.eu_opened | SemiVoyel_W, _ -> Repr.semi_voyel_w | SemiVoyel_Y, _ -> Repr.semi_voyel_y diff --git a/src/lib/sounds/sounds.mli b/src/lib/sounds/sounds.mli index dcb5e8d..2fae17f 100644 --- a/src/lib/sounds/sounds.mli +++ b/src/lib/sounds/sounds.mli @@ -5,10 +5,10 @@ val muted : t -> t val a : t val e : [`Closed | `Opened] -> t -val eu : t +val eu : [`Closed | `Opened] -> t val o : t -val schwa : unit -> t +val schwa: t (** This is an empty sound. diff --git a/src/lib/tokens.mly b/src/lib/tokens.mly index 0eb442e..ea1493a 100644 --- a/src/lib/tokens.mly +++ b/src/lib/tokens.mly @@ -1,5 +1,6 @@ %token Sep +%token Nothing %token A %token B %token C diff --git a/src/test/test.ml b/src/test/test.ml index 6162db0..497e150 100644 --- a/src/test/test.ml +++ b/src/test/test.ml @@ -44,7 +44,7 @@ let tests = ; "abaissait", "abEsE(t)" ; "abaissant", "abEs@(t)" ; "abaissées", "abEse(s)" - ; "abaissera", "abEs°Ra" + ; "abaissera", "abEs2Ra" ; "achat", "aSa(t)" ; "aiment", "Em°(t)" ; "anniversaire", "anivERsER°" @@ -54,8 +54,10 @@ let tests = ; "as", "a(s)" ; "asia", "azia" ; "astiqué", "astike" + ; "atmosphère", "atmosfER°" + ; "automne", "ot§n°" ; "autruche", "otRyS°" - ; "besoin", "b°zw5" + ; "besoin", "b2zw5" ; "beaumont", "bom§(t)" ; "bisoux", "bizu(s)" ; "casait", "kazE(t)" @@ -66,9 +68,10 @@ let tests = ; "chipant", "Sip@(t)" ; "co|incidant", "ko5sid@(t)" ; "croire", "kR[wa]R°" - ; "demeure", "d2m9r°" + ; "demeure", "d2m9R°" ; "ébrouas", "ebRua(s)" ; "em|magasinais","@magazinE(s)" + ; "essai", "EsE" ; "extra", "EkstRa" ; "famille", "famij°" ; "final", "finaL" -- cgit v1.2.3