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 ()