-
Notifications
You must be signed in to change notification settings - Fork 0
/
UkrainianSpeech.hs
2615 lines (2533 loc) · 135 KB
/
UkrainianSpeech.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{-
MIT License
Copyright (c) 2019 OleksandrZhabenko
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-}
module Main (
-- * Main Function
main,
-- * Functions used in the main function itself
createSoundsForSyllable, endS, combineSoundsLs3, words2,
-- * Functions used for preprocessing
concatPauseRecords, assimilationFirst, isSpecialNonSpace, separatePunct, softAssociate, ukrainianLast2, ukrainianJottedLast, ukrainianJotted1, changeAssimilative,
separatePunct0, ukrainianToMoreSounding, changeH2X, change2BS, firstChange, readEnglishWithUkrainian, numberSounds, isFiltered,
-- * Functions used to create syllables or special symbol sequences
pFunctionP, pFunctionP0, hDivideMonths2, concatSoftSign, bGroups, hFunctionH, combineSoundsLs, createSyllablesReady, accountEmphasis, isVowelL, zeroSyllablePart,
createSyllablesMultiLast2, divideToUnits, isSimPRecord, concatPunct, convertSyllableToLanguage, createSyllablesMulti, divideToListOfSoundGroupsAsLists, listOfFrames,
divideConsonants, prepareToSyllables, listOfPoints, createSoundL, createSoundGroups, amountOfPartsForKthSyl, createSoundLChar, isSimilar, isConsonantL, isFilteredForLast2,
-- * Functions that are used for sound creation itself
punctuationPauseLength, punctuationPauseLength1, endE, addSoftSign, punctL, punctOpt, punctL11, punctL1, isDigitOrDot, stringToInteger, createZeroSyllable, createSoftSign,
-- * Other functions that are used internally in these ones
endOfExecutable, isSimilarPauseRecords, specialConcatBS, isVowelOrPunctuation, isVowelEG, dropWithFirst, isDigitOrDash,
isPunctOrSpaceB, oneToTuple2, isPunctOrSpace, takeWithFirst, changeToEsperanto, verbSpecialConv, isSpecial, changeToDecoded, continueLang, mapLS
) where
import System.CPUTime (getCPUTime)
import System.Process (callCommand)
import System.Directory (findExecutable)
import System.Environment (getArgs)
import qualified Data.List as L (groupBy)
import qualified Data.Char as DC (toLower, isDigit, isAlpha, isPunctuation, isSpace)
import Data.Maybe (Maybe(Just,Nothing),isJust,isNothing)
import qualified Data.ByteString.Lazy.Char8 as C (ByteString,length,dropWhile,takeWhile,drop,unpack,pack,cons,empty,singleton,head,tail,
null,filter,groupBy,concat,any,span,foldr,readInteger,all)
import Prelude (Double,String,Char,Bool(True,False),Int,Integer,IO,FilePath,($!),($),(.),(==),(/=),(/),(*),(^),foldl1,(<),(<=),(>),(>=),(&&),(||),not,null,any,notElem,
fst,snd,show,error,putStr,putStrLn,(+),(-),div,mod,(++),foldr,map,zip,zipWith,take,drop,takeWhile,concat,concatMap,toInteger,return,last,init,
mapM_,filter,getContents,elem,last,head,tail,length,fromInteger,fromIntegral,otherwise,and,sum,all,words,unwords,fromIntegral,iterate,dropWhile)
-- | Main function
-- Головна функція
main :: IO ()
main = do
args <- getArgs
if (not . null $ args) && ((head args == "h") || (head args == "-h"))
then do
putStr "Введіть рядок українського тексту. За замовчуванням для багатоскладових слів наголос падатиме на передостанній склад у слові. "
putStr "Якщо Ви бажаєте змінити наголос, тоді перед словом злитно з ним напишіть натуральне число, яке є порядковим номером складу,"
putStr "на який падає наголос, починаючи з першого складу. Наприклад, \"3мальовнИчого\" означатиме, що наголошеним буде склад з \"И\". "
putStrLn "Не ставте дефісів або інших розділювачів (у т. ч. пробілів). Не хвилюйтеся, ці числа НЕ будуть озвучені програмою. "
putStrLn " "
putStr "Якщо бажаєте, щоб програма швидше читала деякі склади або літери, то можете ввести як аргументи командного рядка "
putStr "одне з чисел 1, або 2, або 3 (кожне наступне з яких дещо прискорює вимову деяких складів та літер порівняно з попереднім, "
putStrLn "втім різниця не така велика). "
putStrLn " "
putStrLn "Якщо Ви бажаєте, щоб усі склади розбивалися для озвучування на звуки, то введіть як аргумент командного рядка \"-W\" або \"W\". "
putStrLn ""
putStr "Якщо бажаєте задати свою тривалість паузи, можете задати додаткову тривалість паузи, вставивши в текст на місці паузи набір символів "
putStr "\"!1.253\", де цифри через крапку є звичайним записом числа типу Double, яке є бажаною додатковою тривалістю паузи, більшою за 0.1 секунди. "
putStrLn "Інакше буде додано паузу 0.1 секунди. "
else do
createSoftSign
nI2 <- getContents
let pauseW x = do
mapM_ (createSoundsForSyllable getCPUTime args) x
zz <- getCPUTime
let t1 = 10000000000 + (zz `div` 10000000) in
do
eS <- endS
callCommand $ "sox" ++ eS ++ " --multi-threaded -n -r 22.05k -c 1 -b 16 " ++ show t1 ++ ".ee.wav delay 0.015 trim 0 0.014"
in mapM_ (pauseW . combineSoundsLs3 (if elem "W" args || elem "-W" args then 0 else 1)) (words2 nI2)
-- | Function that is used instead of System.Info.os to check whether the eSpeak and SoX executables end in .exe
-- Функція, яка використовується замість System.Info.os, щоб перевірити, чи eSpeak і SoX програми закінчуються на .exe
endOfExecutable :: String -> IO String
endOfExecutable ys = do
xs <- findExecutable ys
if isJust xs
then return ""
else do
zs <- findExecutable (ys ++ ".exe")
if isJust zs
then return ".exe"
else error ("Please, install the executable " ++ ys ++ " into the directory in the PATH variable! \n")
-- | Function that is used to find out the ending of eSpeak executable installed if any
-- Функція, яка використовується для того, щоб знайти закінчення eSpeak програми, якщо така встановлена в системі
endE :: IO String
endE = endOfExecutable "espeak"
-- | Function that is used to find out the ending of SoX executable installed if any
-- Функція, яка використовується для того, щоб знайти закінчення SoX програми, якщо така встановлена в системі
endS :: IO String
endS = endOfExecutable "sox"
-- | Function that checks the eSpeak and SoX executables existence and is used for soft sign sound creation
-- Функція, що перевіряє існування eSpeak і SoX додатків у системі та використовується для створення звуку для м'якого знаку
createSoftSign :: IO ()
createSoftSign = do
eE <- endE
eS <- endS
callCommand $ "espeak" ++ eE ++ " -v esperanto -g 0 -w ь.wav -z \"j\""
callCommand $ "sox" ++ eS ++ " --multi-threaded ь.wav j.wav trim 0.02 0.037"
-- | Function that for the Ukrainian syllable represented as ((String, String),(String,Integer)) creates sounds
-- Функція, що для українського складу представленого як ((String, String),(String,Integer)) створює звуки
createSoundsForSyllable :: IO Integer -> [String] -> ((String, String),(String,Integer)) -> IO ()
createSoundsForSyllable time args ((xs, ys),(zs, k)) = case k of
0 -> do
t <- time
let t1 = 10000000000 + (t `div` 10000000) in if null args
then punctuationPauseLength t1 xs ys zs args
else punctuationPauseLength1 t1 xs ys zs args
_ -> do
t <- time
let t1 = 10000000000 + (t `div` 10000000) in
if last xs == 'q'
then do
eE <- endE
callCommand $ "espeak" ++ eE ++ " -v " ++ ys ++ " " ++ zs ++ " -w " ++ show t1 ++ "." ++ filter (/= 'q') xs ++ ".wav \"" ++ filter (/= 'q') xs ++ "\""
addSoftSign $ show t1 ++ "." ++ filter (/= 'q') xs ++ ".wav"
else do
eE <- endE
callCommand $ "espeak" ++ eE ++ " -v " ++ ys ++ " " ++ zs ++ " -w " ++ show t1 ++ "." ++ filter (/= 'q') xs ++ ".wav \"" ++ filter (/= 'q') xs ++ "\""
-- | Function that prepares a String for processing by the eSpeak and SoX for non-zero-syllable words
-- Функція, яка готує слово з голосним для подальшої обробки eSpeak та SoX
combineSoundsLs3 :: Int -> C.ByteString -> [((String, String), (String, Integer))]
combineSoundsLs3 k | k == 0 = combineSoundsLs30 pFunctionP0
| otherwise = combineSoundsLs30 pFunctionP
where combineSoundsLs30 p = concatMap hDivideMonths2 . concatSoftSign . bGroups p hFunctionH . combineSoundsLs
-- | Function that produces the list of Ukrainian strings from the primary Ukrainian string which can be further easily processed
-- Функція, яка створює список українських рядків з початкового українського рядка, які можуть бути легко оброблені далі
words2 :: String -> [C.ByteString]
words2 [] = []
words2 xs = concatPauseRecords . filter (not . C.null) . assimilationFirst . map (C.filter isSpecialNonSpace) . separatePunct . softAssociate . ukrainianLast2 . ukrainianJottedLast . ukrainianJotted1 .
changeAssimilative . separatePunct0 . ukrainianToMoreSounding . changeH2X . C.pack . change2BS . filter isFiltered . map firstChange . concatMap readEnglishWithUkrainian . unwords .
map (\x -> if all DC.isDigit x then concatMap numberSounds x else x) . words $ xs
-- | Function-predicate to filter the characters used for further processment
-- Функція-предикат, яка використовується для фільтрування потрібних символів для наступної обробки
isFiltered :: Char -> Bool
isFiltered x | x >= '\x044C' =
if x >= '\x02028'
then if x >= '\x20AC'
then x == '\x20AC' || x == '\x20B4' || x == '\x2103' || x == '\x2109' || x == '\x2122'
else x <= '\x2029' || (x >= '\x2047' && x <= '\x2049') || (x >= '\x20A0' && x <= '\x20A4')
else if x <= '\x0457'
then if x >= '\x0454'
then x /= '\x0455' && x <= '\x0457'
else x /= '\x044D' && x <= '\x044F'
else x == '\x0491' || (x >= '\x2002' && x <= '\x2014') || x == '\x2026'
| otherwise =
if x >= '\x003F'
then if x >= '\x007B'
then if x >= '\x00BB'
then x == '\x00BB' || (x >= '\x0430' && x <= '\x0449')
else (x >= '\x007B' && x <= '\x007F') || x == '\x00A0' || x == '\x00AB'
else x == '\x003F' || x == '\x0040' || x == '\x005C' || x == '\x005F' || x == '\x0060'
else if x <= '\x000F'
then x /= '\x000C' && x /= '\x0007'
else (x >= '\x0017' && x <= '\x001F') || (x >= '\x0020' && x <= '\x0022') || (x >= '\x0026' && x <= '\x003B')
-- | Function-predicate to check whether its argument is from the special volatile punctuation group that sets the duration of the additional pause
-- Функція-предикат, яка перевіряє, чи її аргумент є зі спеціальної довільної групи, яка встановлює тривалість додаткової паузи
isSimPRecord :: Char -> Bool
isSimPRecord x = (x == '\x0021') || isDigitOrDot x
-- | Function-predicate to check whether its arguments are both from the special volatile punctuation group that sets the duration of the additional pause (is used to group them by)
-- Функція-предикат, яка перевіряє, чи її аргументи обидва є зі спеціальної довільної групи, яка встановлює тривалість додаткової паузи (використовується, щоб їх згрупувати)
isSimilarPauseRecords :: C.ByteString -> C.ByteString -> Bool
isSimilarPauseRecords x y = C.all isSimPRecord x && C.all isSimPRecord y
-- | Function that concatenates a list of ByteString into the single ByteString and is used to set the duration of the additional pause
-- Функція, яка ппоєднує список ByteString у один ByteString і яка використовується для встановлення тривалості додаткової паузи
specialConcatBS :: [C.ByteString] -> C.ByteString
specialConcatBS xs | not . null $ xs =
if null . tail $ xs
then head xs
else C.concat xs
| otherwise = C.empty
-- | Function that is used for creation of the volatile pauses
-- Функція, яка використовується для створення довільних пауз
concatPauseRecords :: [C.ByteString] -> [C.ByteString]
concatPauseRecords xs | not . null $ xs =
map specialConcatBS . L.groupBy isSimilarPauseRecords $ xs
| otherwise = []
-- | Function-predicate used for filtering and indicating that a Char '\x000C' has not space semantics after encoding to ByteString
-- Функція-предикат, яка використовується для фільтрування та вказівки на те, що символ '\x000C' має не семантику пробільного символу після кодування в ByteString
isSpecialNonSpace :: Char -> Bool
isSpecialNonSpace x = case x of
'\x000C' -> True
_ -> not . DC.isSpace $ x
-- | Function that is used to create punctuation pauses
-- Функція, що використовується для створення пунктуаційних пауз
punctuationPauseLength :: Integer -> String -> String -> String -> [String] -> IO ()
punctuationPauseLength t1 xs = punctL (punctOpt xs) t1 xs
-- | Function that is used to create punctuation pauses if args include "1", or "2", or "3"
-- Функція, що використовується для створення пунктуаційних пауз, якщо args включають "1", або "2", або "3"
punctuationPauseLength1 :: Integer -> String -> String -> String -> [String] -> IO ()
punctuationPauseLength1 t1 xs = punctL11 (punctOpt xs) t1 xs
-- | Function that checks the eSpeak and SoX executables existence and is used for soft sign sound appending to the syllable or word
-- Функція, що перевіряє існування eSpeak і SoX додатків у системі та використовується для додавання м'якого знаку до кінцевого приголосного у слові чи складі
addSoftSign :: FilePath -> IO ()
addSoftSign file =
do
eS <- endS
callCommand $ "sox" ++ eS ++ " --multi-threaded " ++ file ++ " m." ++ file ++ " trim 0 -0.01"
callCommand $ "sox" ++ eS ++ " --multi-threaded m." ++ file ++ " j.wav " ++ file
-- | Function that divides wrongly sounding syllables for abbeviations of esperanto months into parts
-- Функція, яка ділить неправильно озвучувані склади для абревіатур назв місяців мовою есперанто на дві частини
hDivideMonths2:: ((String, String), (String, Integer)) -> [((String, String), (String, Integer))]
hDivideMonths2 ((xs, ys), (zs, k)) = let y = head xs in if y >= 'j'
then if y `elem` "jmos"
then if y == 'j'
then case xs of
"jan" -> [(("ja", ys), (zs, k)),(("n", ys), (zs, 0))]
"jul" -> [(("ju", ys), (zs, k)),(("l", ys), (zs, 0))]
"jun" -> [(("ju", ys), (zs, k)),(("n", ys), (zs, 0))]
_ -> [((xs, ys), (zs, k))]
else if xs >= "okt"
then case xs of
"okt" -> [(("ok", ys), (zs, k)),(("t", ys), (zs, 0))]
"sept" -> [(("sep", ys), (zs, k)),(("t", ys), (zs, 0))]
_ -> [((xs, ys), (zs, k))]
else case xs of
"maj" -> [(("ma", ys), (zs, k)),(("j", ys), (zs, 0))]
"mar" -> [(("ma", ys), (zs, k)),(("r", ys), (zs, 0))]
_ -> [((xs, ys), (zs, k))]
else [((xs, ys), (zs, k))]
else if y `elem` "adf"
then case xs of
"apr" -> [(("ap", ys), (zs, k)),(("r", ys), (zs, 0))]
"dec" -> [(("de", ys), (zs, k)),(("c", ys), (zs, 0))]
"feb" -> [(("fe", ys), (zs, k)),(("b", ys), (zs, 0))]
_ -> [((xs, ys), (zs, k))]
else [((xs, ys), (zs, k))]
-- | Function that concatenates alone soft sign with the previous letter (Esperanto or Greek)
-- Функція, яка з'єднує ізольований м'який знак з попереднім приголосним (есперанто чи грецькою)
concatSoftSign :: [((String, String), (String, Integer))] -> [((String, String), (String, Integer))]
concatSoftSign (x:xs) = if null xs
then [x]
else case fst . fst . head $ xs of
"q" | (fst . fst $ x) == "γ" -> x:concatSoftSign (tail xs)
| otherwise -> (((fst . fst $ x) ++ "q", "esperanto" ), snd x):concatSoftSign (tail xs)
_ -> x:concatSoftSign xs
concatSoftSign [] = []
-- | Function that converts zero-syllable groups of consonant sounds into separate sounds for further processing
-- Функція, що перетворює безголосні групи приголосних у окремі звуки для подальшої обробки
hFunctionH :: ((String, String), (String, Integer)) -> [((String, String), (String, Integer))]
hFunctionH (([x, y], ys), (zs, _)) | x == 'd' = case y of
'z' -> [(("dz", ys), (zs, 0))]
'ĵ' -> [(("dĵ", ys), (zs, 0))]
_ -> [(("d", ys), (zs, 0)), (([y], ys), (zs, 0))]
| otherwise = [(([x], ys), (zs, 0)), (([y], ys), (zs, 0))]
hFunctionH ((u:t:ts, ys), (zs, _)) | u == 'd' = case t of
'z' -> (("dz", ys), (zs, 0)):hFunctionH ((ts, ys), (zs, 0))
'ĵ' -> (("dĵ", ys), (zs, 0)):hFunctionH ((ts, ys), (zs, 0))
_ -> (("d", ys), (zs, 0)):hFunctionH ((t:ts, ys), (zs, 0))
| otherwise = (([u], ys), (zs, 0)):hFunctionH ((t:ts, ys), (zs, 0))
hFunctionH (([x], ys), (zs, _)) = [(([x], ys), (zs, 0))]
hFunctionH (([], _), (_, _)) = []
-- | Function that combines the emphasis and dividing into sound groups into languages
-- Функція, що поєднує наголос і поділ на групи звуків для мов
combineSoundsLs :: C.ByteString -> [((String, String), (String, Integer))]
combineSoundsLs xs | C.null xs = []
| otherwise = createSyllablesReady . accountEmphasis $ xs
-- | Function that applies additional function h to a if p is True on a
-- Функція, що застосовує додаткову функцію h до a, якщо p є Істина на a
bGroups :: (a -> Bool) -> (a -> [a]) -> [a] -> [a]
bGroups p h = concatMap (\x -> if p x then h x else [x])
-- | Function-predicate that checks whether the hFunctionH must be applied to the ((String, String), (String, Integer))
-- Функція-предикат, яка перевіряє, чи має бути застосована hFunctionH до ((String, String), (String, Integer))
pFunctionP :: ((String, String), (String, Integer)) -> Bool
pFunctionP ((xs, _), (_, _)) = ((not . any isVowelOrPunctuation $ xs) || ((length . takeWhile (not . isVowelEG) $ xs) > 3) || ((length . dropWithFirst isVowelEG $ xs ) > 3)) && (not . any DC.isPunctuation $ xs)
-- | Function-predicate that checks whether the hFunctionH must be applied to the ((String, String), (String, Integer)) for args containing -W or W
-- Функція-предикат, яка перевіряє, чи має бути застосована hFunctionH до ((String, String), (String, Integer)) для args, які містять -W або W
pFunctionP0 :: ((String, String), (String, Integer)) -> Bool
pFunctionP0 ((xs, _), (_, _)) = not . any DC.isPunctuation $ xs
-- | Additional function to take into account assimilation rules that depend on the position in the word of the group of Ukrainian sounds
-- Додаткова функція, щоб врахувати правила асиміляції, які залежать від положення у слові групи українських звуків
assimilationFirst :: [C.ByteString] -> [C.ByteString]
assimilationFirst [] = []
assimilationFirst xs = map (\x -> let z = C.dropWhile isDigitOrDash x in if C.null z
then C.takeWhile isDigitOrDash x
else case C.head z of
'\x007A' -> if C.null . C.tail $ z
then x
else case C.head . C.tail $ z of
'\x0049' -> C.concat [C.takeWhile isDigitOrDash x, '\x0042' `C.cons` C.singleton '\x0049', C.drop 2 z]
'\x0042' -> C.concat [C.takeWhile isDigitOrDash x, '\x0042' `C.cons` C.singleton '\x0042', C.drop 2 z]
_ -> x
_ -> x) xs
-- | Function that separates punctuation from the words for further processing
-- Функція, що відділяє пунктуацію від слів для подальшої обробки
separatePunct :: C.ByteString -> [C.ByteString]
separatePunct xs | C.null xs = [C.empty]
| (not . C.null . C.tail $ xs) && C.head xs == '!' = let z2 = C.span (\x -> isPunctOrSpaceB x || DC.isDigit x) xs in C.singleton ' ':fst z2:separatePunct (snd z2)
| isPunctOrSpaceB . C.head $ xs = let z = C.span isPunctOrSpaceB xs in C.singleton ' ':fst z:separatePunct (snd z)
| otherwise = let zN = C.span (not . isPunctOrSpaceB) xs in fst zN:separatePunct (snd zN)
-- | Additional function to check whether its argument takes into account that soft sign is considered as a part of a consonant
-- Додаткова функція, яка перевіряє, чи її аргумент бере до уваги, що м'який знак вважається частиною приголосного
softAssociate :: C.ByteString -> C.ByteString
softAssociate xs | C.null xs =
C.empty
| C.null . C.tail $ xs =
C.singleton z
| y == '\x0071' =
if z >= '\x006B'
then if z >= '\x0073'
then if z >= '\x0077'
then case z of
'\x0077' -> '\x0050' `C.cons` softAssociate (C.tail . C.tail $ xs)
'\x007A' -> '\x0055' `C.cons` softAssociate (C.tail . C.tail $ xs)
_ -> z `C.cons` softAssociate (C.tail . C.tail $ xs)
else case z of
'\x0073' -> '\x000C' `C.cons` softAssociate (C.tail . C.tail $ xs)
'\x0074' -> '\x0010' `C.cons` softAssociate (C.tail . C.tail $ xs)
'\x0076' -> '\x0078' `C.cons` softAssociate (C.tail . C.tail $ xs)
_ -> z `C.cons` softAssociate (C.tail . C.tail $ xs)
else if z <= '\x006D'
then case z of
'\x006B' -> '\x0056' `C.cons` softAssociate (C.tail . C.tail $ xs)
'\x006C' -> '\x0057' `C.cons` softAssociate (C.tail . C.tail $ xs)
'\x006D' -> '\x0058' `C.cons` softAssociate (C.tail . C.tail $ xs)
_ -> z `C.cons` softAssociate (C.tail . C.tail $ xs)
else case z of
'\x006E' -> '\x0059' `C.cons` softAssociate (C.tail . C.tail $ xs)
'\x0070' -> '\x005A' `C.cons` softAssociate (C.tail . C.tail $ xs)
'\x0072' -> '\x0007' `C.cons` softAssociate (C.tail . C.tail $ xs)
_ -> z `C.cons` softAssociate (C.tail . C.tail $ xs)
else if z <= '\x004F'
then if z >= '\x0049'
then case z of
'\x0049' -> '\x0014' `C.cons` softAssociate (C.tail . C.tail $ xs)
'\x004F' -> '\x0051' `C.cons` softAssociate (C.tail . C.tail $ xs)
_ -> z `C.cons` softAssociate (C.tail . C.tail $ xs)
else case z of
'\x0042' -> '\x0015' `C.cons` softAssociate (C.tail . C.tail $ xs)
'\x0043' -> '\x0016' `C.cons` softAssociate (C.tail . C.tail $ xs)
'\x0045' -> '\x0054' `C.cons` softAssociate (C.tail . C.tail $ xs)
_ -> z `C.cons` softAssociate (C.tail . C.tail $ xs)
else if z <= '\x0064'
then case z of
'\x0062' -> '\x005E' `C.cons` softAssociate (C.tail . C.tail $ xs)
'\x0063' -> '\x0013' `C.cons` softAssociate (C.tail . C.tail $ xs)
'\x0064' -> '\x0053' `C.cons` softAssociate (C.tail . C.tail $ xs)
_ -> z `C.cons` softAssociate (C.tail . C.tail $ xs)
else case z of
'\x0066' -> '\x0011' `C.cons` softAssociate (C.tail . C.tail $ xs)
'\x0067' -> '\x0052' `C.cons` softAssociate (C.tail . C.tail $ xs)
'\x0068' -> '\x0012' `C.cons` softAssociate (C.tail . C.tail $ xs)
_ -> z `C.cons` softAssociate (C.tail . C.tail $ xs)
| otherwise = z `C.cons` y `C.cons` softAssociate (C.tail . C.tail $ xs)
where z = C.head xs
y = C.head . C.tail $ xs
-- | Function that applies assimilation rules to the Ukrainian preprocessed string
-- Функція, яка застосовує правила асиміляції до українського попередньо обробленого рядка
ukrainianLast2 :: C.ByteString -> C.ByteString
ukrainianLast2 = fst . C.foldr f v
where v = (C.empty, C.empty)
f x (zs, xs) = case x of
'\x0045' -> if and [not . C.null $ xs, not . C.null . C.tail $ xs, C.head xs == '\x0073' || C.head xs == '\x0063' || C.head xs == '\x0013',
(C.head . C.tail $ xs) == '\x0071' || (C.head . C.tail $ xs) == '\x0069']
then ('\x0055' `C.cons` zs, x `C.cons` xs)
else ('\x0045' `C.cons` zs, x `C.cons` xs)
'\x0042' -> if and [not . C.null $ xs, not . C.null . C.tail $ xs, C.head xs == '\x0073' || C.head xs == '\x0063' || C.head xs == '\x0013',
(C.head . C.tail $ xs) == '\x0071' || (C.head . C.tail $ xs) == '\x0069']
then ('\x000C' `C.cons` zs, x `C.cons` xs)
else ('\x0042' `C.cons` zs, x `C.cons` xs)
'\x0049' -> if and [not . C.null $ xs, not . C.null . C.tail $ xs, C.head xs == '\x0073' || C.head xs == '\x0063' || C.head xs == '\x0013',
(C.head . C.tail $ xs) == '\x0071' || (C.head . C.tail $ xs) == '\x0069']
then ('\x0013' `C.cons` zs, x `C.cons` xs)
else ('\x0049' `C.cons` zs, x `C.cons` xs)
_ -> let ys = C.dropWhile (not . isFilteredForLast2) xs in if x < '\x0074'
then case x of
'\x0064' | (not . C.null $ ys) && elem (C.head ys) "\x0073\x007A\x0063" ->
('\x0064' `C.cons` '\x007A' `C.cons` zs, x `C.cons` xs)
| (not . C.null $ ys) && elem (C.head ys) "\x0045\x0042\x0049" ->
('\x0064' `C.cons` '\x0045' `C.cons` zs, x `C.cons` xs)
| otherwise -> ('\x0064' `C.cons` zs, x `C.cons` xs)
'\x0073' | (not . C.null $ ys) && (C.head ys == '\x0042') ->
('\x0042' `C.cons` zs, x `C.cons` xs)
| otherwise -> ('\x0073' `C.cons` zs, x `C.cons` xs)
_ -> (x `C.cons` zs, x `C.cons` xs)
else case x of
'\x0074' | (not . C.null $ ys) && (C.head ys == '\x0063') ->
('\x0063' `C.cons` zs, x `C.cons` xs)
| (not . C.null $ ys) && elem (C.head ys) "\x0042\x0049" ->
('\x0049' `C.cons` zs, x `C.cons` xs)
| otherwise -> ('\x0074' `C.cons` zs, x `C.cons` xs)
'\x007A' | (not . C.null $ ys) && elem (C.head ys) "\x0042\x0045\x0049" ->
('\x0045' `C.cons` zs, x `C.cons` xs)
| (not . C.null $ ys) && (C.head ys == '\x0064') &&
(not . C.null . C.tail $ ys) && ((C.head . C.tail $ ys) == '\x0045') ->
('\x0045' `C.cons` zs, x `C.cons` xs)
| otherwise -> ('\x007A' `C.cons` zs, x `C.cons` xs)
_ -> (x `C.cons` zs, x `C.cons` xs)
-- | Function-predicate that is used to eliminate the quantity of ukrainianLast2 applications
-- Функція-предикат, яка використовується для зменшення кількості застосувань функції ukrainianLast2
isFilteredForLast2 :: Char -> Bool
isFilteredForLast2 z | z <= '\x005A' =
if z <= '\x0016'
then z >= '\x0010' || (z == '\x0007' || z == '\x000C')
else z >= '\x0041' && z /= '\x0048'
| z <= '\x00F9' =
if z <= '\x007A'
then z >= '\x0061' || z == '\x005E'
else z >= '\x00E1' && z <= '\x00F9'
| otherwise = DC.isPunctuation z
-- | Function to convert Ukrainian "я", "ю", "є" and "ї" into some other String for syllables processing
-- Функція для перетворення українських "я", "ю", "є" та "ї" на деякі інші рядки для обробки складів
ukrainianJottedLast :: C.ByteString -> C.ByteString
ukrainianJottedLast xs | C.null xs =
C.empty
| otherwise =
case C.head xs of
'\x0047' -> '\x0071' `C.cons` '\x0061' `C.cons` ukrainianJottedLast (C.tail xs)
'\x004A' -> '\x0071' `C.cons` '\x0075' `C.cons` ukrainianJottedLast (C.tail xs)
'\x0046' -> '\x0071' `C.cons` '\x0065' `C.cons` ukrainianJottedLast (C.tail xs)
'\x0044' -> '\x006A' `C.cons` '\x0069' `C.cons` ukrainianJottedLast (C.tail xs)
'\x0074' -> if C.null . C.tail $ xs
then C.singleton '\x0074'
else case C.head . C.tail $ xs of
'\x0073' -> '\x0063' `C.cons` ukrainianJottedLast (C.tail . C.tail $ xs)
_ -> '\x0074' `C.cons` ukrainianJottedLast (C.tail xs)
_ -> C.head xs `C.cons` ukrainianJottedLast (C.tail xs)
-- | Optimized function to convert Ukrainian "я", "ю", "є" and "ї" into some other String for syllables processing
-- Оптимізована функція для перетворення українських "я", "ю", "є" та "ї" на деякі інші рядки для обробки складів
ukrainianJotted1 :: C.ByteString -> C.ByteString
ukrainianJotted1 = fst . C.foldr f v
where v = (C.empty, C.empty)
f x (ys,xs) | C.null xs =
(C.singleton x, x `C.cons` xs)
| otherwise =
if k == '\x0044'
then (x `C.cons` '\x006A' `C.cons` '\x0069' `C.cons` C.tail ys, x `C.cons` xs)
else if k == '\x0047' || k == '\x0046' || k == '\x004A'
then if x >= '\x0030' && x <= '\x0039'
then (x `C.cons` '\x006A' `C.cons` jC k `C.cons` C.tail ys, x `C.cons` xs)
else if x >= '\x004B'
then if x >= '\x006F'
then case x of
'\x006F' -> (x `C.cons` '\x006A' `C.cons` jC k `C.cons` C.tail ys, x `C.cons` xs)
'\x0075' -> (x `C.cons` '\x006A' `C.cons` jC k `C.cons` C.tail ys, x `C.cons` xs)
'\x0079' -> (x `C.cons` '\x006A' `C.cons` jC k `C.cons` C.tail ys, x `C.cons` xs)
_ -> (x `C.cons` '\x0071' `C.cons` jC k `C.cons` C.tail ys, x `C.cons` xs)
else if x <= '\x0061'
then case x of
'\x004B' -> (x `C.cons` '\x006A' `C.cons` jC k `C.cons` C.tail ys, x `C.cons` xs)
'\x0061' -> (x `C.cons` '\x006A' `C.cons` jC k `C.cons` C.tail ys, x `C.cons` xs)
_ -> (x `C.cons` '\x0071' `C.cons` jC k `C.cons` C.tail ys, x `C.cons` xs)
else case x of
'\x0065' -> (x `C.cons` '\x006A' `C.cons` jC k `C.cons` C.tail ys, x `C.cons` xs)
'\x0069' -> (x `C.cons` '\x006A' `C.cons` jC k `C.cons` C.tail ys, x `C.cons` xs)
_ -> (x `C.cons` '\x0071' `C.cons` jC k `C.cons` C.tail ys, x `C.cons` xs)
else if x <= '\x0044'
then if x >= '\x002D'
then case x of
'\x002D' -> (x `C.cons` '\x006A' `C.cons` jC k `C.cons` C.tail ys, x `C.cons` xs)
'\x0044' -> (x `C.cons` '\x006A' `C.cons` jC k `C.cons` C.tail ys, x `C.cons` xs)
_ -> (x `C.cons` '\x0071' `C.cons` jC k `C.cons` C.tail ys, x `C.cons` xs)
else case x of
'\x0020' -> (x `C.cons` '\x006A' `C.cons` jC k `C.cons` C.tail ys, x `C.cons` xs)
'\x0027' -> (x `C.cons` '\x006A' `C.cons` jC k `C.cons` C.tail ys, x `C.cons` xs)
_ -> (x `C.cons` '\x0071' `C.cons` jC k `C.cons` C.tail ys, x `C.cons` xs)
else case x of
'\x0046' -> (x `C.cons` '\x006A' `C.cons` jC k `C.cons` C.tail ys, x `C.cons` xs)
'\x0047' -> (x `C.cons` '\x006A' `C.cons` jC k `C.cons` C.tail ys, x `C.cons` xs)
'\x004A' -> (x `C.cons` '\x006A' `C.cons` jC k `C.cons` C.tail ys, x `C.cons` xs)
_ -> (x `C.cons` '\x0071' `C.cons` jC k `C.cons` C.tail ys, x `C.cons` xs)
else (x `C.cons` ys, x `C.cons` xs)
where k = C.head xs
jC y | y == '\x0047' = '\x0061'
| y == '\x004A' = '\x0075'
| y == '\x0046' = '\x0065'
| otherwise = y
-- | Function that makes some assimilation changes for correct Ukrainian pronunciation
-- Функція, що робить деякі асиміляційні зміни для правильної української вимови
changeAssimilative :: C.ByteString -> C.ByteString
changeAssimilative xs | C.null xs = C.empty
| C.head xs == '\x006E' =
if C.null . C.tail $ xs
then xs
else case C.head . C.tail $ xs of
'\x0074' -> if C.null . C.tail . C.tail $ xs
then xs
else case C.head . C.tail . C.tail $ xs of
'\x0073' -> if C.null . C.tail . C.tail . C.tail $ xs
then xs
else case C.head . C.tail . C.tail . C.tail $ xs of
'\x0074' -> '\x006E' `C.cons` '\x0073' `C.cons` '\x0074' `C.cons` changeAssimilative (C.tail . C.tail . C.tail . C.tail $ xs)
_ -> '\x006E' `C.cons` '\x0063' `C.cons` changeAssimilative (C.tail . C.tail . C.tail $ xs)
'\x000C' -> if C.null . C.tail . C.tail . C.tail $ xs
then xs
else case C.head . C.tail . C.tail . C.tail $ xs of
'\x006B' -> '\x0059' `C.cons` '\x000C' `C.cons` '\x0068' `C.cons` changeAssimilative (C.tail . C.tail . C.tail . C.tail $ xs)
_ -> '\x006E' `C.cons` '\x0013' `C.cons` changeAssimilative (C.tail . C.tail . C.tail $ xs)
_ -> '\x006E' `C.cons` '\x0074' `C.cons` changeAssimilative (C.tail . C.tail $ xs)
_ -> '\x006E' `C.cons` changeAssimilative (C.tail xs)
| C.head xs == '\x0073' =
if C.null . C.tail $ xs
then xs
else case C.head . C.tail $ xs of
'\x0074' -> if C.null . C.tail . C.tail $ xs
then xs
else case C.head . C.tail . C.tail $ xs of
'\x000C' -> if C.null . C.tail . C.tail . C.tail $ xs
then xs
else case C.head . C.tail . C.tail . C.tail $ xs of
'\x006B' -> '\x000C' `C.cons` '\x000C' `C.cons` '\x006B' `C.cons` changeAssimilative (C.tail . C.tail . C.tail . C.tail $ xs)
_ -> '\x0073' `C.cons` '\x0074' `C.cons` '\x000C' `C.cons` changeAssimilative (C.tail . C.tail . C.tail $ xs)
'\x0013' -> if C.null . C.tail . C.tail . C.tail $ xs
then xs
else '\x000C' `C.cons` '\x0013' `C.cons` '\x0013' `C.cons` changeAssimilative (C.tail . C.tail . C.tail $ xs)
'\x0049' -> if C.null . C.tail . C.tail . C.tail $ xs
then xs
else '\x0042' `C.cons` '\x0049' `C.cons` changeAssimilative (C.tail . C.tail . C.tail $ xs)
'\x0064' -> if C.null . C.tail . C.tail . C.tail $ xs
then xs
else '\x007A' `C.cons` '\x0064' `C.cons` changeAssimilative (C.tail . C.tail . C.tail $ xs)
'\x0073' -> if C.null . C.tail . C.tail . C.tail $ xs
then xs
else '\x0073' `C.cons` '\x0073' `C.cons` changeAssimilative (C.tail . C.tail . C.tail $ xs)
_ -> '\x0073' `C.cons` '\x0074' `C.cons` changeAssimilative (C.tail . C.tail $ xs)
_ -> '\x0073' `C.cons` changeAssimilative (C.tail xs)
| C.head xs == '\x0047' =
if C.null . C.tail $ xs
then xs
else case C.head . C.tail $ xs of
'\x0074' -> if C.null . C.tail . C.tail $ xs
then xs
else case C.head . C.tail . C.tail $ xs of
'\x0064' -> if C.null . C.tail . C.tail . C.tail $ xs
then xs
else case C.head . C.tail . C.tail . C.tail $ xs of
'\x0065' -> if C.null . C.tail . C.tail . C.tail . C.tail $ xs
then xs
else case C.head . C.tail . C.tail . C.tail . C.tail $ xs of
'\x0073' -> if C.null . C.tail . C.tail . C.tail . C.tail . C.tail $ xs
then xs
else case C.head . C.tail . C.tail . C.tail . C.tail . C.tail $ xs of
'\x0047' -> if C.null . C.tail . C.tail . C.tail . C.tail . C.tail . C.tail $ xs
then xs
else case C.head . C.tail . C.tail . C.tail . C.tail . C.tail . C.tail $ xs of
'\x0074' -> '\x006A' `C.cons` '\x0061' `C.cons` '\x0064' `C.cons` '\x0065' `C.cons` '\x000C' `C.cons` '\x0061' `C.cons` '\x0074' `C.cons`
changeAssimilative (C.tail . C.tail . C.tail . C.tail . C.tail . C.tail . C.tail $ xs)
_ -> '\x0047' `C.cons` '\x0074' `C.cons` '\x0064' `C.cons` '\x0065' `C.cons` '\x0073' `C.cons` '\x0047' `C.cons`
changeAssimilative (C.tail . C.tail . C.tail . C.tail . C.tail . C.tail $ xs)
_ -> '\x0047' `C.cons` '\x0074' `C.cons` '\x0064' `C.cons` '\x0065' `C.cons` '\x0073'`C.cons`
changeAssimilative (C.tail . C.tail . C.tail . C.tail . C.tail $ xs)
_ -> '\x0047' `C.cons` '\x0074' `C.cons` '\x0064' `C.cons` '\x0065' `C.cons` changeAssimilative (C.tail . C.tail . C.tail . C.tail $ xs)
_ -> '\x0047' `C.cons` '\x0074' `C.cons` '\x0064' `C.cons` changeAssimilative (C.tail . C.tail . C.tail $ xs)
_ -> '\x0047' `C.cons` '\x0074' `C.cons` changeAssimilative (C.tail . C.tail $ xs)
_ -> '\x0047' `C.cons` changeAssimilative (C.tail xs)
| otherwise = C.head xs `C.cons` changeAssimilative (C.tail xs)
-- | Function that separates punctuation marks from the words
-- Функція, яка відділяє пунктуаційні знаки від слів
separatePunct0 :: C.ByteString -> C.ByteString
separatePunct0 = C.foldr f v
where v = C.empty
f x ys | DC.isPunctuation x || (x >= '\x00E1' && x <= '\x00F9') || (x >= '\x0030' && x <= '\x0039') = ' ' `C.cons` x `C.cons` ' ' `C.cons` ys
| otherwise = x `C.cons` ys
-- | Function that primarily converts Ukrainian line into more sounds-based line and more oriented to more using prosodical information
-- Функція, що початково перетворює український рядок на більш орінтований на звуки рядок і більш орієнтований на використання просодійної інформації
ukrainianToMoreSounding :: C.ByteString -> C.ByteString
ukrainianToMoreSounding xs = if C.null xs
then C.empty
else let f ys = if not . C.null . C.tail $ ys
then case C.head . C.tail $ ys of
'\x0047' -> C.head ys `C.cons` '\x006A' `C.cons` '\x0061' `C.cons` ukrainianToMoreSounding (C.tail . C.tail $ ys)
'\x004A' -> C.head ys `C.cons` '\x006A' `C.cons` '\x0075' `C.cons` ukrainianToMoreSounding (C.tail . C.tail $ ys)
'\x0046' -> C.head ys `C.cons` '\x006A' `C.cons` '\x0065' `C.cons` ukrainianToMoreSounding (C.tail . C.tail $ ys)
'\x0044' -> C.head ys `C.cons` '\x006A' `C.cons` '\x0069' `C.cons` ukrainianToMoreSounding (C.tail . C.tail $ ys)
_ -> C.head ys `C.cons` ukrainianToMoreSounding (C.tail ys)
else C.singleton . C.head $ ys in let zz = C.head xs in let z2 zs = C.head zs `C.cons` ukrainianToMoreSounding (C.tail zs) in if zz >= '\x0051'
then if zz >= '\x0058'
then if zz >= '\x005E'
then case zz of
'\x005E' -> f xs
'\x0071' -> f xs
'\x0078' -> f xs
_ -> z2 xs
else case zz of
'\x0058' -> f xs
'\x0059' -> f xs
'\x005A' -> f xs
_ -> z2 xs
else if zz >= '\x0054'
then if zz >= '\x0056'
then case zz of
'\x0056' -> f xs
'\x0057' -> f xs
_ -> z2 xs
else case zz of
'\x0054' -> f xs
'\x0055' -> f xs
_ -> z2 xs
else case zz of
'\x0051' -> f xs
'\x0052' -> f xs
'\x0053' -> f xs
_ -> z2 xs
else if zz <= '\x0013'
then if zz <= '\x0010'
then case zz of
'\x0007' -> f xs
'\x000C' -> f xs
'\x0010' -> if not . C.null . C.tail $ xs
then case C.head . C.tail $ xs of
'\x0073' -> if not . C.null . C.tail . C.tail $ xs
then if (C.head . C.tail . C.tail $ xs) == '\x0047'
then '\x0013' `C.cons` '\x0013' `C.cons` '\x0061' `C.cons`
ukrainianToMoreSounding (C.tail . C.tail . C.tail $ xs)
else '\x0010' `C.cons` '\x0073' `C.cons` ukrainianToMoreSounding (C.tail . C.tail $ xs)
else '\x0010' `C.cons` C.singleton '\x0073'
_ -> '\x0010' `C.cons` ukrainianToMoreSounding (C.tail xs)
else C.singleton '\x0010'
_ -> z2 xs
else case zz of
'\x0011' -> f xs
'\x0012' -> f xs
'\x0013' -> f xs
_ -> z2 xs
else if zz <= '\x0020'
then if zz <= '\x0015'
then case zz of
'\x0014' -> f xs
'\x0015' -> f xs
_ -> z2 xs
else case zz of
'\x0016' -> f xs
'\x0020' -> if not . C.null . C.tail $ xs
then case C.head . C.tail $ xs of
'-' -> if not . C.null . C.tail . C.tail $ xs
then if (C.head . C.tail . C.tail $ xs) == '-'
then ' ' `C.cons` ukrainianToMoreSounding (C.tail . C.tail . C.tail $ xs)
else ' ' `C.cons` '-' `C.cons` ukrainianToMoreSounding (C.tail xs)
else C.singleton ' '
_ -> ' ' `C.cons` ukrainianToMoreSounding (C.tail xs)
else C.singleton ' '
_ -> z2 xs
else if zz >= '\x004B'
then case zz of
'\x004B' -> if not . C.null . C.tail $ xs
then case C.head . C.tail $ xs of
'\x0047' -> '\x006A' `C.cons` '\x006A' `C.cons` '\x0061' `C.cons` ukrainianToMoreSounding (C.tail . C.tail $ xs)
'\x004A' -> '\x006A' `C.cons` '\x006A' `C.cons` '\x0075' `C.cons` ukrainianToMoreSounding (C.tail . C.tail $ xs)
'\x0046' -> '\x006A' `C.cons` '\x006A' `C.cons` '\x0065' `C.cons` ukrainianToMoreSounding (C.tail . C.tail $ xs)
'\x0044' -> '\x006A' `C.cons` '\x006A' `C.cons` '\x0069' `C.cons` ukrainianToMoreSounding (C.tail . C.tail $ xs)
_ -> C.head xs `C.cons` ukrainianToMoreSounding (C.tail xs)
else C.empty
'\x0050' -> f xs
_ -> z2 xs
else case zz of
'\x002D' -> if not . C.null . C.tail $ xs
then case C.head . C.tail $ xs of
'-' -> if not . C.null . C.tail . C.tail $ xs
then if (C.head . C.tail . C.tail $ xs) == ' '
then ' ' `C.cons` ukrainianToMoreSounding (C.tail . C.tail . C.tail $ xs)
else ' ' `C.cons` ukrainianToMoreSounding (C.tail . C.tail $ xs)
else C.singleton ' '
_ -> ' ' `C.cons` ukrainianToMoreSounding (C.tail xs)
else C.singleton ' '
'\x0043' -> '\x0042' `C.cons` '\x0049' `C.cons` ukrainianToMoreSounding (C.tail xs)
_ -> z2 xs
-- | Function for special Ukrainian words where "г" sounds approximately as "х"
-- Функція для спеціальних українських слів, де звук "г" звучить близько до "х"
changeH2X :: C.ByteString -> C.ByteString
changeH2X xs | C.null xs = C.empty
| C.head xs == '\x0076' = if C.null . C.tail $ xs
then xs
else case C.head . C.tail $ xs of
'\x006F' -> if C.null . C.tail . C.tail $ xs
then xs
else case C.head . C.tail . C.tail $ xs of
'\x0041' -> if C.null . C.tail . C.tail . C.tail $ xs
then xs
else case C.head . C.tail . C.tail . C.tail $ xs of
'\x006B' -> '\x0076' `C.cons` '\x006F' `C.cons` '\x0068' `C.cons` '\x006B' `C.cons` changeH2X (C.tail . C.tail . C.tail . C.tail $ xs)
_ -> '\x0076' `C.cons` '\x006F' `C.cons` '\x0041' `C.cons` (C.head . C.tail . C.tail . C.tail $ xs) `C.cons` changeH2X (C.tail . C.tail . C.tail . C.tail $ xs)
_ -> '\x0076' `C.cons` '\x006F' `C.cons` (C.head . C.tail . C.tail $ xs) `C.cons` changeH2X (C.tail . C.tail . C.tail $ xs)
_ -> '\x0076' `C.cons` (C.head . C.tail $ xs) `C.cons` changeH2X (C.tail . C.tail $ xs)
| C.head xs == '\x006C' = if C.null . C.tail $ xs
then xs
else case C.head . C.tail $ xs of
'\x0065' -> if C.null . C.tail . C.tail $ xs
then xs
else case C.head . C.tail . C.tail $ xs of
'\x0041' -> if C.null . C.tail . C.tail . C.tail $ xs
then xs
else case C.head . C.tail . C.tail . C.tail $ xs of
'\x006B' -> '\x006C' `C.cons` '\x0065' `C.cons` '\x0068' `C.cons` '\x006B' `C.cons` changeH2X (C.tail . C.tail . C.tail . C.tail $ xs)
_ -> '\x006C' `C.cons` '\x0065' `C.cons` '\x0041' `C.cons` (C.head . C.tail . C.tail . C.tail $ xs) `C.cons` changeH2X (C.tail . C.tail . C.tail . C.tail $ xs)
_ -> '\x006C' `C.cons` '\x0065' `C.cons` (C.head . C.tail . C.tail $ xs) `C.cons` changeH2X (C.tail . C.tail . C.tail $ xs)
_ -> '\x006C' `C.cons` (C.head . C.tail $ xs) `C.cons` changeH2X (C.tail . C.tail $ xs)
| C.head xs == '\x006B' = if C.null . C.tail $ xs
then xs
else case C.head . C.tail $ xs of
'\x0069' -> if C.null . C.tail . C.tail $ xs
then xs
else case C.head . C.tail . C.tail $ xs of
'\x0041' -> if C.null . C.tail . C.tail . C.tail $ xs
then xs
else case C.head . C.tail . C.tail . C.tail $ xs of
'\x0074' -> '\x006B' `C.cons` '\x0069' `C.cons` '\x0068' `C.cons` '\x0074' `C.cons` changeH2X (C.tail . C.tail . C.tail . C.tail $ xs)
_ -> '\x006B' `C.cons` '\x0069' `C.cons` '\x0041' `C.cons` (C.head . C.tail . C.tail . C.tail $ xs) `C.cons` changeH2X (C.tail . C.tail . C.tail . C.tail $ xs)
_ -> '\x006B' `C.cons` '\x0069' `C.cons` (C.head . C.tail . C.tail $ xs) `C.cons` changeH2X (C.tail . C.tail . C.tail $ xs)
_ -> '\x006B' `C.cons` (C.head . C.tail $ xs) `C.cons` changeH2X (C.tail . C.tail $ xs)
| C.head xs == '\x006E' = if C.null . C.tail $ xs
then xs
else case C.head . C.tail $ xs of
'\x0069' -> if C.null . C.tail . C.tail $ xs
then xs
else case C.head . C.tail . C.tail $ xs of
'\x0041' -> if C.null . C.tail . C.tail . C.tail $ xs
then xs
else case C.head . C.tail . C.tail . C.tail $ xs of
'\x0074' -> '\x006E' `C.cons` '\x0069' `C.cons` '\x0068' `C.cons` '\x0074' `C.cons` changeH2X (C.tail . C.tail . C.tail . C.tail $ xs)
_ -> '\x006E' `C.cons` '\x0069' `C.cons` '\x0041' `C.cons` (C.head . C.tail . C.tail . C.tail $ xs) `C.cons` changeH2X (C.tail . C.tail . C.tail . C.tail $ xs)
_ -> '\x006E' `C.cons` '\x0069' `C.cons` (C.head . C.tail . C.tail $ xs) `C.cons` changeH2X (C.tail . C.tail . C.tail $ xs)
_ -> '\x006E' `C.cons` (C.head . C.tail $ xs) `C.cons` changeH2X (C.tail . C.tail $ xs)
| C.head xs == '\x0064' = if C.null . C.tail $ xs
then xs
else case C.head . C.tail $ xs of
'\x0069' -> if C.null . C.tail . C.tail $ xs
then xs
else case C.head . C.tail . C.tail $ xs of
'\x0041' -> if C.null . C.tail . C.tail . C.tail $ xs
then xs
else case C.head . C.tail . C.tail . C.tail $ xs of
'\x0074' -> if C.null . C.tail . C.tail . C.tail . C.tail $ xs
then xs
else case C.head . C.tail . C.tail . C.tail . C.tail $ xs of
'\x0047' -> if C.null . C.tail . C.tail . C.tail . C.tail . C.tail $ xs
then xs
else case C.head . C.tail . C.tail . C.tail . C.tail . C.tail $ xs of
'\x0072' -> '\x0064' `C.cons` '\x0069' `C.cons` '\x0068' `C.cons` '\x0074' `C.cons` '\x0047' `C.cons`
'\x0072' `C.cons` changeH2X (C.tail . C.tail . C.tail . C.tail . C.tail . C.tail $ xs)
_ -> '\x0064' `C.cons` '\x0069' `C.cons` '\x0041' `C.cons` '\x0074' `C.cons` '\x0047' `C.cons`
(C.head . C.tail . C.tail . C.tail . C.tail . C.tail $ xs) `C.cons` changeH2X (C.tail . C.tail . C.tail . C.tail . C.tail . C.tail $ xs)
_ -> '\x0064' `C.cons` '\x0069' `C.cons` '\x0041' `C.cons` '\x0074' `C.cons` (C.head . C.tail . C.tail . C.tail . C.tail $ xs) `C.cons`
changeH2X (C.tail . C.tail . C.tail . C.tail . C.tail $ xs)
_ -> '\x0064' `C.cons` '\x0069' `C.cons` '\x0041' `C.cons` (C.head . C.tail . C.tail . C.tail $ xs) `C.cons`
changeH2X (C.tail . C.tail . C.tail . C.tail $ xs)
_ -> '\x0064' `C.cons` '\x0069' `C.cons` (C.head . C.tail . C.tail $ xs) `C.cons` changeH2X (C.tail . C.tail . C.tail $ xs)
_ -> '\x0064' `C.cons` (C.head . C.tail $ xs) `C.cons` changeH2X (C.tail . C.tail $ xs)
| otherwise = C.head xs `C.cons` changeH2X (C.tail xs)
-- | Function that encode the Unicode characters from '\x0430' to '\x2122' for using in the Data.ByteString.Lazy.Char8 functions
-- Функція, що кодує Unicode символи з '\x0430' по '\x2122' для використання у Data.ByteString.Lazy.Char8 функціях
change2BS :: String -> String
change2BS (x : (y : (z : xs)))
| y == '\1100' =
if x >= '\1088' then
if x >= '\1094' then
if x >= '\1097' then
case x of
'\1097' -> '\SYN' : change2BS (z : xs)
'\1169' -> 'R' : change2BS (z : xs)
_ -> change2BS (x : z : xs)
else
case x of
'\1094' -> '\DC3' : change2BS (z : xs)
'\1095' -> '\DC4' : change2BS (z : xs)
'\1096' -> '\NAK' : change2BS (z : xs)
_ -> change2BS (x : z : xs)
else
if x >= '\1092' then
case x of
'\1092' -> '\DC1' : change2BS (z : xs)
'\1093' -> '\DC2' : change2BS (z : xs)
_ -> change2BS (x : z : xs)
else
case x of
'\1088' -> '\a' : change2BS (z : xs)
'\1089' -> '\f' : change2BS (z : xs)
'\1090' -> '\DLE' : change2BS (z : xs)
_ -> change2BS (x : z : xs)
else
if x <= '\1078' then
if x <= '\1075' then
case x of
'\1073' -> '^' : change2BS (z : xs)
'\1074' -> 'x' : change2BS (z : xs)
'\1075' -> '\US' : change2BS (z : xs)
_ -> change2BS (x : z : xs)
else
case x of
'\1076' -> 'S' : change2BS (z : xs)
'\1078' -> 'T' : change2BS (z : xs)
_ -> change2BS (x : z : xs)
else
if x >= '\1084' then
case x of
'\1084' -> 'X' : change2BS (z : xs)
'\1085' -> 'Y' : change2BS (z : xs)
'\1087' -> 'Z' : change2BS (z : xs)
_ -> change2BS (x : z : xs)
else
case x of
'\1079' -> 'U' : change2BS (z : xs)
'\1082' -> 'V' : change2BS (z : xs)
'\1083' -> 'W' : change2BS (z : xs)
_ -> change2BS (x : z : xs)
| x == '\1076' =
case y of
'\1079' -> if z == '\1100' then 'Q' : change2BS xs else
'O' : change2BS (z : xs)
'\1078' -> if z == '\1100' then 'P' : change2BS xs else
'w' : change2BS (z : xs)
_ -> 'd' : change2BS (y : z : xs)
| x >= '\8195' =
if x >= '\8212' then
if x >= '\8354' then
if x >= '\8372' then
if x >= '\8457' then
case x of
'\8457' -> '\162' : change2BS (y : z : xs)
'\8482' -> '\168' : change2BS (y : z : xs)
_ -> x : change2BS (y : z : xs)
else
case x of
'\8372' -> '\255' : change2BS (y : z : xs)
'\8451' -> '\165' : change2BS (y : z : xs)
_ -> x : change2BS (y : z : xs)
else
if x <= '\8355' then
case x of
'\8354' -> '\252' : change2BS (y : z : xs)
'\8355' -> '\253' : change2BS (y : z : xs)
_ -> x : change2BS (y : z : xs)
else
case x of
'\8356' -> '\254' : change2BS (y : z : xs)
'\8364' -> '\181' : change2BS (y : z : xs)
_ -> x : change2BS (y : z : xs)
else
if x <= '\8263' then
if x >= '\8233' then
case x of
'\8233' -> '\246' : change2BS (y : z : xs)
'\8263' -> '\247' : change2BS (y : z : xs)
_ -> x : change2BS (y : z : xs)
else
case x of
'\8212' -> 'M' : change2BS (y : z : xs)
'\8230' -> '.' : '.' : '.' : change2BS (y : z : xs)
'\8232' -> '\245' : change2BS (y : z : xs)
_ -> x : change2BS (y : z : xs)
else
if x <= '\8265' then
case x of
'\8264' -> '\248' : change2BS (y : z : xs)
'\8265' -> '\249' : change2BS (y : z : xs)
_ -> x : change2BS (y : z : xs)
else
case x of
'\8352' -> '\250' : change2BS (y : z : xs)
'\8353' -> '\251' : change2BS (y : z : xs)
_ -> x : change2BS (y : z : xs)
else
if x <= '\8202' then
if x >= '\8199' then
if x >= '\8201' then
case x of
'\8201' -> '\232' : change2BS (y : z : xs)
'\8202' -> '\233' : change2BS (y : z : xs)
_ -> x : change2BS (y : z : xs)
else
case x of
'\8199' -> '\230' : change2BS (y : z : xs)
'\8200' -> '\231' : change2BS (y : z : xs)
_ -> x : change2BS (y : z : xs)
else
if x <= '\8196' then
case x of
'\8195' -> '\226' : change2BS (y : z : xs)
'\8196' -> '\227' : change2BS (y : z : xs)
_ -> x : change2BS (y : z : xs)
else
case x of
'\8197' -> '\228' : change2BS (y : z : xs)
'\8198' -> '\229' : change2BS (y : z : xs)
_ -> x : change2BS (y : z : xs)
else
if x <= '\8206' then
if x >= '\8205' then
case x of
'\8205' -> '\236' : change2BS (y : z : xs)
'\8206' -> '\237' : change2BS (y : z : xs)
_ -> x : change2BS (y : z : xs)
else
case x of
'\8203' -> '\234' : change2BS (y : z : xs)
'\8204' -> '\235' : change2BS (y : z : xs)
_ -> x : change2BS (y : z : xs)
else
if x <= '\8209' then
case x of
'\8207' -> '\238' : change2BS (y : z : xs)
'\8208' -> '\239' : change2BS (y : z : xs)
'\8209' -> '\240' : change2BS (y : z : xs)
_ -> x : change2BS (y : z : xs)
else
case x of
'\8210' -> '\241' : change2BS (y : z : xs)
'\8211' -> 'L' : change2BS (y : z : xs)
_ -> x : change2BS (y : z : xs)
| x <= '\1088' =
if x >= '\1080' then
if x >= '\1085' then
if x >= '\1087' then
case x of
'\1087' -> 'p' : change2BS (y : z : xs)
'\1088' -> 'r' : change2BS (y : z : xs)
_ -> x : change2BS (y : z : xs)
else
case x of
'\1085' -> 'n' : change2BS (y : z : xs)
'\1086' -> 'o' : change2BS (y : z : xs)
_ -> x : change2BS (y : z : xs)
else
if x <= '\1082' then
case x of
'\1080' -> 'y' : change2BS (y : z : xs)
'\1081' -> 'j' : change2BS (y : z : xs)
'\1082' -> 'k' : change2BS (y : z : xs)
_ -> x : change2BS (y : z : xs)
else
case x of
'\1083' -> 'l' : change2BS (y : z : xs)
'\1084' -> 'm' : change2BS (y : z : xs)
_ -> x : change2BS (y : z : xs)
else
if x <= '\1075' then
if x >= '\1074' then
case x of
'\1074' -> 'v' : change2BS (y : z : xs)
'\1075' -> 'A' : change2BS (y : z : xs)
_ -> x : change2BS (y : z : xs)
else
case x of
'\'' -> 'K' : change2BS (y : z : xs)
'\1072' -> 'a' : change2BS (y : z : xs)
'\1073' -> 'b' : change2BS (y : z : xs)
_ -> x : change2BS (y : z : xs)
else
if x <= '\1077' then
case x of
'\1076' -> 'd' : change2BS (y : z : xs)
'\1077' -> 'e' : change2BS (y : z : xs)
_ -> x : change2BS (y : z : xs)
else
case x of
'\1078' -> 'E' : change2BS (y : z : xs)
'\1079' -> 'z' : change2BS (y : z : xs)
_ -> x : change2BS (y : z : xs)
| x <= '\1097' =
if x >= '\1093' then
if x >= '\1096' then
case x of
'\1096' -> 'B' : change2BS (y : z : xs)