summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSébastien Dailly <sebastien@chimrod.com>2021-09-01 18:33:26 +0200
committerSébastien Dailly <sebastien@chimrod.com>2021-09-01 18:33:26 +0200
commit12ccc075d724f9985be488b162b243f46dff871a (patch)
treeae788a28754397db7ad009c011b9c02818cc555d
parent843230359b2157212c4e93b51994f0fde90d808b (diff)
Made all tests pass
-rw-r--r--src/lib/accent.ml4
-rw-r--r--src/lib/lexer.mll16
-rw-r--r--src/lib/modifiers/vocalize.ml7
-rw-r--r--src/lib/parser.mly4
-rw-r--r--src/lib/process.ml5
-rw-r--r--src/lib/prononciation.mly28
-rw-r--r--src/lib/sounds/sounds.ml46
-rw-r--r--src/test/test.ml8
8 files changed, 84 insertions, 34 deletions
diff --git a/src/lib/accent.ml b/src/lib/accent.ml
new file mode 100644
index 0000000..a8bf4d2
--- /dev/null
+++ b/src/lib/accent.ml
@@ -0,0 +1,4 @@
+type t =
+ | NONE
+ | ACUTE
+ | AGRAVE
diff --git a/src/lib/lexer.mll b/src/lib/lexer.mll
index 27a7a8f..a5cee10 100644
--- a/src/lib/lexer.mll
+++ b/src/lib/lexer.mll
@@ -14,11 +14,11 @@ rule letter = parse
| 'b' { B }
| 'c' { C }
| 'd' { D }
-| 'e' { E }
-| '\232' { E_ACUTE }
-| "è" { E_AGRAVE }
-| '\233' { E_ACUTE }
-| "é" { E_ACUTE }
+| 'e' { E Accent.NONE }
+| '\232' { E Accent.ACUTE }
+| "è" { E Accent.AGRAVE }
+| '\233' { E Accent.ACUTE }
+| "é" { E Accent.ACUTE }
| 'f' { F }
| 'g' { G }
| 'h' { H }
@@ -45,10 +45,10 @@ rule letter = parse
| 'z' { Z }
| ' ' { Space }
| ending { EOL }
-| "eaux" ending { AUX_ }
-| "aux" ending { AUX_ }
-| "ient" ending { IENT_ }
+| "el" ending { EL_ }
| "ent" ending { ENT_ }
+| "ient" ending { IENT_ }
+| "x" ending { X_ }
(* This rule looks for a single line, terminated with '\n' or eof.
It returns a pair of an optional string (the line that was found)
diff --git a/src/lib/modifiers/vocalize.ml b/src/lib/modifiers/vocalize.ml
index 6857718..dab36ed 100644
--- a/src/lib/modifiers/vocalize.ml
+++ b/src/lib/modifiers/vocalize.ml
@@ -10,10 +10,15 @@ let process
| None -> init
| Some op ->
(* The voyel may be none in case of ending word. In such case, we shall
- not trnasform the S into Z *)
+ not transform the S into Z *)
let is_voyel = T.is_voyel v1 && T.is_voyel v2 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->
+ (* The s is followed by a semi-voyel *)
+ let c = Some { op with opening = [T.z; n] } in
+ (((v1, v2), c) , ending)
| _ -> init
diff --git a/src/lib/parser.mly b/src/lib/parser.mly
index 92a8750..20a9a84 100644
--- a/src/lib/parser.mly
+++ b/src/lib/parser.mly
@@ -47,6 +47,7 @@ obstruent:
liquid:
| L { T.l }
+ | L L { T.l }
| R { T.r }
nasal:
@@ -78,7 +79,8 @@ opening_consonant:
not *)
voyels:
| A { T.a , T.a }
- | A I { T.e `Opened , T.e `Opened }
+ | A I { T.voyel_ai , T.voyel_ai }
+ | E I { T.e `Opened , T.e `Opened }
| I { T.i , T.i }
| E { T.e `Opened , T.schwa () }
| E_ACUTE E? { T.e `Closed , T.e `Closed }
diff --git a/src/lib/process.ml b/src/lib/process.ml
index 8c463b5..fa0d056 100644
--- a/src/lib/process.ml
+++ b/src/lib/process.ml
@@ -32,7 +32,10 @@ module M(T:Sounds.T) = struct
= function
| [] -> acc
| hd::tl ->
- let modifier = (Modifiers.vocalize_s) :: (Modifiers.nasal) :: m in
+
+ 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)
diff --git a/src/lib/prononciation.mly b/src/lib/prononciation.mly
index bd97632..63bf2a1 100644
--- a/src/lib/prononciation.mly
+++ b/src/lib/prononciation.mly
@@ -8,10 +8,17 @@
*)
open Tokens
+
+ let letter_e = function
+ | Accent.NONE -> Tokens.E
+ | Accent.AGRAVE -> Tokens.E_AGRAVE
+ | Accent.ACUTE -> Tokens.E_ACUTE
+
%}
-%token AUX_
+%token X_
%token ENT_
+%token EL_
%token IENT_
%token Sep
@@ -19,7 +26,7 @@
%token B
%token C
%token D
-%token E
+%token<Accent.t> E
%token E_ACUTE
%token E_AGRAVE
%token F
@@ -32,12 +39,10 @@
%token M
%token N
%token O
-%token OU
%token Q
%token P
%token R
%token S
-%token SZ
%token T
%token U
%token V
@@ -58,15 +63,13 @@
voyel:
| A { A }
- | E { E }
+ | E { letter_e $1 }
| I { I }
| O { O }
| A U { O }
| E A U { O }
| O U { OU }
| U { U }
- | E_ACUTE { E_ACUTE }
- | E_AGRAVE { E_AGRAVE }
letters:
@@ -78,7 +81,7 @@ letters:
| C { K :: [] }
| C H { X :: [] }
| C I { S :: I :: [] }
- | C E { S :: E :: [] }
+ | C E { S :: letter_e $2 :: [] }
| C U { K :: U :: [] }
| C U I { K :: I :: [] }
| C U E { K :: E :: [] }
@@ -87,15 +90,15 @@ letters:
| F { F :: [] }
| G { G :: [] }
| G I { J :: I :: [] }
- | G E { J :: E :: [] }
+ | G E { J :: letter_e $2 :: [] }
| G U { G :: U :: [] }
| G U I { G :: I :: [] }
- | G U E { G :: E :: [] }
+ | G U E { G :: letter_e $3 :: [] }
| H { Sep :: [] }
| J { J :: [] }
| K { K :: [] }
- | E L { E :: L :: [] }
+ | E L { letter_e $1 :: L :: [] }
| E L L { E_AGRAVE :: L :: [] }
| I L { I :: L :: [] }
| I L L { I :: Y :: [] }
@@ -128,9 +131,10 @@ letters:
| Z { Z :: [] }
ending:
- | AUX_ { O::S::EOL::[]}
+ | X_ { S::EOL::[]}
| IENT_ { I::T::EOL::[]}
| ENT_ { E::T::EOL::[]}
+ | EL_ { E_AGRAVE::L::EOL::[]}
| EOL { EOL::[] }
main:
diff --git a/src/lib/sounds/sounds.ml b/src/lib/sounds/sounds.ml
index f2a9d86..9892ace 100644
--- a/src/lib/sounds/sounds.ml
+++ b/src/lib/sounds/sounds.ml
@@ -19,12 +19,21 @@ module type T = sig
When nazalized, the voyel become [in] like in "ainsi" *)
val i : t
+ (** This is the sound present with letter [ai].
+ It is the e like in "semaine".
+
+ When nazalized, the voyel become [in]
+
+
+ *)
+ val voyel_ai : t
+
(** This is the sound ou like in "ouvrier"
When nazalized, the voyel does not change *)
val voyel_u : t
(** This is the sound u like in "unis"
- When nazalized, the voyel becom [un] like in "brun" *)
+ When nazalized, the voyel become [un] like in "brun" *)
val voyel_y : t
(** Create a diphtongue from a semi-voyel and a voyel *)
@@ -58,12 +67,15 @@ module type T = sig
val is_voyel : t -> bool
val is_nasal : t -> bool
+ val repr : t -> string
+
end
module T = struct
type kind =
| None
| Voyel
+ | SemiVoyel
type code =
| None
@@ -74,6 +86,7 @@ module T = struct
| Voyel_O
| Voyel_U (* OU like in Ouvrir *)
| Voyel_Y (* U like in Unique *)
+ | Voyel_AI
| SemiVoyel_W
| SemiVoyel_Y
| Consonant_P
@@ -134,7 +147,7 @@ module Repr = struct
and v = "v"
and ch = "S"
- and j = "j"
+ and j = "Z"
and s = "s"
and z = "z"
@@ -153,7 +166,9 @@ module S = struct
include T
- let is_voyel t = t.kind = Voyel
+ let is_voyel t =
+ t.kind = Voyel
+ || t.kind = SemiVoyel
let is_nasal t = t.nasal
@@ -182,6 +197,12 @@ module S = struct
; repr = Repr.a
}
+ let voyel_ai =
+ { voyel with
+ code = Voyel_AI
+ ; repr = "E"
+ }
+
let e = function
| `Closed -> { voyel with repr = "e" ; code = Voyel_E }
| `Opened -> { voyel with repr = "E" ; code = Voyel_E }
@@ -309,22 +330,25 @@ module S = struct
let semi_voyel_w =
{ none with
- repr = Repr.semi_voyel_w
+ kind = SemiVoyel
+ ; repr = Repr.semi_voyel_w
; code = SemiVoyel_W}
let semi_voyel_y =
{ none with
- repr = Repr.semi_voyel_y
+ kind = SemiVoyel
+ ; repr = Repr.semi_voyel_y
; code = SemiVoyel_Y}
let nasal t =
match t.code with
- | Voyel_E -> Some { t with repr = Repr.a_nasal ; nasal = true }
- | Voyel_A -> Some { t with repr = Repr.a_nasal ; nasal = true }
- | Voyel_O -> Some { t with repr = Repr.o_nasal ; nasal = true }
- | Voyel_I -> Some { t with repr = Repr.i_nasal ; nasal = true }
- | Voyel_Y -> Some { t with repr = Repr.y_nasal ; nasal = true }
+ | Voyel_E -> Some { t with repr = Repr.a_nasal ; nasal = true }
+ | Voyel_A -> Some { t with repr = Repr.a_nasal ; nasal = true }
+ | Voyel_AI -> Some { t with repr = Repr.i_nasal ; nasal = true }
+ | Voyel_O -> Some { t with repr = Repr.o_nasal ; nasal = true }
+ | Voyel_I -> Some { t with repr = Repr.i_nasal ; nasal = true }
+ | Voyel_Y -> Some { t with repr = Repr.y_nasal ; nasal = true }
| Diphtonge (s1, s2) ->
begin match s1.code, s2.code with
| (SemiVoyel_W, Voyel_I) ->
@@ -361,6 +385,8 @@ module S = struct
| Voyel_A, false -> Repr.a
| Voyel_A, true -> Repr.a_nasal
+ | Voyel_AI, false -> "E"
+ | Voyel_AI, true -> Repr.i_nasal
| Voyel_E, _ -> ""
| Voyel_I, false -> Repr.i
| Voyel_I, true -> Repr.i_nasal
diff --git a/src/test/test.ml b/src/test/test.ml
index a3f4598..c7f45d5 100644
--- a/src/test/test.ml
+++ b/src/test/test.ml
@@ -54,8 +54,10 @@ let tests =
; "asia", "azia"
; "astiqué", "astike"
; "autruche", "otRyS°"
+ ; "besoin", "b°zw5"
; "casait", "kazE(t)"
; "cassait", "kasE(t)"
+ ; "célibat", "seLiba(t)"
; "chanci", "S@si"
; "chat", "Sa(t)"
; "chipant", "Sip@(t)"
@@ -66,7 +68,10 @@ let tests =
; "loin", "Lw5"
; "groin", "gR[w5]"
; "hirondelle", "iR§dEL°"
- ; "joues", "ju°(s)"
+ ; "joues", "Zu°(s)"
+ ; "libellule", "LibELyL°"
+ ; "main", "m5"
+ ; "neige", "nEZ°"
; "pacha", "paSa"
; "péché", "peSe"
; "persai", "pERsE"
@@ -74,6 +79,7 @@ let tests =
; "plat", "pLa(t)"
; "platte", "pLat°"
; "soin", "sw5"
+ ; "souris", "suRi(s)"
; "toiture", "twatyR°"
; "trois", "tR[wa](s)"
; "vil|le", "viLL°"