phonetic-languages-ukrainian-array 0.1.0.0 → 0.2.0.0
raw patch · 3 files changed
+41/−11 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Phonetic.Languages.Ukrainian.PrepareText: growLinesN :: Int -> [String] -> [String]
+ Phonetic.Languages.Ukrainian.PrepareText: prepareGrowTextN :: Int -> String -> [String]
Files
- ChangeLog.md +4/−0
- Phonetic/Languages/Ukrainian/PrepareText.hs +36/−10
- phonetic-languages-ukrainian-array.cabal +1/−1
ChangeLog.md view
@@ -3,3 +3,7 @@ ## 0.1.0.0 -- 2020-12-31 * First version. Released on an unsuspecting world.++## 0.2.0.0 -- 2021-07-24++* Second version. Added two new functions to 'grow' the lines to the needed value. Some code improvements.
Phonetic/Languages/Ukrainian/PrepareText.hs view
@@ -1,6 +1,6 @@ -- | -- Module : Phonetic.Languages.Ukrainian.PrepareText--- Copyright : (c) OleksandrZhabenko 2020+-- Copyright : (c) OleksandrZhabenko 2020-2021 -- License : MIT -- Stability : Experimental -- Maintainer : olexandr543@yahoo.com@@ -23,9 +23,7 @@ module Phonetic.Languages.Ukrainian.PrepareText ( -- * Basic functions- prepareText- , prepareTextN- , complexWords+ complexWords , splitLines , splitLinesN , auxiliary1@@ -34,6 +32,11 @@ , isSpC , concatenated2 , jottedConv+ -- * The end-user functions+ , prepareText+ , prepareTextN+ , growLinesN+ , prepareGrowTextN -- * Used to transform after convertToProperUkrainian from mmsyn6ukr package , aux4 ) where@@ -42,6 +45,7 @@ import Data.List.InnToOut.Basic (mapI) import Data.Char (isAlpha,toLower) import GHC.Arr+import GHC.List (scanl1) -- | Is used to convert a Ukrainian text into list of 'String' each of which is ready to be -- used by the functions from the other modules in the package.@@ -50,7 +54,8 @@ -- to avoid the misinterpretation and preserve maximum of the semantics for the -- \"phonetic\" language on the Ukrainian basis. prepareText :: String -> [String]-prepareText = filter (any isUkrainianL) . splitLines . map (unwords . concatenated2. auxiliary1 . complexWords . words . filter (\t -> isAlpha t || isSpC t)) . filter (not . null) . lines+prepareText = prepareTextN 7+{-# INLINE prepareText #-} -- | Concatenates complex words in Ukrainian so that they are not separated further by possible words order rearrangements (because they are treated -- as a single word). This is needed to preserve basic grammar in phonetic languages.@@ -118,10 +123,8 @@ -- | Since 0.2.1.0 version the function is recursive and is applied so that all returned elements ('String') are no longer than 7 words in them. splitLines :: [String] -> [String]-splitLines xss- | null xss = []- | otherwise = mapI (\xs -> compare (length . words $ xs) 7 == GT) (\xs -> let yss = words xs in- splitLines . map unwords . (\(q,r) -> [q,r]) . splitAt (length yss `quot` 2) $ yss) $ xss+splitLines = splitLinesN 7+{-# INLINE splitLines #-} -- | A generalized variant of the 'splitLines' with the arbitrary maximum number of the words in the lines given as the first argument. splitLinesN :: Int -> [String] -> [String]@@ -260,4 +263,27 @@ -- | Is taken from the @mmsyn6ukr@ package version 0.8.1.0 so that the amount of dependencies are reduced (and was slightly modified). isUkrainianL :: Char -> Bool isUkrainianL y | (y >= '\1040' && y <= '\1065') || (y >= '\1070' && y <= '\1097') = True- | otherwise = getBFstL' False (map (\x -> (x, True)) $ "\1028\1030\1031\1068\1100\1102\1103\1108\1110\1111\1168\1169\8217") y+ | otherwise = getBFstL' False (map (\x -> (x, True)) $ "\1028\1030\1031\1068\1100\1102\1103\1108\1110\1111\1168\1169\8217") y++-------------------------------------++{-| @ since 0.2.0.0+Given a positive number and a list tries to rearrange the list's 'String's by concatenation of the several elements of the list+so that the number of words in every new 'String' in the resulting list is not greater than the 'Int' argument. If some of the+'String's have more than that number quantity of the words then these 'String's are preserved.+-}+growLinesN :: Int -> [String] -> [String]+growLinesN n xss+ | null xss || n < 0 = []+ | otherwise = unwords yss : growLinesN n zss+ where l = length . takeWhile (<= n) . scanl1 (+) . map (length . words) $ xss -- the maximum number of lines to be taken+ (yss,zss) = splitAt (max l 1) xss++{-| @ since 0.2.0.0+The function combines the 'prepareTextN' and 'growLinesN' function. Applies needed phonetic language preparations+to the Ukrainian text and tries to \'grow\' the resulting 'String's in the list so that the number of the words in every+of them is no greater than the given 'Int' number. +-} +prepareGrowTextN :: Int -> String -> [String]+prepareGrowTextN n = growLinesN n . prepareTextN n+{-# INLINE prepareGrowTextN #-}
phonetic-languages-ukrainian-array.cabal view
@@ -2,7 +2,7 @@ -- further documentation, see http://haskell.org/cabal/users-guide/ name: phonetic-languages-ukrainian-array-version: 0.1.0.0+version: 0.2.0.0 synopsis: Prepares Ukrainian text to be used as a phonetic language text description: Prepares Ukrainian text to be used as a phonetic language text. Applies needed minimal grammar connections so that the text afterwards can be processed by dobutokO-poetry related programs. Uses arrays instead of vectors. homepage: https://hackage.haskell.org/package/phonetic-languages-ukrainian-array