diff options
author | Sébastien Dailly <sebastien@chimrod.com> | 2021-09-03 17:37:03 +0200 |
---|---|---|
committer | Sébastien Dailly <sebastien@chimrod.com> | 2021-09-03 17:37:03 +0200 |
commit | 123c8bc693063cfc880709c7dfa700a177a66adb (patch) | |
tree | 5dd508c4ac5876fe80a661a4281b6fdaf3d064a9 /src/lib/process.ml | |
parent | 48dc04c3b9afe19207d15b873452129d9c2b3b4c (diff) |
Ended refactoring
Diffstat (limited to 'src/lib/process.ml')
-rw-r--r-- | src/lib/process.ml | 143 |
1 files changed, 70 insertions, 73 deletions
diff --git a/src/lib/process.ml b/src/lib/process.ml index 13a24a1..463701c 100644 --- a/src/lib/process.ml +++ b/src/lib/process.ml @@ -1,86 +1,83 @@ open StdLabels -module M(T:Sounds.Sig.T) = struct - - type voyel = T.t Modifiers.Sig.voyel - - type group = voyel * T.t Modifiers.Sig.consonants option - type modifier = T.t Modifiers.Sig.modifier - - (** Apply all the modifiers to the syllabic group in order to correct the - relation between the elements - - This is just a fold_left list, and the order matter : for example - nasalisation shall be applied after the S vocalisation - - *) - let apply_modifiers - : group * T.t option option -> modifier list -> group * T.t option option - = fun e m -> - List.fold_left m - ~init:e - ~f:(fun e f -> f (module T:Sounds.Sig.T with type t = T.t) 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 -> T.t list - = function - | [] -> acc - | hd::tl -> - let modifier = match tl with - | [] -> Modifiers.nasal::m - | _ -> (Modifiers.vocalize_s) :: (Modifiers.nasal) :: m in - let (voyel, consonants), ending_consonant = - 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 - | None -> voyel::acc +type voyel = Sounds.t Modifiers.Sig.voyel + +type group = voyel * Sounds.t Modifiers.Sig.consonants option +type modifier = Sounds.t Modifiers.Sig.modifier + +(** Apply all the modifiers to the syllabic group in order to correct the + relation between the elements + + This is just a fold_left list, and the order matter : for example + nasalisation shall be applied after the S vocalisation + +*) +let apply_modifiers + : group * Sounds.t option option -> modifier list -> group * Sounds.t option option + = fun e m -> + List.fold_left m + ~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 + | hd::tl -> + let modifier = match tl with + | [] -> Modifiers.nasal::m + | _ -> (Modifiers.vocalize_s) :: (Modifiers.nasal) :: m in + let (voyel, consonants), ending_consonant = + 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 + | None -> voyel::acc + | Some s -> + let default = voyel :: acc in + match s with + | None -> default | Some s -> - let default = voyel :: acc in - match s with - | None -> default - | Some s -> - voyel :: s::acc in + voyel :: s::acc in - match consonants with - | None -> _rebuild ~m:[] acc None tl - | Some {ending; opening; following} -> + match consonants with + | None -> _rebuild ~m:[] acc None tl + | Some {ending; opening; following} -> - let acc = match following with - | None -> acc - | Some s -> s::acc in + let acc = match following with + | None -> acc + | Some s -> s::acc in - match opening with - | [] ->_rebuild ~m:[] acc ending tl - | opening -> _rebuild ~m:[] (opening @ acc) ending tl + match opening with + | [] ->_rebuild ~m:[] acc ending tl + | opening -> _rebuild ~m:[] (opening @ acc) ending tl - (** Rebuild the list in the normal order +(** Rebuild the list in the normal order - The voyels have to be choosen, depending either they are followed by a - consonant or not + The voyels have to be choosen, depending either they are followed by a + consonant or not - Some consonants may be changed depending of the following voyel + Some consonants may be changed depending of the following voyel - The list has to be reversed + The list has to be reversed - and so one + and so one - *) - let rebuild - : T.t Modifiers.Sig.consonants option -> group list -> T.t list - = fun ending elems -> - let elems' = match ending with - | None -> elems - | Some _ -> ((T.none, T.none), ending)::elems in - _rebuild ~m:[Modifiers.mute_consonant] [] None elems' +*) +let rebuild + : Sounds.t Modifiers.Sig.consonants option -> group list -> Sounds.t list + = fun ending elems -> + let elems' = match ending with + | None -> elems + | Some _ -> ((Sounds.none, Sounds.none), ending)::elems in + _rebuild ~m:[Modifiers.mute_consonant] [] None elems' -end |