ukrainian-phonetics-basic 0.1.9.0 → 0.1.10.0
raw patch · 3 files changed
+48/−31 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- CHANGELOG.md +4/−0
- Melodics/ByteString/Ukrainian.hs +43/−30
- ukrainian-phonetics-basic.cabal +1/−1
CHANGELOG.md view
@@ -41,3 +41,7 @@ * First version revised I. Fixed issues with separating soft sign from the processed sound combinations inside the Melodics.ByteString.Ukrainian module. +## 0.1.10.0 -- 2020-11-06++* First version revised J. Fixed issues with rare complex letter combinations in the Melodics.ByteString.Ukrainian module. The applyChanges uses now strict in the accumulator +version of the foldr -- foldr'.
Melodics/ByteString/Ukrainian.hs view
@@ -35,6 +35,7 @@ import qualified Data.Vector.Unboxed as V import qualified Data.Vector as VB import qualified Data.ByteString.Char8 as B+import qualified Data.Foldable as F import CaseBi.Unboxed (getBFst') import qualified CaseBi as X (getBFst') import Data.List.InnToOut.Basic (mapI)@@ -49,35 +50,35 @@ -- | The function that converts a written Ukrainian text into the sounding in the program phonetical respesentation. -- It is not exact phonetically but you can make for yourself a general impression of the Ukrainian sounding. convertToProperUkrainian :: String -> V.Vector Char-convertToProperUkrainian ys = toVector . convertToProperUkrainianS $ ys+convertToProperUkrainian = toVector . convertToProperUkrainianS {-# INLINE convertToProperUkrainian #-} -- | The function that converts a written Ukrainian text into the sounding in the program phonetical respesentation. -- It is not exact phonetically but you can make for yourself a general impression of the Ukrainian sounding. convertToProperUkrainianV :: VB.Vector Char -> V.Vector Char-convertToProperUkrainianV v = toVector . convertToProperUkrainianV2S $ v+convertToProperUkrainianV = toVector . convertToProperUkrainianV2S {-# INLINE convertToProperUkrainianV #-} -- | Unlike the 'convertToProperUkrainian', it returns a boxed 'VB.Vector' instead of unboxed one 'V.Vector', -- @ since 0.1.2.0 convertToProperUkrainianX :: String -> VB.Vector Char-convertToProperUkrainianX ys = toVectorB . convertToProperUkrainianS $ ys+convertToProperUkrainianX = toVectorB . convertToProperUkrainianS {-# INLINE convertToProperUkrainianX #-} -- | Unlike the 'convertToProperUkrainianV', it returns a boxed 'VB.Vector' instead of unboxed one 'V.Vector', -- @ since 0.1.2.0 convertToProperUkrainianV2X :: VB.Vector Char -> VB.Vector Char-convertToProperUkrainianV2X v = toVectorB . convertToProperUkrainianV2S $ v+convertToProperUkrainianV2X = toVectorB . convertToProperUkrainianV2S {-# INLINE convertToProperUkrainianV2X #-} convertToProperUkrainianS :: String -> String-convertToProperUkrainianS ys = correctB . correctA . applyChanges . bsToCharUkr . createTuplesByAnalysis . secondConv . filterUkr . changeJotted .- filter (\x -> isUkrainianL x || isSpace x || isControl x || isPunctuation x) . map toLower $ ys+convertToProperUkrainianS = correctB . correctA . applyChanges . bsToCharUkr . createTuplesByAnalysis . secondConv . filterUkr . changeIotated .+ filter (\x -> isUkrainianL x || isSpace x || isControl x || isPunctuation x) . map toLower {-# INLINE convertToProperUkrainianS #-} convertToProperUkrainianV2S :: VB.Vector Char -> String-convertToProperUkrainianV2S v = correctB . correctA . applyChanges . bsToCharUkr . createTuplesByAnalysis . secondConv . filterUkr . changeJotted . VB.toList .- VB.filter (\x -> isUkrainianL x || isSpace x || isControl x || isPunctuation x) . VB.map toLower $ v+convertToProperUkrainianV2S = correctB . correctA . applyChanges . bsToCharUkr . createTuplesByAnalysis . secondConv . filterUkr . changeIotated . VB.toList .+ VB.filter (\x -> isUkrainianL x || isSpace x || isControl x || isPunctuation x) . VB.map toLower {-# INLINE convertToProperUkrainianV2S #-} isUkrainianL :: Char -> Bool@@ -85,15 +86,15 @@ | otherwise = getBFst' (False, V.fromList . map (\x -> (x, True)) $ "'-\700\1028\1030\1031\1068\1100\1102\1103\1108\1110\1111\1168\1169\8217") y {-# INLINE isUkrainianL #-} -changeJotted :: String -> String-changeJotted (x:y:zs)+changeIotated :: String -> String+changeIotated (x:y:zs) | (y `elem` ("\1102\1103\1108\1110"::String)) && isConsNotJ x = x:'\1100':(case y of '\1102' -> '\1091' '\1103' -> '\1072' '\1108' -> '\1077'- _ -> '\1110'):changeJotted zs- | otherwise = x:changeJotted (y:zs)-changeJotted xs = xs+ _ -> '\1110'):changeIotated zs+ | otherwise = x:changeIotated (y:zs)+changeIotated xs = xs isConsNotJ :: Char -> Bool isConsNotJ = getBFst' (False, V.fromList $ zip "\1073\1074\1075\1076\1078\1079\1082\1083\1084\1085\1087\1088\1089\1090\1092\1093\1094\1095\1096\1097\1169" (repeat True))@@ -152,27 +153,38 @@ applyChanges :: [(Char, Triple)] -> [(Char, Triple)] applyChanges [] = []-applyChanges [(x, _)] = [(x, Z)]-applyChanges xs- | snd z == T =- X.getBFst' ((fst z, Z), VB.fromList . zip "ABDEFNOPcdfhkpstwxz" $- [дзT zs, жT zs, сьT zs, чT zs, шT zs, нтT zs, стT zs, тьT zs, цT zs, дT zs, фT zs, гT zs, кT zs, пT zs, сT zs, тT zs, цьT zs, хT zs, зT zs]) (fst z):applyChanges zs- | otherwise = z:applyChanges zs- where z = head xs- zs = tail xs+applyChanges ys = F.foldr' f v ys+ where v = []+ f x xs+ | null xs = (:[]) . (\(y,_) -> (y, Z)) $ x+ | snd x == T =+ X.getBFst' ((fst x, Z), VB.fromList . zip "ABDEFNOPcdfhkpstwxz" $ [дзT xs, жT xs, сьT xs, чT xs, шT xs, нтT xs, стT xs, тьT xs,+ цT xs, дT xs, фT xs, гT xs, кT xs, пT xs, сT xs, тT xs, цьT xs, хT xs, зT xs]) (fst x):xs+ | otherwise = x:xs isVoicedObstruent :: B.ByteString -> Bool isVoicedObstruent = X.getBFst' (False, VB.fromList [("A",True),("B",True),("Q",True),("R",True),("T",True),("b",True),("d",True),("g",True),("h",True), ("j",True),("z", True)]) . B.take 1+{-# INLINE isVoicedObstruent #-} +isVoicedObstruentH :: B.ByteString -> Bool+isVoicedObstruentH = X.getBFst' (False, VB.fromList [("A",True),("B",True),("b",True),("d",True),("g",True),("h",True),("j",True),("z", True)]) . B.take 1+{-# INLINE isVoicedObstruentH #-}++isVoicedObstruentS :: B.ByteString -> Bool+isVoicedObstruentS = (`elem` ["Q","R","T"]) . B.take 1+{-# INLINE isVoicedObstruentS #-}+ isSoftDOrL :: [(Char, Triple)] -> Bool isSoftDOrL xs = X.getBFst' (False, VB.fromList . zip ["bq","cq","dq","fq","lq","mq","nq","pq","sq","tq","vq"] $ (repeat True)) (takeFromFT_ 2 xs) || X.getBFst' (False, VB.fromList . zip ["P","Q","R","S","T"] . repeat $ True) (takeFromFT_ 1 xs)+{-# INLINE isSoftDOrL #-} isSoftDen :: [(Char, Triple)] -> Bool isSoftDen xs = X.getBFst' (False, VB.fromList . zip ["Aq","cq","dq","lq","nq","sq","tq","zq"] $ (repeat True)) (takeFromFT_ 2 xs) || X.getBFst' (False, VB.fromList . zip ["P","Q","R","S","T"] . repeat $ True) (takeFromFT_ 1 xs)+{-# INLINE isSoftDen #-} -- in the further ??T functions the last (, T) means that it must be afterwards be separated with the soft sign into two tuples (1 additional function in the composition) -- need further processing means that there should be additional checks and may be transformations. May be they can be omitted@@ -226,8 +238,8 @@ пT _ = ('p', Z) сT :: [(Char, Triple)] -> (Char, Triple)-сT t1@(_:_) | ((isVoicedObstruent . takeFromFT_ 1 $ t1) && B.drop 1 (takeFromFT_ 2 t1) == "q") = ('R', T)- | isVoicedObstruent . takeFromFT_ 1 $ t1 = ('b', Z)+сT t1@(_:_) | ((isVoicedObstruentH . takeFromFT_ 1 $ t1) && B.drop 1 (takeFromFT_ 2 t1) == "q") || isVoicedObstruentS (takeFromFT_ 1 t1) = ('R', T)+ | isVoicedObstruentH . takeFromFT_ 1 $ t1 = ('z', Z) | isSoftDOrL t1 = ('D', Z) | takeFromFT_ 1 t1 == "F" = ('F', Z) | otherwise = ('s', Z)@@ -247,8 +259,8 @@ сьT _ = ('D', Z) тT :: [(Char, Triple)] -> (Char, Triple)-тT t1@(_:_) | (isVoicedObstruent . takeFromFT_ 1 $ t1) && B.drop 1 (takeFromFT_ 2 t1) == "q" = ('T', T)- | isVoicedObstruent . takeFromFT_ 1 $ t1 = ('d', Z)+тT t1@(_:_) | ((isVoicedObstruentH . takeFromFT_ 1 $ t1) && B.drop 1 (takeFromFT_ 2 t1) == "q") || isVoicedObstruentS (takeFromFT_ 1 t1) = ('T', T)+ | isVoicedObstruentH . takeFromFT_ 1 $ t1 = ('d', Z) | takeFromFT_ 2 t1 == "cq" || takeFromFT_ 1 t1 == "w" = ('w', Z) | takeFromFT_ 1 t1 == "c" = ('c', Z) | isSoftDen t1 = ('P', T)@@ -273,9 +285,9 @@ хT _ = ('х', Z) цT :: [(Char, Triple)] -> (Char, Triple)-цT t1@(_:_) | (isVoicedObstruent . takeFromFT_ 1 $ t1) && B.drop 1 (takeFromFT_ 2 t1) == "q" = ('Q', T)+цT t1@(_:_) | ((isVoicedObstruentH . takeFromFT_ 1 $ t1) && B.drop 1 (takeFromFT_ 2 t1) == "q") || isVoicedObstruentS (takeFromFT_ 1 t1) = ('Q', T) | isSoftDOrL t1 = ('w', Z)- | isVoicedObstruent . takeFromFT_ 1 $ t1 = ('A', Z)+ | isVoicedObstruentH . takeFromFT_ 1 $ t1 = ('A', Z) | otherwise = ('c', Z) цT _ = ('c', Z) @@ -326,10 +338,11 @@ {-# INLINE separateSoftS #-} correctSomeW :: [Char] -> [Char]-correctSomeW (x:y:z:xs) | x == 'w' && y == 'D' && z == 'a' = x:'w':z:correctSomeW xs- | (x == '1' || x == '0') && y == 'C' && z == 'a' =+correctSomeW (x:y:z:xs@(t:ys))+ | x == 't' && y == 'q' && z == 'D' && t == 'a' = 'w':'w':'a':correctSomeW ys+ | (x == '1' || x == '0') && y == 'C' && z == 'a' = if take 2 xs == "En"- then x:y:z:'F':correctSomeW (tail xs)+ then x:y:z:'F':correctSomeW ys else x:correctSomeW (y:z:xs) | otherwise = x:correctSomeW (y:z:xs) correctSomeW zs = zs
ukrainian-phonetics-basic.cabal view
@@ -2,7 +2,7 @@ -- further documentation, see http://haskell.org/cabal/users-guide/ name: ukrainian-phonetics-basic-version: 0.1.9.0+version: 0.1.10.0 synopsis: A library to work with the basic Ukrainian phonetics and syllable segmentation. description: A library to work with the basic Ukrainian phonetics and syllable segmentation. Rewritten from the mmsyn6ukr and mmsyn7s packages. homepage: https://hackage.haskell.org/package/ukrainian-phonetics-basic