summaryrefslogtreecommitdiff
path: root/sorsyl/test/test_syllabifier.ml
diff options
context:
space:
mode:
Diffstat (limited to 'sorsyl/test/test_syllabifier.ml')
-rw-r--r--sorsyl/test/test_syllabifier.ml49
1 files changed, 49 insertions, 0 deletions
diff --git a/sorsyl/test/test_syllabifier.ml b/sorsyl/test/test_syllabifier.ml
new file mode 100644
index 0000000..08f3d0d
--- /dev/null
+++ b/sorsyl/test/test_syllabifier.ml
@@ -0,0 +1,49 @@
+open Printf
+open Sorsyl
+
+let test_syllabifier () =
+ (* Create sonority calculator *)
+ let data_dir =
+ if Sys.file_exists "./data" then "./data"
+ else if Sys.file_exists "../data" then "../data"
+ else if Sys.file_exists "../../../data" then "../../../data"
+ else (
+ Printf.eprintf "Current directory: %s\n" (Sys.getcwd ());
+ failwith "Cannot find data directory")
+ in
+ let sonority = Sonority.create data_dir in
+
+ (* Test basic syllabification *)
+ let test_word word ipa lang =
+ printf "\nTesting: %s [%s] (%s)\n" word ipa lang;
+ let result = Syllabifier.syllabify ~sonority ~ipa ~word ~lang in
+ printf "Clean IPA: %s\n" result.clean_ipa;
+ printf "Syllables: %d\n" (List.length result.syllables);
+ Base.List.iteri result.syllables ~f:(fun i syl ->
+ printf "\nSyllable %d:\n" (i + 1);
+ printf " All: %s\n" (Syllable.all syl);
+ printf " Onset: %s\n" syl.onset;
+ printf " Nucleus: %s\n" syl.nucleus;
+ printf " Coda: %s\n" syl.coda;
+ printf " Tone: %s\n" syl.tone;
+ printf " Stressed: %b\n" syl.stressed)
+ in
+
+ (* Test cases *)
+ test_word "hello" "hɛˈloʊ" "en";
+ test_word "computer" "kəmˈpjuːtər" "en";
+ test_word "language" "ˈlæŋɡwɪdʒ" "en";
+ test_word "syllable" "ˈsɪləbəl" "en";
+
+ (* Test with tones (if supported) *)
+ test_word "ma" "ma˧" "zh";
+
+ (* Test pretty printing *)
+ printf "\n\nPretty print example:\n";
+ let result =
+ Syllabifier.syllabify ~sonority ~ipa:"ˈsɪləbəl" ~word:"syllable" ~lang:"en"
+ in
+ Base.List.iter result.syllables ~f:(fun syl ->
+ printf "%s\n" (Syllable.pretty_print syl))
+
+let () = test_syllabifier ()