summaryrefslogtreecommitdiff
path: root/src/lib/process.ml
diff options
context:
space:
mode:
authorSébastien Dailly <sebastien@chimrod.com>2021-08-27 13:15:35 +0200
committerSébastien Dailly <sebastien@chimrod.com>2021-08-27 13:15:35 +0200
commit65d5990607e9542aa847ec7cb684afd3ffdedb8f (patch)
tree47a26877c88e303915bc9545a22b004d8dd8089b /src/lib/process.ml
parentdf92da631e9a10a099a72ba846f90adf99d180df (diff)
Update
Diffstat (limited to 'src/lib/process.ml')
-rw-r--r--src/lib/process.ml50
1 files changed, 41 insertions, 9 deletions
diff --git a/src/lib/process.ml b/src/lib/process.ml
index 10b2945..01c6d4a 100644
--- a/src/lib/process.ml
+++ b/src/lib/process.ml
@@ -48,6 +48,8 @@ module M(T:Sounds.T) = struct
, c )
, None )
+ (** Transform the S into Z if the S is the opening consonant and
+ there is no ending consonant before *)
let vocalize_s
: modifier
= fun init ->
@@ -55,33 +57,60 @@ module M(T:Sounds.T) = struct
match c with
| None -> init
- | Some op -> match op.opening, op.ending with
- | hd::[], None when T.code hd = T.SZ ->
+ | Some op ->
+ (* The voyel may be none in case of ending word. In such case, we shall
+ not trnasform the S into Z *)
+ let is_voyel = T.is_voyel v1 && T.is_voyel v2 in
+ match is_voyel, op.opening, op.ending with
+ | true, hd::[], None when T.code hd = T.SZ ->
let c = Some { op with opening = [T.z ()] } in
(((v1, v2), c) , ending)
| _ -> init
+ (** 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 mute_consonant
+ : modifier
+ = fun init ->
+ let (((v1, v2), c) , ending) = init in
+ let is_voyel = T.is_voyel v1 && T.is_voyel v2 in
+ match is_voyel, c with
+ | false, Some c ->
+ let c = { c with opening = List.map ~f:T.muted c.opening } in
+ (((v1, v2), Some c) , ending)
+ | _ -> init
+
+ 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_ = vocalize_s :: nasal :: m in
+ let modifier = vocalize_s :: nasal :: m in
let (voyel, consonants), ending_consonant =
apply_modifiers
(hd, ending_consonant)
- modifier_ in
+ modifier in
+ let voyel = change_voyel ((voyel, consonants), ending_consonant) in
(* Add the last consonant and the voyel *)
let m, acc = match ending_consonant with
- | None -> modifier_, (snd voyel)::acc
+ | None -> modifier, voyel::acc
| Some s ->
- let default = modifier_, (fst voyel) :: acc in
+ let default = modifier, voyel :: acc in
match s with
| None -> default
| Some s ->
- modifier_, (fst voyel) :: s::acc in
+ modifier, voyel :: s::acc in
match consonants with
| None -> _rebuild ~m acc None tl
@@ -108,8 +137,11 @@ module M(T:Sounds.T) = struct
*)
let rebuild
- : T.t option option -> group list -> T.t list
+ : consonants option -> group list -> T.t list
= fun ending elems ->
- _rebuild ~m:[] [] ending elems
+ let elems' = match ending with
+ | None -> elems
+ | Some _ -> ((T.none, T.none), ending)::elems in
+ _rebuild ~m:[mute_consonant] [] None elems'
end