packages feed

dobutokO-poetry 0.6.0.0 → 0.7.0.0

raw patch · 10 files changed

+605/−251 lines, 10 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- DobutokO.Poetry: type Uniqueness = ([Int], Vector Int, String)
- DobutokO.Poetry: uniqInMaxPoetical :: Vector ([Int], Int, Int, Int, String) -> IO (Vector ([Int], Int, Int, Int, String))
- DobutokO.Poetry: uniqInMaxPoeticalN :: Int -> Vector ([Int] -> Int) -> Vector Uniqueness -> IO (Vector Uniqueness)
- DobutokO.Poetry: uniqInMaxPoeticalNLine :: Int -> Vector ([Int] -> Int) -> Vector Uniqueness -> IO (Vector Uniqueness)
- DobutokO.Poetry: uniqMaxPoeticalG :: ([Int] -> Int) -> String -> ([Int], Int, Int, Int, String)
- DobutokO.Poetry: uniqMaxPoeticalGNV :: Int -> Vector ([Int] -> Int) -> Vector Uniqueness -> Uniqueness
- DobutokO.Poetry: uniqNPoetical :: Int -> Vector ([Int], Int, Int, Int, String) -> IO ()
- DobutokO.Poetry: uniqNPoeticalN :: Int -> Int -> Vector ([Int] -> Int) -> Vector Uniqueness -> IO ()
- DobutokO.Poetry: uniqNPoeticalNLine :: Int -> Int -> Vector ([Int] -> Int) -> Vector Uniqueness -> IO ()
- DobutokO.Poetry: uniqNPoeticalV :: Int -> Vector ([Int], Int, Int, Int, String) -> IO (Vector ([Int], Int, Int, Int, String))
- DobutokO.Poetry: uniqNPoeticalVG :: Int -> ([Int] -> Int) -> String -> IO (Vector ([Int], Int, Int, Int, String))
- DobutokO.Poetry: uniqNPoeticalVN :: Int -> Int -> Vector ([Int] -> Int) -> Vector Uniqueness -> IO (Vector Uniqueness)
- DobutokO.Poetry: uniquenessVariants2GN :: Vector ([Int] -> Int) -> (String -> [Int]) -> String -> Vector Uniqueness
- DobutokO.Poetry: uniquenessVariants3 :: String -> Vector ([Int], Int, Int, Int, String)
- DobutokO.Poetry: uniquenessVariants4 :: String -> Vector ([Int], Int, Int, Int, String)
- DobutokO.Poetry: uniquenessVariantsG :: ([Int] -> Int) -> String -> Vector ([Int], Int, Int, Int, String)
- DobutokO.Poetry.Auxiliary: fourFrom5 :: (a, b, b, b, c) -> (a, b, b, b)
- DobutokO.Poetry.Auxiliary: lastFrom5 :: (a, b, b, b, c) -> c
- DobutokO.Poetry.Auxiliary: twoFrom3 :: (a, b, c) -> (a, b)
+ DobutokO.Poetry: uniqMaxPoetical2GNL :: Vector ([Int] -> Int) -> (String -> [Int]) -> String -> Uniqueness
+ DobutokO.Poetry: uniqMaxPoeticalGNL :: Vector ([Int] -> Int) -> String -> Uniqueness
+ DobutokO.Poetry: uniqNPoetical2GNL :: Int -> Vector ([Int] -> Int) -> (String -> [Int]) -> String -> IO ()
+ DobutokO.Poetry: uniqNPoetical2GNLineL :: Int -> Vector ([Int] -> Int) -> (String -> [Int]) -> String -> IO ()
+ DobutokO.Poetry: uniqNPoetical2VGNL :: Int -> Vector ([Int] -> Int) -> (String -> [Int]) -> String -> IO (Vector Uniqueness)
+ DobutokO.Poetry: uniqNPoeticalGNL :: Int -> Vector ([Int] -> Int) -> String -> IO ()
+ DobutokO.Poetry: uniqNPoeticalUGNL :: Int -> Int -> Vector ([Int] -> Int) -> String -> IO (Vector Uniqueness)
+ DobutokO.Poetry: uniqNPoeticalUGNL_ :: Int -> Int -> Vector ([Int] -> Int) -> String -> IO ()
+ DobutokO.Poetry: uniqNPoeticalVGNL :: Int -> Vector ([Int] -> Int) -> String -> IO (Vector Uniqueness)
+ DobutokO.Poetry.Basic: type Uniqueness = ([Int], Vector Int, String)
+ DobutokO.Poetry.Basic: uniqInMaxPoeticalN :: Int -> Vector ([Int] -> Int) -> Vector Uniqueness -> IO (Vector Uniqueness)
+ DobutokO.Poetry.Basic: uniqInMaxPoeticalNL :: Vector ([Int] -> Int) -> Vector Uniqueness -> IO (Vector Uniqueness)
+ DobutokO.Poetry.Basic: uniqInMaxPoeticalNLine :: Int -> Vector ([Int] -> Int) -> Vector Uniqueness -> IO (Vector Uniqueness)
+ DobutokO.Poetry.Basic: uniqInMaxPoeticalNLineL :: Vector ([Int] -> Int) -> Vector Uniqueness -> IO (Vector Uniqueness)
+ DobutokO.Poetry.Basic: uniqMaxPoeticalGNV :: Int -> Vector ([Int] -> Int) -> Vector Uniqueness -> Uniqueness
+ DobutokO.Poetry.Basic: uniqMaxPoeticalGNVL :: Vector ([Int] -> Int) -> Vector Uniqueness -> Uniqueness
+ DobutokO.Poetry.Basic: uniqNPoeticalN :: Int -> Int -> Vector ([Int] -> Int) -> Vector Uniqueness -> IO ()
+ DobutokO.Poetry.Basic: uniqNPoeticalNL :: Int -> Vector ([Int] -> Int) -> Vector Uniqueness -> IO ()
+ DobutokO.Poetry.Basic: uniqNPoeticalNLine :: Int -> Int -> Vector ([Int] -> Int) -> Vector Uniqueness -> IO ()
+ DobutokO.Poetry.Basic: uniqNPoeticalNLineL :: Int -> Vector ([Int] -> Int) -> Vector Uniqueness -> IO ()
+ DobutokO.Poetry.Basic: uniqNPoeticalVN :: Int -> Int -> Vector ([Int] -> Int) -> Vector Uniqueness -> IO (Vector Uniqueness)
+ DobutokO.Poetry.Basic: uniqNPoeticalVNL :: Int -> Vector ([Int] -> Int) -> Vector Uniqueness -> IO (Vector Uniqueness)
+ DobutokO.Poetry.PrependAppend: uniq10Poetical4 :: String -> String -> String -> IO ()
+ DobutokO.Poetry.PrependAppend: uniq10Poetical5 :: String -> String -> String -> IO ()
+ DobutokO.Poetry.PrependAppend: uniq10PoeticalG :: String -> String -> ([Int] -> Int) -> String -> IO ()
+ DobutokO.Poetry.PrependAppend: uniqInMaxPoeticalN :: Int -> Vector ([Int] -> Int) -> Vector Uniqueness -> IO (Vector Uniqueness)
+ DobutokO.Poetry.PrependAppend: uniqInMaxPoeticalNL :: Vector ([Int] -> Int) -> Vector Uniqueness -> IO (Vector Uniqueness)
+ DobutokO.Poetry.PrependAppend: uniqInMaxPoeticalNLine :: Int -> Vector ([Int] -> Int) -> Vector Uniqueness -> IO (Vector Uniqueness)
+ DobutokO.Poetry.PrependAppend: uniqInMaxPoeticalNLineL :: Vector ([Int] -> Int) -> Vector Uniqueness -> IO (Vector Uniqueness)
+ DobutokO.Poetry.PrependAppend: uniqMaxPoetical2GN :: String -> String -> Int -> Vector ([Int] -> Int) -> (String -> [Int]) -> String -> Uniqueness
+ DobutokO.Poetry.PrependAppend: uniqMaxPoetical2GNL :: String -> String -> Vector ([Int] -> Int) -> (String -> [Int]) -> String -> Uniqueness
+ DobutokO.Poetry.PrependAppend: uniqMaxPoeticalGN :: String -> String -> Int -> Vector ([Int] -> Int) -> String -> Uniqueness
+ DobutokO.Poetry.PrependAppend: uniqMaxPoeticalGNL :: String -> String -> Vector ([Int] -> Int) -> String -> Uniqueness
+ DobutokO.Poetry.PrependAppend: uniqMaxPoeticalGNV :: Int -> Vector ([Int] -> Int) -> Vector Uniqueness -> Uniqueness
+ DobutokO.Poetry.PrependAppend: uniqMaxPoeticalGNVL :: Vector ([Int] -> Int) -> Vector Uniqueness -> Uniqueness
+ DobutokO.Poetry.PrependAppend: uniqNPoetical2GN :: String -> String -> Int -> Int -> Vector ([Int] -> Int) -> (String -> [Int]) -> String -> IO ()
+ DobutokO.Poetry.PrependAppend: uniqNPoetical2GNL :: String -> String -> Int -> Vector ([Int] -> Int) -> (String -> [Int]) -> String -> IO ()
+ DobutokO.Poetry.PrependAppend: uniqNPoetical2GNLine :: String -> String -> Int -> Int -> Vector ([Int] -> Int) -> (String -> [Int]) -> String -> IO ()
+ DobutokO.Poetry.PrependAppend: uniqNPoetical2GNLineL :: String -> String -> Int -> Vector ([Int] -> Int) -> (String -> [Int]) -> String -> IO ()
+ DobutokO.Poetry.PrependAppend: uniqNPoetical2VGN :: String -> String -> Int -> Int -> Vector ([Int] -> Int) -> (String -> [Int]) -> String -> IO (Vector Uniqueness)
+ DobutokO.Poetry.PrependAppend: uniqNPoetical2VGNL :: String -> String -> Int -> Vector ([Int] -> Int) -> (String -> [Int]) -> String -> IO (Vector Uniqueness)
+ DobutokO.Poetry.PrependAppend: uniqNPoeticalG :: String -> String -> Int -> ([Int] -> Int) -> String -> IO ()
+ DobutokO.Poetry.PrependAppend: uniqNPoeticalGN :: String -> String -> Int -> Int -> Vector ([Int] -> Int) -> String -> IO ()
+ DobutokO.Poetry.PrependAppend: uniqNPoeticalGNL :: String -> String -> Int -> Vector ([Int] -> Int) -> String -> IO ()
+ DobutokO.Poetry.PrependAppend: uniqNPoeticalN :: Int -> Int -> Vector ([Int] -> Int) -> Vector Uniqueness -> IO ()
+ DobutokO.Poetry.PrependAppend: uniqNPoeticalNL :: Int -> Vector ([Int] -> Int) -> Vector Uniqueness -> IO ()
+ DobutokO.Poetry.PrependAppend: uniqNPoeticalNLine :: Int -> Int -> Vector ([Int] -> Int) -> Vector Uniqueness -> IO ()
+ DobutokO.Poetry.PrependAppend: uniqNPoeticalNLineL :: Int -> Vector ([Int] -> Int) -> Vector Uniqueness -> IO ()
+ DobutokO.Poetry.PrependAppend: uniqNPoeticalUGN :: String -> String -> Int -> Int -> Int -> Vector ([Int] -> Int) -> String -> IO (Vector Uniqueness)
+ DobutokO.Poetry.PrependAppend: uniqNPoeticalUGN51 :: String -> String -> Int -> Int -> String -> IO (Vector Uniqueness)
+ DobutokO.Poetry.PrependAppend: uniqNPoeticalUGN51_ :: String -> String -> Int -> Int -> String -> IO ()
+ DobutokO.Poetry.PrependAppend: uniqNPoeticalUGNL :: String -> String -> Int -> Int -> Vector ([Int] -> Int) -> String -> IO (Vector Uniqueness)
+ DobutokO.Poetry.PrependAppend: uniqNPoeticalUGNL_ :: String -> String -> Int -> Int -> Vector ([Int] -> Int) -> String -> IO ()
+ DobutokO.Poetry.PrependAppend: uniqNPoeticalUGN_ :: String -> String -> Int -> Int -> Int -> Vector ([Int] -> Int) -> String -> IO ()
+ DobutokO.Poetry.PrependAppend: uniqNPoeticalVGN :: String -> String -> Int -> Int -> Vector ([Int] -> Int) -> String -> IO (Vector Uniqueness)
+ DobutokO.Poetry.PrependAppend: uniqNPoeticalVGNL :: String -> String -> Int -> Vector ([Int] -> Int) -> String -> IO (Vector Uniqueness)
+ DobutokO.Poetry.PrependAppend: uniqNPoeticalVN :: Int -> Int -> Vector ([Int] -> Int) -> Vector Uniqueness -> IO (Vector Uniqueness)
+ DobutokO.Poetry.PrependAppend: uniqNPoeticalVNL :: Int -> Vector ([Int] -> Int) -> Vector Uniqueness -> IO (Vector Uniqueness)
+ DobutokO.Poetry.PrependAppend: uniquenessVariantsGN :: String -> String -> Vector ([Int] -> Int) -> String -> Vector Uniqueness
+ DobutokO.Poetry.StrictV: uniquenessVariants2GN :: Vector ([Int] -> Int) -> (String -> [Int]) -> String -> Vector ([Int], Vector Int, String)
+ DobutokO.Poetry.StrictV: uniquenessVariants2GNP :: String -> String -> Vector ([Int] -> Int) -> (String -> [Int]) -> String -> Vector ([Int], Vector Int, String)

Files

ChangeLog.md view
@@ -36,3 +36,7 @@  * Sixth version. Added three new functions to the DobutokO.Poetry module: uniqInMaxPoeticalNLine, uniqNPoeticalNLine and uniqNPoetical2GNLine. They are  similar to the respective functions without 'Line' ending in their name but prints their output on the same line. ++## 0.7.0.0 -- 2020-07-29++* Seventh version. Changed the module structure. Added new modules and rewritten the old ones. Fixed unexact or not complete documentation for some functions.
DobutokO/Poetry.hs view
@@ -6,36 +6,21 @@ -- Maintainer  :  olexandr543@yahoo.com -- -- Helps to order the 7 or less Ukrainian words (or their concatenations) --- to obtain (to some extent) suitable for poetry or music text. The main --- module in the library that imports all other ones except Main.+-- to obtain (to some extent) suitable for poetry or music text.   {-# LANGUAGE BangPatterns #-}  module DobutokO.Poetry (-  -- * Uniqueness type synonym-  Uniqueness   -- * Main functions-  , uniq10Poetical4+  uniq10Poetical4   , uniq10Poetical5   , uniq10PoeticalG   , uniqNPoeticalG   , uniqNPoeticalGN-  , uniqNPoetical-  , uniqNPoeticalN-  , uniqNPoeticalV-  , uniqNPoeticalVN-  , uniqNPoeticalVG   , uniqNPoeticalVGN   -- * Additional functions-  , uniquenessVariantsG   , uniquenessVariantsGN-  , uniquenessVariants3-  , uniquenessVariants4-  , uniqMaxPoeticalG   , uniqMaxPoeticalGN-  , uniqMaxPoeticalGNV-  , uniqInMaxPoetical-  , uniqInMaxPoeticalN   -- * Generalized variants   -- ** Main ones   , uniqNPoetical2GN@@ -45,83 +30,36 @@   , uniqNPoeticalUGN51_   , uniqNPoeticalUGN51   -- ** Additional functions-  , uniquenessVariants2GN   , uniqMaxPoetical2GN   -- * On one line output-  , uniqInMaxPoeticalNLine-  , uniqNPoeticalNLine   , uniqNPoetical2GNLine+  -- * With all the norms used+  , uniqMaxPoeticalGNL+  , uniqNPoeticalGNL+  , uniqNPoeticalVGNL+  , uniqMaxPoetical2GNL+  , uniqNPoetical2GNL+  , uniqNPoetical2GNLineL+  , uniqNPoetical2VGNL+  , uniqNPoeticalUGNL_+  , uniqNPoeticalUGNL ) where  import Data.Char (isPunctuation) import qualified Data.Vector as V import Data.List ((\\))-import MMSyn7s +import MMSyn7s import DobutokO.Poetry.Norms import DobutokO.Poetry.Auxiliary import DobutokO.Poetry.UniquenessPeriodsG--type Uniqueness = ([Int],V.Vector Int,String)---- | A variant of 'uniquesessVariantsG' with the norm being 'norm3'.-uniquenessVariants3 :: String -> V.Vector ([Int],Int,Int,Int,String)-uniquenessVariants3 = uniquenessVariantsG norm3---- | A variant of 'uniquesessVariantsG' with the norm being 'norm4'.-uniquenessVariants4 :: String -> V.Vector ([Int],Int,Int,Int,String)-uniquenessVariants4 = uniquenessVariantsG norm4---- | Given a 'String' consisting of no more than 7 Ukrainian words [some of them can be created by concatenation with preserving the Ukrainian --- pronunciation of the parts, e. g. \"так як\" (actually two correct Ukrainian words and a single conjunction) can be written \"такйак\" --- (one phonetical Ukrainian word transformed literally with preserving phonetical structure), if you would not like to treat them separately], --- it returns a 'V.Vector' of possible combinations without repeating of the words in different order and for each of them appends also --- the information about 'uniquenessPeriods' to it and finds out three different metrics -- named \"norms\". --- --- Afterwards, depending on these norms it can be specified some phonetical properties of the words that --- allow to use them poetically or to create a varied melody with them. Some variants of this generalized function are 'uniquesessVariants3' and --- 'uniquesessVariants4' with the predefined norms.-uniquenessVariantsG :: ([Int] -> Int) -> String -> V.Vector ([Int],Int,Int,Int,String)-uniquenessVariantsG g xs -  | null xs = V.empty-  | otherwise = -     case V.length . V.fromList . take 7 . words $ xs of -      7 -> -       V.fromList . map ((\vs -> let !rs = uniquenessPeriods vs in (rs, norm1 rs, norm2 rs, g rs, vs)) . unwords . V.toList . -        V.backpermute (V.fromList . take 7 . words $ xs)) $ -         ([V.fromList [x1,x2,x3,x4,x5,x6,x7] | !x1 <- [0..6], !x2 <- [0..6] \\ [x1], !x3 <- [0..6] \\ [x1,x2], !x4 <- [0..6] \\ [x1,x2,x3], -           !x5 <- [0..6] \\ [x1,x2,x3,x4], !x6 <- [0..6] \\ [x1,x2,x3,x4,x5], !x7 <- [0..6] \\ [x1,x2,x3,x4,x5,x6]]::[V.Vector Int])-      6 -> -       V.fromList . map ((\vs -> let rs = uniquenessPeriods vs in (rs, norm1 rs, norm2 rs, g rs, vs)) . unwords . V.toList . -        V.backpermute (V.fromList . take 7 . words $ xs)) $-         ([V.fromList [x1,x2,x3,x4,x5,x6] | !x1 <- [0..5], !x2 <- [0..5] \\ [x1], !x3 <- [0..5] \\ [x1,x2], !x4 <- [0..5] \\ [x1,x2,x3], -           !x5 <- [0..5] \\ [x1,x2,x3,x4], !x6 <- [0..5] \\ [x1,x2,x3,x4,x5]]::[V.Vector Int])-      5 -> -       V.fromList . map ((\vs -> let rs = uniquenessPeriods vs in (rs, norm1 rs, norm2 rs, g rs, vs)) . unwords . V.toList . -        V.backpermute (V.fromList . take 7 . words $ xs)) $-         ([V.fromList [x1,x2,x3,x4,x5] | !x1 <- [0..4], !x2 <- [0..4] \\ [x1], !x3 <- [0..4] \\ [x1,x2], !x4 <- [0..4] \\ [x1,x2,x3], -            !x5 <- [0..4] \\ [x1,x2,x3,x4]]::[V.Vector Int])-      4 -> -       V.fromList . map ((\vs -> let rs = uniquenessPeriods vs in (rs, norm1 rs, norm2 rs, g rs, vs)) . unwords . V.toList . -        V.backpermute (V.fromList . take 7 . words $ xs)) $-         ([V.fromList [x1,x2,x3,x4] | !x1 <- [0..3], !x2 <- [0..3] \\ [x1], !x3 <- [0..3] \\ [x1,x2], !x4 <- [0..3] \\ [x1,x2,x3]]::[V.Vector Int])-      3 -> -       V.fromList . map ((\vs -> let rs = uniquenessPeriods vs in (rs, norm1 rs, norm2 rs, g rs, vs)) . unwords . V.toList . -        V.backpermute (V.fromList . take 7 . words $ xs)) $ ([V.fromList [x1,x2,x3] | !x1 <- [0..2], !x2 <- [0..2] \\ [x1], -          !x3 <- [0..2] \\ [x1,x2]]::[V.Vector Int])-      2 -> -       V.fromList . map ((\vs -> let rs = uniquenessPeriods vs in (rs, norm1 rs, norm2 rs, g rs, vs)) . unwords . V.toList . -        V.backpermute (V.fromList . take 7 . words $ xs)) $ ([V.fromList [x1,x2] | !x1 <- [0,1], !x2 <- [0,1] \\ [x1]]::[V.Vector Int])-      _ -> V.empty+import DobutokO.Poetry.StrictV+import DobutokO.Poetry.Basic  -- | Generalization of the 'uniquenessVariantsG' with usage of several norms (instead of one). They constitute a 'V.Vector' of functions  -- @norm :: [Int] -> Int@. So the inner vector in the each resulting 'Uniqueness' has the same length as the vector of norms. uniquenessVariantsGN :: V.Vector ([Int] -> Int) -> String -> V.Vector Uniqueness uniquenessVariantsGN vN = uniquenessVariants2GN vN (uniquenessPeriods)-  --- | Given a norm and a Ukrainian 'String' consisting of no more than 7 words (see also the information for 'uniquenessVariantG'), returns the maximum by the--- specified norm element of the 'uniquenessVariantsG' applied to the same arguments.-uniqMaxPoeticalG :: ([Int] -> Int) ->  String -> ([Int],Int,Int,Int,String)-uniqMaxPoeticalG g = V.maximumBy (\(_,_,_,x30,_) (_,_,_,x31,_) -> compare x30 x31) . uniquenessVariantsG g+{-# INLINE uniquenessVariantsGN #-}  -- | Generalized variant of the 'uniqMaxPoeticalG' with the several norms given as a 'V.Vector' of functions and an 'Int' parameter. The function evaluates  -- the generated 'V.Vector' of 'Uniqueness' elements to retrieve the possibly maximum element in it with respect to the order and significance (principality) @@ -129,207 +67,152 @@ -- minus 1, then less significant is the next to the left norm and so on. uniqMaxPoeticalGN :: Int -> V.Vector ([Int] -> Int) ->  String -> Uniqueness uniqMaxPoeticalGN k vN = uniqMaxPoetical2GN k vN (uniquenessPeriods)---- | Similar to 'uniqMaxPoeticalG' but instead of resulting in a maximum element, outputs it by parts and returns the rest of the 'V.Vector' without this --- maximum element.-uniqInMaxPoetical :: V.Vector ([Int],Int,Int,Int,String) -> IO (V.Vector ([Int],Int,Int,Int,String))-uniqInMaxPoetical v = do-  let !uniq = V.maximumBy (\(_,_,_,x30,_) (_,_,_,x31,_) -> compare x30 x31) v-  putStrLn (filter (not . isPunctuation) . lastFrom5 $ uniq) >> print (fourFrom5 uniq) >> putStrLn "" -  return . V.filter (/= uniq) $ v+{-# INLINE uniqMaxPoeticalGN #-} --- | Generalized variant of the 'uniqInMaxPoetical' with usage of the several norms. -uniqInMaxPoeticalN :: Int -> V.Vector ([Int] -> Int) -> V.Vector Uniqueness -> IO (V.Vector Uniqueness)-uniqInMaxPoeticalN k vN v = do-  let !uniq = uniqMaxPoeticalGNV k vN v-  putStrLn (filter (not . isPunctuation) . lastFrom3 $ uniq) >> print (twoFrom3 uniq) >> putStrLn "" -  return . V.filter (/= uniq) $ v  +-- | Variant of 'uniqMaxPoeticalGN' where all the elements in the norms 'V.Vector' are used as norms from right to left.+uniqMaxPoeticalGNL :: V.Vector ([Int] -> Int) ->  String -> Uniqueness+uniqMaxPoeticalGNL vN = uniqMaxPoeticalGN (V.length vN) vN+{-# INLINE uniqMaxPoeticalGNL #-} --- | Generalized variant of the 'uniqInMaxPoetical' with usage of the several norms and all the information is printed on the same line. -uniqInMaxPoeticalNLine :: Int -> V.Vector ([Int] -> Int) -> V.Vector Uniqueness -> IO (V.Vector Uniqueness)-uniqInMaxPoeticalNLine k vN v = do-  let !uniq = uniqMaxPoeticalGNV k vN v-  putStr (filter (not . isPunctuation) . lastFrom3 $ uniq) >> putStr " " -  return . V.filter (/= uniq) $ v    +-- | A variant of the 'uniqNPoeticalGN' with only one norm.+uniqNPoeticalG :: Int -> ([Int] -> Int) -> String -> IO ()+uniqNPoeticalG n g = uniqNPoeticalGN n 1 (V.singleton g)+{-# INLINE uniqNPoeticalG #-}  -- | A variant of the 'uniqNPoeticalG' function with the @n@ equal to 10. uniq10PoeticalG :: ([Int] -> Int) -> String -> IO () uniq10PoeticalG = uniqNPoeticalG 10+{-# INLINE uniq10PoeticalG #-}  -- | A variant of 'uniq10PoeticalG' with the 'norm4' applied. The list is (according to some model, not universal, but a reasonable one in the most cases) the  -- most suitable for intonation changing and, therefore, for the accompaniment of the highly changable or variative melody. uniq10Poetical4 :: String -> IO () uniq10Poetical4 = uniq10PoeticalG norm4+{-# INLINE uniq10Poetical4 #-}  -- | A variant of 'uniq10PoeticalG' with the 'norm5' applied. The list is (according to some model, not universal, but a reasonable one in the most cases) the  -- most suitable for rhythmic speech and two-syllabilistic-based poetry. Therefore, it can be used to create a poetic composition or to emphasize some  -- thoughts. uniq10Poetical5 :: String -> IO () uniq10Poetical5 = uniq10PoeticalG norm5---- | Recursive @n :: Int@ times application of the 'uniqInMaxPoetical' function. Prints @n@ (or less if there are less of them) maximum elements starting from --- the first and further to the rest. The norm given defines the way, in which the elements are considered the \"maximum\" ones.-uniqNPoetical :: Int -> V.Vector ([Int],Int,Int,Int,String) -> IO ()-uniqNPoetical n v - | n == 0 = return ()- | compare (V.length v) n == LT = V.mapM_ (\x -> putStrLn (filter (not . isPunctuation) . lastFrom5 $ x) >> print (fourFrom5 x) >> putStrLn "" ) v- | otherwise = (uniqInMaxPoetical v >>= uniqNPoetical (n - 1))---- | Generalized variant of the 'uniqNPoetical' with usage of several norms. -uniqNPoeticalN :: Int -> Int -> V.Vector ([Int] -> Int) -> V.Vector Uniqueness -> IO ()-uniqNPoeticalN n k vN v - | n == 0 = return ()- | compare (V.length v) n == LT = V.mapM_ (\x -> putStrLn (filter (not . isPunctuation) . lastFrom3 $ x) >> print (twoFrom3 x) >> putStrLn "" ) v- | otherwise = (uniqInMaxPoeticalN k vN v >>= uniqNPoeticalN (n - 1) k vN) ---- | Generalized variant of the 'uniqNPoetical' with usage of several norms but prints it output on the one line. -uniqNPoeticalNLine :: Int -> Int -> V.Vector ([Int] -> Int) -> V.Vector Uniqueness -> IO ()-uniqNPoeticalNLine n k vN v - | n == 0 = putStrLn ""- | compare (V.length v) n == LT = V.mapM_ (\x -> putStr (filter (not . isPunctuation) . lastFrom3 $ x) >> putStr " " ) v  >> putStrLn ""- | otherwise = (uniqInMaxPoeticalNLine k vN v >>= uniqNPoeticalNLine (n - 1) k vN) ---- | The result of the recursive @n :: Int@ times application of the 'uniqInMaxPoetical' function. The norm given defines the way, in which the elements --- are considered the \"maximum\" ones.-uniqNPoeticalV :: Int -> V.Vector ([Int],Int,Int,Int,String) -> IO (V.Vector ([Int],Int,Int,Int,String))-uniqNPoeticalV n v - | n == 0 || compare (V.length v) n == LT = return v- | otherwise = (uniqInMaxPoetical v >>= uniqNPoeticalV (n - 1)) ---- | Generalized variant of the 'uniqNPoeticalV' with usage of several norms. -uniqNPoeticalVN :: Int -> Int -> V.Vector ([Int] -> Int) -> V.Vector Uniqueness -> IO (V.Vector Uniqueness)-uniqNPoeticalVN n k vN v - | n == 0 || compare (V.length v) n == LT = return v- | otherwise = (uniqInMaxPoeticalN k vN v >>= uniqNPoeticalVN (n - 1) k vN)  ---- | Recursive @n :: Int@ times application of the 'uniqInMaxPoetical' function after the 'uniquenessVariantsG' application to the 'String'. --- Prints @n@ (or less if there are less of them) maximum elements starting from the first and further to the rest. The norm given defines the way, --- in which the elements are considered the \"maximum\" ones.-uniqNPoeticalG :: Int -> ([Int] -> Int) -> String -> IO ()-uniqNPoeticalG n g xs - | n == 0 = return ()- | otherwise = do -   let v = uniquenessVariantsG g xs-   if compare (V.length v) n == LT -     then V.mapM_ (\x -> putStrLn (filter (not . isPunctuation) . lastFrom5 $ x) >> print (fourFrom5 x) >> putStrLn "" ) v -     else (uniqInMaxPoetical v >>= uniqNPoetical (n - 1))+{-# INLINE uniq10Poetical5 #-} --- | Generalized variant of the 'uniqNPoeticalG' with usage of several norms. +-- | Variant of 'uniqNPoeticalVN' where all the elements in the norms 'V.Vector' are used as norms from right to left.+uniqNPoeticalVNL :: Int -> V.Vector ([Int] -> Int) -> V.Vector Uniqueness -> IO (V.Vector Uniqueness)+uniqNPoeticalVNL n vN = uniqNPoeticalVN n (V.length vN) vN+{-# INLINE uniqNPoeticalVNL #-}+ +-- | A variant of the 'uniqNPoetical2GN' with the conversion (\"uniquenessPeriods\" function) function 'uniquenessPeriods'. uniqNPoeticalGN :: Int -> Int -> V.Vector ([Int] -> Int) -> String -> IO ()-uniqNPoeticalGN n k vN = uniqNPoetical2GN n k vN (uniquenessPeriods)    +uniqNPoeticalGN n k vN = uniqNPoetical2GN n k vN (uniquenessPeriods)+{-# INLINE uniqNPoeticalGN #-} --- | The result of the recursive @n :: Int@ times application of the 'uniqInMaxPoetical' function after the 'uniquenessVariantsG' application to the 'String'. --- The norm given defines the way, in which the elements are considered the \"maximum\" ones.-uniqNPoeticalVG :: Int -> ([Int] -> Int) -> String -> IO (V.Vector ([Int],Int,Int,Int,String))-uniqNPoeticalVG n g xs - | n == 0 = return V.empty- | otherwise = do -   let v = uniquenessVariantsG g xs-   if compare (V.length v) n == LT then return v else uniqNPoeticalV n v+-- | Variant of 'uniqNPoeticalGN' where all the elements in the norms 'V.Vector' are used as norms from right to left.+uniqNPoeticalGNL :: Int -> V.Vector ([Int] -> Int) -> String -> IO ()+uniqNPoeticalGNL n vN = uniqNPoetical2GNL n vN (uniquenessPeriods)+{-# INLINE uniqNPoeticalGNL #-}  -- | Generalized variant of the 'uniqNPoeticalVG' with usage of several norms.  uniqNPoeticalVGN :: Int -> Int -> V.Vector ([Int] -> Int) -> String -> IO (V.Vector Uniqueness) uniqNPoeticalVGN n k vN = uniqNPoetical2VGN n k vN (uniquenessPeriods)+{-# INLINE uniqNPoeticalVGN #-} --- | Generalization of the 'uniquenessVariantsG' with usage of several norms (instead of one). They constitute a 'V.Vector' of functions --- @norm :: [Int] -> Int@. So the inner vector in the each resulting 'Uniqueness' has the same length as the vector of norms.-uniquenessVariants2GN :: V.Vector ([Int] -> Int) -> (String -> [Int]) -> String -> V.Vector Uniqueness-uniquenessVariants2GN vN g xs -  | null xs = V.empty-  | otherwise = -     case V.length . V.fromList . take 7 . words $ xs of -      7 -> -       V.fromList . map ((\vs -> let !rs = g vs in (rs, V.map (\f -> f rs) vN, vs)) . unwords . V.toList . -        V.backpermute (V.fromList . take 7 . words $ xs)) $ -         ([V.fromList [x1,x2,x3,x4,x5,x6,x7] | !x1 <- [0..6], !x2 <- [0..6] \\ [x1], !x3 <- [0..6] \\ [x1,x2], !x4 <- [0..6] \\ [x1,x2,x3], -           !x5 <- [0..6] \\ [x1,x2,x3,x4], !x6 <- [0..6] \\ [x1,x2,x3,x4,x5], !x7 <- [0..6] \\ [x1,x2,x3,x4,x5,x6]]::[V.Vector Int])-      6 -> -       V.fromList . map ((\vs -> let rs = g vs in (rs, V.map (\f -> f rs) vN, vs)) . unwords . V.toList . -        V.backpermute (V.fromList . take 7 . words $ xs)) $-         ([V.fromList [x1,x2,x3,x4,x5,x6] | !x1 <- [0..5], !x2 <- [0..5] \\ [x1], !x3 <- [0..5] \\ [x1,x2], !x4 <- [0..5] \\ [x1,x2,x3], -           !x5 <- [0..5] \\ [x1,x2,x3,x4], !x6 <- [0..5] \\ [x1,x2,x3,x4,x5]]::[V.Vector Int])-      5 -> -       V.fromList . map ((\vs -> let rs = g vs in (rs, V.map (\f -> f rs) vN, vs)) . unwords . V.toList . -        V.backpermute (V.fromList . take 7 . words $ xs)) $-         ([V.fromList [x1,x2,x3,x4,x5] | !x1 <- [0..4], !x2 <- [0..4] \\ [x1], !x3 <- [0..4] \\ [x1,x2], !x4 <- [0..4] \\ [x1,x2,x3], -            !x5 <- [0..4] \\ [x1,x2,x3,x4]]::[V.Vector Int])-      4 -> -       V.fromList . map ((\vs -> let rs = g vs in (rs, V.map (\f -> f rs) vN, vs)) . unwords . V.toList . -        V.backpermute (V.fromList . take 7 . words $ xs)) $-         ([V.fromList [x1,x2,x3,x4] | !x1 <- [0..3], !x2 <- [0..3] \\ [x1], !x3 <- [0..3] \\ [x1,x2], !x4 <- [0..3] \\ [x1,x2,x3]]::[V.Vector Int])-      3 -> -       V.fromList . map ((\vs -> let rs = g vs in (rs, V.map (\f -> f rs) vN, vs)) . unwords . V.toList . -        V.backpermute (V.fromList . take 7 . words $ xs)) $ ([V.fromList [x1,x2,x3] | !x1 <- [0..2], !x2 <- [0..2] \\ [x1], -          !x3 <- [0..2] \\ [x1,x2]]::[V.Vector Int])-      2 -> -       V.fromList . map ((\vs -> let rs = g vs in (rs, V.map (\f -> f rs) vN, vs)) . unwords . V.toList . -        V.backpermute (V.fromList . take 7 . words $ xs)) $ ([V.fromList [x1,x2] | !x1 <- [0,1], !x2 <- [0,1] \\ [x1]]::[V.Vector Int])-      _ -> V.empty      -         --- | Generalized variant of the 'uniqMaxPoeticalG' with the several norms given as a 'V.Vector' of functions and an 'Int' parameter. The function evaluates +-- | Variant of 'uniqNPoeticalVGN' where all the elements in the norms 'V.Vector' are used as norms from right to left.+uniqNPoeticalVGNL :: Int -> V.Vector ([Int] -> Int) -> String -> IO (V.Vector Uniqueness)+uniqNPoeticalVGNL n vN = uniqNPoetical2VGN n (V.length vN) vN (uniquenessPeriods)+{-# INLINE uniqNPoeticalVGNL #-}++-- | The function evaluates  -- the generated 'V.Vector' of 'Uniqueness' elements to retrieve the possibly maximum element in it with respect to the order and significance (principality)  -- of the norms being evaluated. The most significant and principal is the norm, which index in the 'V.Vector' of them is the 'Int' argument of the function  -- minus 1, then less significant is the next to the left norm and so on. uniqMaxPoetical2GN :: Int -> V.Vector ([Int] -> Int) ->  (String -> [Int]) -> String -> Uniqueness-uniqMaxPoetical2GN k vN g xs +uniqMaxPoetical2GN k vN g xs  | compare k (V.length vN) == GT = error "DobutokO.Poetry.uniqMaxPoetical2GN: undefined for that amount of norms. "- | compare k 0 == GT = + | compare k 0 == GT =    let vM = uniquenessVariants2GN vN g xs        maxK = V.maximumBy (\(_,vN0,_) (_,vN1,_) -> compare (V.unsafeIndex vN0 (k - 1)) (V.unsafeIndex vN1 (k - 1))) vM-       vK = V.filter (\(_,vN2,_) -> V.unsafeIndex vN2 (k - 1) == ((\(_,vNk,_) -> V.unsafeIndex vNk (k - 1)) maxK)) vM in +       vK = V.filter (\(_,vN2,_) -> V.unsafeIndex vN2 (k - 1) == ((\(_,vNk,_) -> V.unsafeIndex vNk (k - 1)) maxK)) vM in          uniqMaxPoeticalGNV (k - 1) (V.unsafeSlice 0 (V.length vN - 1) vN) vK  | otherwise = V.maximumBy (\(_,vN0,_) (_,vN1,_) -> compare (V.unsafeIndex vN0 0) (V.unsafeIndex vN1 0)) . uniquenessVariantsGN vN $ xs --- | The same as 'uniqMaxPoetical2GN' but applied to the other last argument. Is used inside the former one.-uniqMaxPoeticalGNV :: Int -> V.Vector ([Int] -> Int) ->  V.Vector Uniqueness -> Uniqueness-uniqMaxPoeticalGNV k vN vM - | compare k (V.length vN) == GT = error "DobutokO.Poetry.uniqMaxPoeticalGNV: undefined for that amount of norms. "- | compare k 0 == GT = -   let maxK = V.maximumBy (\(_,vN0,_) (_,vN1,_) -> compare (V.unsafeIndex vN0 (k - 1)) (V.unsafeIndex vN1 (k - 1))) vM-       vK = V.filter (\(_,vN2,_) -> V.unsafeIndex vN2 (k - 1) == ((\(_,vNk,_) -> V.unsafeIndex vNk (k - 1)) maxK)) vM in -         uniqMaxPoeticalGNV (k - 1) (V.unsafeSlice 0 (V.length vN - 1) vN) vK- | otherwise = V.maximumBy (\(_,vN0,_) (_,vN1,_) -> compare (V.unsafeIndex vN0 0) (V.unsafeIndex vN1 0)) vM +-- | Variant of 'uniqMaxPoetical2GN' where all the elements in the norms 'V.Vector' are used as norms from right to left.+uniqMaxPoetical2GNL :: V.Vector ([Int] -> Int) ->  (String -> [Int]) -> String -> Uniqueness+uniqMaxPoetical2GNL vN = uniqMaxPoetical2GN (V.length vN) vN+{-# INLINE uniqMaxPoetical2GNL #-} --- | Generalized variant of the 'uniqNPoeticalG' with usage of the several norms. +-- | Prints @n@ (given as the first 'Int' argument) maximum elements with respect to the several norms (their quantity is the second 'Int' argument) starting +-- from the right to the left. The last norm is the first element in the 'V.Vector' of norms (@[Int] -> Int@). uniqNPoetical2GN :: Int -> Int -> V.Vector ([Int] -> Int) -> (String -> [Int]) -> String -> IO ()-uniqNPoetical2GN n k vN g xs +uniqNPoetical2GN n k vN g xs  | n == 0 = return ()- | otherwise = do + | otherwise = do    let v = uniquenessVariants2GN vN g xs-   if compare (V.length v) n == LT -     then V.mapM_ (\x -> putStrLn ((filter (not . isPunctuation) . lastFrom3 $ x)) >> print (twoFrom3 x) >> putStrLn "" ) v -     else (uniqInMaxPoeticalN k vN v >>= uniqNPoeticalN (n - 1) k vN)     +   if compare (V.length v) n == LT+     then V.mapM_ (\x -> putStr ((filter (not . isPunctuation) . lastFrom3 $ x)) >> putStrLn "" ) v+     else (uniqInMaxPoeticalN k vN v >>= uniqNPoeticalN (n - 1) k vN) --- | Generalized variant of the 'uniqNPoeticalG' with usage of the several norms, but prints its output on the same line. +-- | Variant of 'uniqNPoetical2GN' where all the elements in the norms 'V.Vector' are used as norms from right to left.+uniqNPoetical2GNL :: Int -> V.Vector ([Int] -> Int) -> (String -> [Int]) -> String -> IO ()+uniqNPoetical2GNL n vN = uniqNPoetical2GN n (V.length vN) vN+{-# INLINE uniqNPoetical2GNL #-}+ +-- | A variant of the 'uniqNPoetical2GN', but prints its output on the same line.  uniqNPoetical2GNLine :: Int -> Int -> V.Vector ([Int] -> Int) -> (String -> [Int]) -> String -> IO ()-uniqNPoetical2GNLine n k vN g xs +uniqNPoetical2GNLine n k vN g xs  | n == 0 = putStrLn ""- | otherwise = do + | otherwise = do    let v = uniquenessVariants2GN vN g xs-   if compare (V.length v) n == LT +   if compare (V.length v) n == LT      then V.mapM_ (\x -> putStr ((filter (not . isPunctuation) . lastFrom3 $ x)) >> putStr " " ) v >> putStrLn ""-     else (uniqInMaxPoeticalNLine k vN v >>= uniqNPoeticalNLine (n - 1) k vN)      +     else (uniqInMaxPoeticalNLine k vN v >>= uniqNPoeticalNLine (n - 1) k vN) --- | Generalized variant of the 'uniqNPoeticalVG' with usage of the several norms. +-- | Variant of 'uniqNPoetical2GNLine' where all the elements in the norms 'V.Vector' are used as norms from right to left.+uniqNPoetical2GNLineL :: Int -> V.Vector ([Int] -> Int) -> (String -> [Int]) -> String -> IO ()+uniqNPoetical2GNLineL n vN = uniqNPoetical2GNLine n (V.length vN) vN+{-# INLINE uniqNPoetical2GNLineL #-}+ +-- | Prints @n@ (given as the first 'Int' argument) maximum elements with respect to the several norms (their quantity is the second 'Int' argument) starting +-- from the right to the left. The last norm is the first element in the 'V.Vector' of norms (@[Int] -> Int@). Contrary to its pair function +-- 'uniqNPoetical2GN' returns then the rest of the given 'V.Vector' 'Uniqueness' after filtering the printed elements 'String'. uniqNPoetical2VGN :: Int -> Int -> V.Vector ([Int] -> Int) -> (String -> [Int]) -> String -> IO (V.Vector Uniqueness)-uniqNPoetical2VGN n k vN g xs +uniqNPoetical2VGN n k vN g xs  | n == 0 = return V.empty- | otherwise = do + | otherwise = do    let v = uniquenessVariants2GN vN g xs    if compare (V.length v) n == LT then return v else uniqNPoeticalVN n k vN v +-- | Variant of 'uniqNPoetical2VGN' where all the elements in the norms 'V.Vector' are used as norms from right to left.+uniqNPoetical2VGNL :: Int -> V.Vector ([Int] -> Int) -> (String -> [Int]) -> String -> IO (V.Vector Uniqueness)+uniqNPoetical2VGNL n vN = uniqNPoetical2VGN n (V.length vN) vN+{-# INLINE uniqNPoetical2VGNL #-}+  -- | Variant of the 'uniqNPoetical2GN', which uses as a function 'uniquenessPeriods2' with the first argument equal to the first 'Int' argument. uniqNPoeticalUGN_ :: Int -> Int -> Int -> V.Vector ([Int] -> Int) -> String -> IO ()-uniqNPoeticalUGN_ x n k vN = uniqNPoetical2GN n k vN (uniquenessPeriods2 x) +uniqNPoeticalUGN_ x n k vN = uniqNPoetical2GN n k vN (uniquenessPeriods2 x)+{-# INLINE uniqNPoeticalUGN_ #-} +-- | Variant of 'uniqNPoeticalUGN_' where all the elements in the norms 'V.Vector' are used as norms from right to left.+uniqNPoeticalUGNL_ :: Int -> Int -> V.Vector ([Int] -> Int) -> String -> IO ()+uniqNPoeticalUGNL_ x n vN = uniqNPoetical2GNL n vN (uniquenessPeriods2 x)+{-# INLINE uniqNPoeticalUGNL_ #-}+ -- | Variant of the 'uniqNPoetical2VGN', which uses as a function 'uniquenessPeriods2' with the first argument equal to the first 'Int' argument. uniqNPoeticalUGN :: Int -> Int -> Int -> V.Vector ([Int] -> Int) -> String -> IO (V.Vector Uniqueness) uniqNPoeticalUGN x n k vN = uniqNPoetical2VGN n k vN (uniquenessPeriods2 x)+{-# INLINE uniqNPoeticalUGN #-} +-- | Variant of 'uniqNPoeticalUGN' where all the elements in the norms 'V.Vector' are used as norms from right to left.+uniqNPoeticalUGNL :: Int -> Int -> V.Vector ([Int] -> Int) -> String -> IO (V.Vector Uniqueness)+uniqNPoeticalUGNL x n vN = uniqNPoetical2VGN n (V.length vN) vN (uniquenessPeriods2 x)+{-# INLINE uniqNPoeticalUGNL #-}+ -- | Variant of the 'uniqNPoeticalUGN_', which uses as a single norm 'norm51'. uniqNPoeticalUGN51_ :: Int -> Int -> String -> IO () uniqNPoeticalUGN51_ x n = uniqNPoeticalUGN_ x n 1 (V.singleton norm51)+{-# INLINE uniqNPoeticalUGN51_ #-}  -- | Variant of the 'uniqNPoeticalUGN', which uses as a single norm 'norm51'. uniqNPoeticalUGN51 :: Int -> Int -> String -> IO (V.Vector Uniqueness) uniqNPoeticalUGN51 x n = uniqNPoeticalUGN x n 1 (V.singleton norm51)+{-# INLINE uniqNPoeticalUGN51 #-}
DobutokO/Poetry/Auxiliary.hs view
@@ -10,20 +10,10 @@  module DobutokO.Poetry.Auxiliary (   -- * Help functions-  fourFrom5-  , lastFrom5  -  , twoFrom3-  , lastFrom3+  lastFrom3 ) where -twoFrom3 :: (a,b,c) -> (a,b)-twoFrom3 (x,y,_) = (x,y)- lastFrom3 :: (a,b,c) -> c lastFrom3 (_,_,z) = z--fourFrom5 :: (a,b,b,b,c) -> (a,b,b,b)-fourFrom5 (x,y0,y1,y2,_) = (x,y0,y1,y2)+{-# INLINE lastFrom3 #-} -lastFrom5 :: (a,b,b,b,c) -> c-lastFrom5 (_,_,_,_,z) = z
+ DobutokO/Poetry/Basic.hs view
@@ -0,0 +1,121 @@+-- |+-- Module      :  DobutokO.Poetry.Basic+-- Copyright   :  (c) OleksandrZhabenko 2020+-- License     :  MIT+-- Stability   :  Experimental+-- Maintainer  :  olexandr543@yahoo.com+--+-- Helps to order the 7 or less Ukrainian words (or their concatenations) +-- to obtain (to some extent) suitable for poetry or music text. ++{-# LANGUAGE BangPatterns #-}++module DobutokO.Poetry.Basic (+  Uniqueness+  -- * Main functions+  , uniqNPoeticalN+  , uniqNPoeticalVN+  -- * Additional functions+  , uniqMaxPoeticalGNV+  , uniqInMaxPoeticalN+  -- * On one line output+  , uniqInMaxPoeticalNLine+  , uniqNPoeticalNLine+  -- * With all the norms used+  , uniqInMaxPoeticalNL+  , uniqInMaxPoeticalNLineL+  , uniqNPoeticalNL+  , uniqNPoeticalNLineL+  , uniqNPoeticalVNL+  , uniqMaxPoeticalGNVL+) where++import Data.Char (isPunctuation)+import qualified Data.Vector as V+import DobutokO.Poetry.Auxiliary++type Uniqueness = ([Int],V.Vector Int,String)++-- | Prints the maximum element with respect of the @k@ norms (the most significant of which is the rightest one, then to the left less significant etc.), +-- which is given as the first argument. The last norm is the first element in the 'V.Vector' of norms (@[Int] -> Int@). +uniqInMaxPoeticalN :: Int -> V.Vector ([Int] -> Int) -> V.Vector Uniqueness -> IO (V.Vector Uniqueness)+uniqInMaxPoeticalN k vN v = do+  let !uniq = uniqMaxPoeticalGNV k vN v+  let !fsT = (\(!ys,_,_) -> ys) uniq+  putStr (filter (not . isPunctuation) . lastFrom3 $ uniq) >> putStrLn ""+  return . V.filter (\(xs,_,_) -> xs /= fsT) $ v++-- | Variant of 'uniqInMaxPoticalN' where all the elements in the norms 'V.Vector' are used as norms from right to left.+uniqInMaxPoeticalNL :: V.Vector ([Int] -> Int) -> V.Vector Uniqueness -> IO (V.Vector Uniqueness)+uniqInMaxPoeticalNL vN = uniqInMaxPoeticalN (V.length vN) vN+{-# INLINE uniqInMaxPoeticalNL #-}++-- | Generalized variant of the 'uniqInMaxPoeticalN' with usage of the several norms and all the information is printed on the same line. +uniqInMaxPoeticalNLine :: Int -> V.Vector ([Int] -> Int) -> V.Vector Uniqueness -> IO (V.Vector Uniqueness)+uniqInMaxPoeticalNLine k vN v = do+  let !uniq = uniqMaxPoeticalGNV k vN v+  let !fsT = (\(!ys,_,_) -> ys) uniq+  putStr (filter (not . isPunctuation) . lastFrom3 $ uniq) >> putStr " "+  return . V.filter (\(xs,_,_) -> xs /= fsT) $ v++-- | Variant of 'uniqInMaxPoticalNLine' where all the elements in the norms 'V.Vector' are used as norms from right to left.+uniqInMaxPoeticalNLineL :: V.Vector ([Int] -> Int) -> V.Vector Uniqueness -> IO (V.Vector Uniqueness)+uniqInMaxPoeticalNLineL vN = uniqInMaxPoeticalNLine (V.length vN) vN+{-# INLINE uniqInMaxPoeticalNLineL #-}++-- | Prints @n@ (given as the first argument) maximum elements with respect to the several norms (their quantity is the second argument) starting +-- from the right to the left. The last norm is the first element in the 'V.Vector' of norms (@[Int] -> Int@). +uniqNPoeticalN :: Int -> Int -> V.Vector ([Int] -> Int) -> V.Vector Uniqueness -> IO ()+uniqNPoeticalN n k vN v+ | n == 0 = return ()+ | compare (V.length v) n == LT = V.mapM_ (\x -> putStr (filter (not . isPunctuation) . lastFrom3 $ x) >> putStrLn "" ) v+ | otherwise = (uniqInMaxPoeticalN k vN v >>= uniqNPoeticalN (n - 1) k vN)++-- | Variant of 'uniqNPoeticalN' where all the elements in the norms 'V.Vector' are used as norms from right to left.+uniqNPoeticalNL :: Int -> V.Vector ([Int] -> Int) -> V.Vector Uniqueness -> IO ()+uniqNPoeticalNL n vN = uniqNPoeticalN n (V.length vN) vN+{-# INLINE uniqNPoeticalNL #-}++-- | Variant of the 'uniqNPoeticalN' with its output being printed on the same line.+uniqNPoeticalNLine :: Int -> Int -> V.Vector ([Int] -> Int) -> V.Vector Uniqueness -> IO ()+uniqNPoeticalNLine n k vN v+ | n == 0 = putStrLn ""+ | compare (V.length v) n == LT = V.mapM_ (\x -> putStr (filter (not . isPunctuation) . lastFrom3 $ x) >> putStr " " ) v  >> putStrLn ""+ | otherwise = (uniqInMaxPoeticalNLine k vN v >>= uniqNPoeticalNLine (n - 1) k vN)++-- | Variant of 'uniqNPoeticalNLine' where all the elements in the norms 'V.Vector' are used as norms from right to left.+uniqNPoeticalNLineL :: Int -> V.Vector ([Int] -> Int) -> V.Vector Uniqueness -> IO ()+uniqNPoeticalNLineL n vN = uniqNPoeticalNLine n (V.length vN) vN+{-# INLINE uniqNPoeticalNLineL #-}++-- | Prints @n@ (given as the first argument) maximum elements with respect to the several norms (their quantity is the second argument) starting +-- from the right to the left. The last norm is the first element in the 'V.Vector' of norms (@[Int] -> Int@). Contrary to its pair function +-- 'uniqNPoeticalN' returns then the rest of the given 'V.Vector' 'Uniqueness' after filtering the printed elements 'String'.+uniqNPoeticalVN :: Int -> Int -> V.Vector ([Int] -> Int) -> V.Vector Uniqueness -> IO (V.Vector Uniqueness)+uniqNPoeticalVN n k vN v+ | n == 0 || compare (V.length v) n == LT = return v+ | otherwise = (uniqInMaxPoeticalN k vN v >>= uniqNPoeticalVN (n - 1) k vN)++-- | Variant of 'uniqNPoeticalVN' where all the elements in the norms 'V.Vector' are used as norms from right to left.+uniqNPoeticalVNL :: Int -> V.Vector ([Int] -> Int) -> V.Vector Uniqueness -> IO (V.Vector Uniqueness)+uniqNPoeticalVNL n vN = uniqNPoeticalVN n (V.length vN) vN+{-# INLINE uniqNPoeticalVNL #-}++-- | The function evaluates the 'V.Vector' of 'Uniqueness' elements to retrieve the possibly maximum element in it with respect to the order +-- and significance (principality)  of the norms being evaluated. The most significant and principal is the norm, which index in the 'V.Vector' of them is +-- the 'Int' argument of the function minus 1, then less significant is the next to the left norm and so on. Is similar to 'DobutokO.Poetry.uniqMaxPoeticalGN' +-- function.+uniqMaxPoeticalGNV :: Int -> V.Vector ([Int] -> Int) ->  V.Vector Uniqueness -> Uniqueness+uniqMaxPoeticalGNV k vN vM+ | compare k (V.length vN) == GT = error "DobutokO.Poetry.Basic.uniqMaxPoeticalGNV: undefined for that amount of norms. "+ | compare k 0 == GT =+   let maxK = V.maximumBy (\(_,vN0,_) (_,vN1,_) -> compare (V.unsafeIndex vN0 (k - 1)) (V.unsafeIndex vN1 (k - 1))) vM+       vK = V.filter (\(_,vN2,_) -> V.unsafeIndex vN2 (k - 1) == ((\(_,vNk,_) -> V.unsafeIndex vNk (k - 1)) maxK)) vM in+         uniqMaxPoeticalGNV (k - 1) (V.unsafeSlice 0 (V.length vN - 1) vN) vK+ | otherwise = V.maximumBy (\(_,vN0,_) (_,vN1,_) -> compare (V.unsafeIndex vN0 0) (V.unsafeIndex vN1 0)) vM++-- | Variant of 'uniqMaxPoeticalGNV' where all the elements in the norms 'V.Vector' are used as norms from right to left.+uniqMaxPoeticalGNVL :: V.Vector ([Int] -> Int) ->  V.Vector Uniqueness -> Uniqueness+uniqMaxPoeticalGNVL vN = uniqMaxPoeticalGNV (V.length vN) vN+{-# INLINE uniqMaxPoeticalGNVL #-}+
DobutokO/Poetry/Norms.hs view
@@ -10,6 +10,8 @@ -- provides several different norms that allow to research the text and  -- to create interesting sequences. +{-# LANGUAGE BangPatterns #-}+ module DobutokO.Poetry.Norms (   -- * Different norms   norm1@@ -28,54 +30,62 @@  -- | The first norm for the list of non-negative 'Int'. For not empty lists equals to the maximum element. norm1 :: [Int] -> Int -norm1 xs +norm1 !xs    | null xs = 0   | otherwise = maximum xs+{-# INLINE norm1 #-}  -- | The second norm for the list of non-negative 'Int'. For not empty lists equals to the sum of the elements. norm2 :: [Int] -> Int-norm2 xs = sum xs +norm2 !xs = sum xs+{-# INLINE norm2 #-}  -- | The third norm for the list of non-negative 'Int'. For not empty lists equals to the sum of the doubled maximum element and the rest elements of the list. norm3 :: [Int] -> Int-norm3 xs +norm3 !xs   | null xs = 0  | otherwise = maximum xs + sum xs+{-# INLINE norm3 #-}   -- | The fourth norm for the list of non-negative 'Int'. Equals to the sum of the 'norm3' and 'norm2'. norm4 :: [Int] -> Int-norm4 xs +norm4 !xs   | null xs = 0  | otherwise = maximum xs + sum xs + maximum (xs \\ [maximum xs])+{-# INLINE norm4 #-}   -- | The fifth norm for the list of non-negative 'Int'. For not empty lists equals to the sum of the elements quoted with sum of the two most minimum elements. norm5 :: [Int] -> Int-norm5 xs +norm5 !xs   | null xs = 0- | minimum xs == 0 = let ys = filter (/= 0) xs in norm5 ys+ | minimum xs == 0 = norm5 . filter (/= 0) $ xs  | otherwise = sum xs `quot` (minimum xs + minimum (xs \\ [minimum xs]))+{-# INLINE norm5 #-}   -- | The fifth modified norm for the list of non-negative 'Int'. Tries to take into account doubled and prolonged sounds to reduce their influence on the 'norm5'. norm51 :: [Int] -> Int-norm51 xs +norm51 !xs   | null xs = 0- | compare (minimum xs) 1 /= GT = let ys = filter (\t -> compare t 1 == GT) xs in (3 * sum xs) `quot` (minimum ys + minimum (ys \\ [minimum ys]))+ | compare (minimum xs) 1 /= GT = let !ys = filter (\t -> compare t 1 == GT) xs in (3 * sum xs) `quot` (minimum ys + minimum (ys \\ [minimum ys]))  | otherwise = (3 * sum xs) `quot` (minimum xs + minimum (xs \\ [minimum xs]))+{-# INLINE norm51 #-}   -- | The fifth modified (with three minimums) norm for the list of non-negative 'Int'. Tries to take into account doubled and prolonged sounds  -- to reduce their influence on the 'norm5'. norm513 :: [Int] -> Int-norm513 xs +norm513 !xs   | null xs = 0  | compare (minimum xs) 1 /= GT = -   let ys = filter (\t -> compare t 1 == GT) xs -       zs = ys \\ [minimum ys] in (3 * sum xs) `quot` (minimum ys + minimum zs + minimum (zs \\ [minimum zs]))+   let !ys = filter (\t -> compare t 1 == GT) xs +       !zs = ys \\ [minimum ys] in (3 * sum xs) `quot` (minimum ys + minimum zs + minimum (zs \\ [minimum zs]))  | otherwise = -   let zs = xs \\ [minimum xs] in (3 * sum xs) `quot` (minimum xs + minimum zs + minimum (zs \\ [minimum zs]))+   let !zs = xs \\ [minimum xs] in (3 * sum xs) `quot` (minimum xs + minimum zs + minimum (zs \\ [minimum zs]))+{-# INLINE norm513 #-}     -- | The sixth norm for the list of non-negative 'Int'. norm6 :: [Int] -> Int-norm6 xs = floor (fromIntegral (norm5 xs * sum xs) / fromIntegral (norm3 xs))+norm6 !xs = floor (fromIntegral (norm5 xs * sum xs) / fromIntegral (norm3 xs))+{-# INLINE norm6 #-}  -- | Splits a given list of non-negative integers into lists of elements not equal to zero and then applies to them the norms from the 'V.Vector' starting  -- from the last element in the vector right-to-left.
+ DobutokO/Poetry/PrependAppend.hs view
@@ -0,0 +1,303 @@+-- |+-- Module      :  DobutokO.Poetry.PrependAppend+-- Copyright   :  (c) OleksandrZhabenko 2020+-- License     :  MIT+-- Stability   :  Experimental+-- Maintainer  :  olexandr543@yahoo.com+--+-- Helps to order the 7 or less Ukrainian words (or their concatenations) +-- to obtain (to some extent) suitable for poetry or music text. +-- In contrast to the the same named functions from the 'DobutokO.Poetry' module each its function uses in the processment prepending and appending 'String' given +-- as the first two arguments. The first one is prepended and the second one is appended to the processed 'String' to be processed with it. +-- This allows to create more connection with the previous and postpending text.++{-# LANGUAGE BangPatterns #-}++module DobutokO.Poetry.PrependAppend (+  -- * Main functions+  uniq10Poetical4+  , uniq10Poetical5+  , uniq10PoeticalG+  , uniqNPoeticalG+  , uniqNPoeticalGN+  , uniqNPoeticalN+  , uniqNPoeticalVN+  , uniqNPoeticalVGN+  -- * Additional functions+  , uniquenessVariantsGN+  , uniqMaxPoeticalGN+  , uniqMaxPoeticalGNV+  , uniqInMaxPoeticalN+  -- * Generalized variants+  -- ** Main ones+  , uniqNPoetical2GN+  , uniqNPoetical2VGN+  , uniqNPoeticalUGN_+  , uniqNPoeticalUGN+  , uniqNPoeticalUGN51_+  , uniqNPoeticalUGN51+  -- ** Additional functions+  , uniqMaxPoetical2GN+  -- * On one line output+  , uniqInMaxPoeticalNLine+  , uniqNPoeticalNLine+  , uniqNPoetical2GNLine+  -- * With all the norms used+  , uniqMaxPoeticalGNL+  , uniqInMaxPoeticalNL+  , uniqInMaxPoeticalNLineL+  , uniqNPoeticalNL+  , uniqNPoeticalNLineL+  , uniqNPoeticalVNL+  , uniqNPoeticalGNL+  , uniqNPoeticalVGNL+  , uniqMaxPoetical2GNL+  , uniqMaxPoeticalGNVL+  , uniqNPoetical2GNL+  , uniqNPoetical2GNLineL+  , uniqNPoetical2VGNL+  , uniqNPoeticalUGNL_+  , uniqNPoeticalUGNL+) where++import Data.Char (isPunctuation)+import qualified Data.Vector as V+import Data.List ((\\))+import MMSyn7s+import DobutokO.Poetry.Norms+import DobutokO.Poetry.Auxiliary+import DobutokO.Poetry.UniquenessPeriodsG+import DobutokO.Poetry.StrictV+import DobutokO.Poetry.Basic++-- | Generalization of the 'uniquenessVariantsG' with usage of several norms (instead of one). They constitute a 'V.Vector' of functions +-- @norm :: [Int] -> Int@. So the inner vector in the each resulting 'Uniqueness' has the same length as the vector of norms. +-- In contrast to the the same named function from the 'DobutokO.Poetry' module uses in the processment prepending and appending 'String' given +-- as the first two arguments. The first one is prepended and the second one is appended to the processed 'String' to be processed with it. +-- This allows to create more connection with the previous and postpending text.+uniquenessVariantsGN :: String -> String -> V.Vector ([Int] -> Int) -> String -> V.Vector Uniqueness+uniquenessVariantsGN !ts !us vN = uniquenessVariants2GNP ts us vN (uniquenessPeriods)+{-# INLINE uniquenessVariantsGN #-}++-- | Generalized variant of the 'uniqMaxPoeticalG' with the several norms given as a 'V.Vector' of functions and an 'Int' parameter. The function evaluates +-- the generated 'V.Vector' of 'Uniqueness' elements to retrieve the possibly maximum element in it with respect to the order and significance (principality) +-- of the norms being evaluated. The most significant and principal is the norm, which index in the 'V.Vector' of them is the 'Int' argument of the function +-- minus 1, then less significant is the next to the left norm and so on.+-- In contrast to the the same named function from the 'DobutokO.Poetry' module uses in the processment prepending and appending 'String' given +-- as the first two arguments. The first one is prepended and the second one is appended to the processed 'String' to be processed with it. +-- This allows to create more connection with the previous and postpending text.+uniqMaxPoeticalGN :: String -> String -> Int -> V.Vector ([Int] -> Int) ->  String -> Uniqueness+uniqMaxPoeticalGN !ts !us k vN = uniqMaxPoetical2GN ts us k vN (uniquenessPeriods)+{-# INLINE uniqMaxPoeticalGN #-}++-- | Variant of 'uniqMaxPoeticalGN' where all the elements in the norms 'V.Vector' are used as norms from right to left.+-- In contrast to the the same named function from the 'DobutokO.Poetry' module uses in the processment prepending and appending 'String' given +-- as the first two arguments. The first one is prepended and the second one is appended to the processed 'String' to be processed with it. +-- This allows to create more connection with the previous and postpending text.+uniqMaxPoeticalGNL :: String -> String -> V.Vector ([Int] -> Int) ->  String -> Uniqueness+uniqMaxPoeticalGNL !ts !us vN = uniqMaxPoeticalGN ts us (V.length vN) vN+{-# INLINE uniqMaxPoeticalGNL #-}++-- | A variant of the 'uniqNPoeticalGN' with only one norm.+-- In contrast to the the same named function from the 'DobutokO.Poetry' module uses in the processment prepending and appending 'String' given +-- as the first two arguments. The first one is prepended and the second one is appended to the processed 'String' to be processed with it. +-- This allows to create more connection with the previous and postpending text.+uniqNPoeticalG :: String -> String -> Int -> ([Int] -> Int) -> String -> IO ()+uniqNPoeticalG !ts !us n g = uniqNPoeticalGN ts us n 1 (V.singleton g)+{-# INLINE uniqNPoeticalG #-}++-- | A variant of the 'uniqNPoeticalG' function with the @n@ equal to 10.+-- In contrast to the the same named function from the 'DobutokO.Poetry' module uses in the processment prepending and appending 'String' given +-- as the first two arguments. The first one is prepended and the second one is appended to the processed 'String' to be processed with it. +-- This allows to create more connection with the previous and postpending text.+uniq10PoeticalG :: String -> String -> ([Int] -> Int) -> String -> IO ()+uniq10PoeticalG !ts !us = uniqNPoeticalG ts us 10+{-# INLINE uniq10PoeticalG #-}++-- | A variant of 'uniq10PoeticalG' with the 'norm4' applied. The list is (according to some model, not universal, but a reasonable one in the most cases) the +-- most suitable for intonation changing and, therefore, for the accompaniment of the highly changable or variative melody. +-- In contrast to the the same named function from the 'DobutokO.Poetry' module uses in the processment prepending and appending 'String' given +-- as the first two arguments. The first one is prepended and the second one is appended to the processed 'String' to be processed with it. +-- This allows to create more connection with the previous and postpending text.+uniq10Poetical4 :: String -> String -> String -> IO ()+uniq10Poetical4 !ts !us = uniq10PoeticalG ts us norm4+{-# INLINE uniq10Poetical4 #-}++-- | A variant of 'uniq10PoeticalG' with the 'norm5' applied. The list is (according to some model, not universal, but a reasonable one in the most cases) the +-- most suitable for rhythmic speech and two-syllabilistic-based poetry. Therefore, it can be used to create a poetic composition or to emphasize some +-- thoughts. +-- In contrast to the the same named function from the 'DobutokO.Poetry' module uses in the processment prepending and appending 'String' given +-- as the first two arguments. The first one is prepended and the second one is appended to the processed 'String' to be processed with it. +-- This allows to create more connection with the previous and postpending text.+uniq10Poetical5 :: String -> String -> String -> IO ()+uniq10Poetical5 !ts !us = uniq10PoeticalG ts us norm5+{-# INLINE uniq10Poetical5 #-}++-- | A variant of the 'uniqNPoetical2GN' with the conversion (\"uniquenessPeriods\" function) function 'uniquenessPeriods'.+-- In contrast to the the same named function from the 'DobutokO.Poetry' module uses in the processment prepending and appending 'String' given +-- as the first two arguments. The first one is prepended and the second one is appended to the processed 'String' to be processed with it. +-- This allows to create more connection with the previous and postpending text.+uniqNPoeticalGN :: String -> String -> Int -> Int -> V.Vector ([Int] -> Int) -> String -> IO ()+uniqNPoeticalGN !ts !us n k vN = uniqNPoetical2GN ts us n k vN (uniquenessPeriods)+{-# INLINE uniqNPoeticalGN #-}++-- | Variant of 'uniqNPoeticalGN' where all the elements in the norms 'V.Vector' are used as norms from right to left. +-- In contrast to the the same named function from the 'DobutokO.Poetry' module uses in the processment prepending and appending 'String' given +-- as the first two arguments. The first one is prepended and the second one is appended to the processed 'String' to be processed with it. +-- This allows to create more connection with the previous and postpending text.+uniqNPoeticalGNL :: String -> String -> Int -> V.Vector ([Int] -> Int) -> String -> IO ()+uniqNPoeticalGNL !ts !us n vN = uniqNPoetical2GNL ts us n vN (uniquenessPeriods)+{-# INLINE uniqNPoeticalGNL #-}++-- | Generalized variant of the 'uniqNPoeticalVG' with usage of several norms. +-- In contrast to the the same named function from the 'DobutokO.Poetry' module uses in the processment prepending and appending 'String' given +-- as the first two arguments. The first one is prepended and the second one is appended to the processed 'String' to be processed with it. +-- This allows to create more connection with the previous and postpending text.+uniqNPoeticalVGN :: String -> String -> Int -> Int -> V.Vector ([Int] -> Int) -> String -> IO (V.Vector Uniqueness)+uniqNPoeticalVGN !ts !us n k vN = uniqNPoetical2VGN ts us n k vN (uniquenessPeriods)+{-# INLINE uniqNPoeticalVGN #-}++-- | Variant of 'uniqNPoeticalVGN' where all the elements in the norms 'V.Vector' are used as norms from right to left.+-- In contrast to the the same named function from the 'DobutokO.Poetry' module uses in the processment prepending and appending 'String' given +-- as the first two arguments. The first one is prepended and the second one is appended to the processed 'String' to be processed with it. +-- This allows to create more connection with the previous and postpending text.+uniqNPoeticalVGNL :: String -> String -> Int -> V.Vector ([Int] -> Int) -> String -> IO (V.Vector Uniqueness)+uniqNPoeticalVGNL !ts !us n vN = uniqNPoetical2VGN ts us n (V.length vN) vN (uniquenessPeriods)+{-# INLINE uniqNPoeticalVGNL #-}++-- | The function evaluates +-- the generated 'V.Vector' of 'Uniqueness' elements to retrieve the possibly maximum element in it with respect to the order and significance (principality) +-- of the norms being evaluated. The most significant and principal is the norm, which index in the 'V.Vector' of them is the 'Int' argument of the function +-- minus 1, then less significant is the next to the left norm and so on.+-- In contrast to the the same named function from the 'DobutokO.Poetry' module uses in the processment prepending and appending 'String' given +-- as the first two arguments. The first one is prepended and the second one is appended to the processed 'String' to be processed with it. +-- This allows to create more connection with the previous and postpending text.+uniqMaxPoetical2GN :: String -> String -> Int -> V.Vector ([Int] -> Int) ->  (String -> [Int]) -> String -> Uniqueness+uniqMaxPoetical2GN !ts !us k vN g !xs+ | compare k (V.length vN) == GT = error "DobutokO.Poetry.PrependAppend.uniqMaxPoetical2GN: undefined for that amount of norms. "+ | compare k 0 == GT =+   let vM = uniquenessVariants2GNP ts us vN g xs+       maxK = V.maximumBy (\(_,vN0,_) (_,vN1,_) -> compare (V.unsafeIndex vN0 (k - 1)) (V.unsafeIndex vN1 (k - 1))) vM+       vK = V.filter (\(_,vN2,_) -> V.unsafeIndex vN2 (k - 1) == ((\(_,vNk,_) -> V.unsafeIndex vNk (k - 1)) maxK)) vM in+         uniqMaxPoeticalGNV (k - 1) (V.unsafeSlice 0 (V.length vN - 1) vN) vK+ | otherwise = V.maximumBy (\(_,vN0,_) (_,vN1,_) -> compare (V.unsafeIndex vN0 0) (V.unsafeIndex vN1 0)) . uniquenessVariantsGN ts us vN $ xs++-- | Variant of 'uniqMaxPoetical2GN' where all the elements in the norms 'V.Vector' are used as norms from right to left.+-- In contrast to the the same named function from the 'DobutokO.Poetry' module uses in the processment prepending and appending 'String' given +-- as the first two arguments. The first one is prepended and the second one is appended to the processed 'String' to be processed with it. +-- This allows to create more connection with the previous and postpending text.+uniqMaxPoetical2GNL :: String -> String -> V.Vector ([Int] -> Int) ->  (String -> [Int]) -> String -> Uniqueness+uniqMaxPoetical2GNL !ts !us vN = uniqMaxPoetical2GN ts us (V.length vN) vN+{-# INLINE uniqMaxPoetical2GNL #-}+  +-- | Prints @n@ (given as the first 'Int' argument) maximum elements with respect to the several norms (their quantity is the second 'Int' argument) starting +-- from the right to the left. The last norm is the first element in the 'V.Vector' of norms (@[Int] -> Int@). +-- In contrast to the the same named function from the 'DobutokO.Poetry' module uses in the processment prepending and appending 'String' given +-- as the first two arguments. The first one is prepended and the second one is appended to the processed 'String' to be processed with it. +-- This allows to create more connection with the previous and postpending text.+uniqNPoetical2GN :: String -> String -> Int -> Int -> V.Vector ([Int] -> Int) -> (String -> [Int]) -> String -> IO ()+uniqNPoetical2GN !ts !us n k vN g !xs+ | n == 0 = return ()+ | otherwise = do+   let v = uniquenessVariants2GNP ts us vN g xs+   if compare (V.length v) n == LT+     then V.mapM_ (\x -> putStrLn ((filter (not . isPunctuation) . lastFrom3 $ x)) >> putStrLn "" ) v+     else (uniqInMaxPoeticalN k vN v >>= uniqNPoeticalN (n - 1) k vN)++-- | Variant of 'uniqNPoetical2GN' where all the elements in the norms 'V.Vector' are used as norms from right to left.+-- In contrast to the the same named function from the 'DobutokO.Poetry' module uses in the processment prepending and appending 'String' given +-- as the first two arguments. The first one is prepended and the second one is appended to the processed 'String' to be processed with it. +-- This allows to create more connection with the previous and postpending text.+uniqNPoetical2GNL :: String -> String -> Int -> V.Vector ([Int] -> Int) -> (String -> [Int]) -> String -> IO ()+uniqNPoetical2GNL !ts !us n vN = uniqNPoetical2GN ts us n (V.length vN) vN+{-# INLINE uniqNPoetical2GNL #-}+ +-- | Generalized variant of the 'uniqNPoeticalG' with usage of the several norms, but prints its output on the same line. +-- In contrast to the the same named function from the 'DobutokO.Poetry' module uses in the processment prepending and appending 'String' given +-- as the first two arguments. The first one is prepended and the second one is appended to the processed 'String' to be processed with it. +-- This allows to create more connection with the previous and postpending text.+uniqNPoetical2GNLine :: String -> String -> Int -> Int -> V.Vector ([Int] -> Int) -> (String -> [Int]) -> String -> IO ()+uniqNPoetical2GNLine !ts !us n k vN g !xs+ | n == 0 = putStrLn ""+ | otherwise = do+   let v = uniquenessVariants2GNP ts us vN g xs+   if compare (V.length v) n == LT+     then V.mapM_ (\x -> putStr ((filter (not . isPunctuation) . lastFrom3 $ x)) >> putStr " " ) v >> putStrLn ""+     else (uniqInMaxPoeticalNLine k vN v >>= uniqNPoeticalNLine (n - 1) k vN)++-- | Variant of 'uniqNPoetical2GNLine' where all the elements in the norms 'V.Vector' are used as norms from right to left.+-- In contrast to the the same named function from the 'DobutokO.Poetry' module uses in the processment prepending and appending 'String' given +-- as the first two arguments. The first one is prepended and the second one is appended to the processed 'String' to be processed with it. +-- This allows to create more connection with the previous and postpending text.+uniqNPoetical2GNLineL :: String -> String -> Int -> V.Vector ([Int] -> Int) -> (String -> [Int]) -> String -> IO ()+uniqNPoetical2GNLineL !ts !us n vN = uniqNPoetical2GNLine ts us n (V.length vN) vN+{-# INLINE uniqNPoetical2GNLineL #-}+ +-- | Prints @n@ (given as the first 'Int' argument) maximum elements with respect to the several norms (their quantity is the second 'Int' argument) starting +-- from the right to the left. The last norm is the first element in the 'V.Vector' of norms (@[Int] -> Int@). Contrary to its pair function +-- 'uniqNPoetical2GN' returns then the rest of the given 'V.Vector' 'Uniqueness' after filtering the printed elements 'String'.+-- In contrast to the the same named function from the 'DobutokO.Poetry' module uses in the processment prepending and appending 'String' given +-- as the first two arguments. The first one is prepended and the second one is appended to the processed 'String' to be processed with it. +-- This allows to create more connection with the previous and postpending text.+uniqNPoetical2VGN :: String -> String -> Int -> Int -> V.Vector ([Int] -> Int) -> (String -> [Int]) -> String -> IO (V.Vector Uniqueness)+uniqNPoetical2VGN !ts !us n k vN g !xs+ | n == 0 = return V.empty+ | otherwise = do+   let v = uniquenessVariants2GNP ts us vN g xs+   if compare (V.length v) n == LT then return v else uniqNPoeticalVN n k vN v++-- | Variant of 'uniqNPoetical2VGN' where all the elements in the norms 'V.Vector' are used as norms from right to left.+-- In contrast to the the same named function from the 'DobutokO.Poetry' module uses in the processment prepending and appending 'String' given +-- as the first two arguments. The first one is prepended and the second one is appended to the processed 'String' to be processed with it. +-- This allows to create more connection with the previous and postpending text.+uniqNPoetical2VGNL :: String -> String -> Int -> V.Vector ([Int] -> Int) -> (String -> [Int]) -> String -> IO (V.Vector Uniqueness)+uniqNPoetical2VGNL !ts !us n vN = uniqNPoetical2VGN ts us n (V.length vN) vN+{-# INLINE uniqNPoetical2VGNL #-}+ +-- | Variant of the 'uniqNPoetical2GN', which uses as a function 'uniquenessPeriods2' with the first argument equal to the first 'Int' argument.+-- In contrast to the the same named function from the 'DobutokO.Poetry' module uses in the processment prepending and appending 'String' given +-- as the first two arguments. The first one is prepended and the second one is appended to the processed 'String' to be processed with it. +-- This allows to create more connection with the previous and postpending text.+uniqNPoeticalUGN_ :: String -> String -> Int -> Int -> Int -> V.Vector ([Int] -> Int) -> String -> IO ()+uniqNPoeticalUGN_ !ts !us x n k vN = uniqNPoetical2GN ts us n k vN (uniquenessPeriods2 x)+{-# INLINE uniqNPoeticalUGN_ #-}++-- | Variant of 'uniqNPoeticalUGN_' where all the elements in the norms 'V.Vector' are used as norms from right to left.+-- In contrast to the the same named function from the 'DobutokO.Poetry' module uses in the processment prepending and appending 'String' given +-- as the first two arguments. The first one is prepended and the second one is appended to the processed 'String' to be processed with it. +-- This allows to create more connection with the previous and postpending text.+uniqNPoeticalUGNL_ :: String -> String -> Int -> Int -> V.Vector ([Int] -> Int) -> String -> IO ()+uniqNPoeticalUGNL_ !ts !us x n vN = uniqNPoetical2GNL ts us n vN (uniquenessPeriods2 x)+{-# INLINE uniqNPoeticalUGNL_ #-}++-- | Variant of the 'uniqNPoetical2VGN', which uses as a function 'uniquenessPeriods2' with the first argument equal to the first 'Int' argument.+-- In contrast to the the same named function from the 'DobutokO.Poetry' module uses in the processment prepending and appending 'String' given +-- as the first two arguments. The first one is prepended and the second one is appended to the processed 'String' to be processed with it. +-- This allows to create more connection with the previous and postpending text.+uniqNPoeticalUGN :: String -> String -> Int -> Int -> Int -> V.Vector ([Int] -> Int) -> String -> IO (V.Vector Uniqueness)+uniqNPoeticalUGN !ts !us x n k vN = uniqNPoetical2VGN ts us n k vN (uniquenessPeriods2 x)+{-# INLINE uniqNPoeticalUGN #-}++-- | Variant of 'uniqNPoeticalUGN' where all the elements in the norms 'V.Vector' are used as norms from right to left.+-- In contrast to the the same named function from the 'DobutokO.Poetry' module uses in the processment prepending and appending 'String' given +-- as the first two arguments. The first one is prepended and the second one is appended to the processed 'String' to be processed with it. +-- This allows to create more connection with the previous and postpending text.+uniqNPoeticalUGNL :: String -> String -> Int -> Int -> V.Vector ([Int] -> Int) -> String -> IO (V.Vector Uniqueness)+uniqNPoeticalUGNL !ts !us x n vN = uniqNPoetical2VGN ts us n (V.length vN) vN (uniquenessPeriods2 x)+{-# INLINE uniqNPoeticalUGNL #-}++-- | Variant of the 'uniqNPoeticalUGN_', which uses as a single norm 'norm51'.+-- In contrast to the the same named function from the 'DobutokO.Poetry' module uses in the processment prepending and appending 'String' given +-- as the first two arguments. The first one is prepended and the second one is appended to the processed 'String' to be processed with it. +-- This allows to create more connection with the previous and postpending text.+uniqNPoeticalUGN51_ :: String -> String -> Int -> Int -> String -> IO ()+uniqNPoeticalUGN51_ !ts !us x n = uniqNPoeticalUGN_ ts us x n 1 (V.singleton norm51)+{-# INLINE uniqNPoeticalUGN51_ #-}++-- | Variant of the 'uniqNPoeticalUGN', which uses as a single norm 'norm51'.+-- In contrast to the the same named function from the 'DobutokO.Poetry' module uses in the processment prepending and appending 'String' given +-- as the first two arguments. The first one is prepended and the second one is appended to the processed 'String' to be processed with it. +-- This allows to create more connection with the previous and postpending text.+uniqNPoeticalUGN51 :: String -> String -> Int -> Int -> String -> IO (V.Vector Uniqueness)+uniqNPoeticalUGN51 !ts !us x n = uniqNPoeticalUGN ts us x n 1 (V.singleton norm51)+{-# INLINE uniqNPoeticalUGN51 #-}
+ DobutokO/Poetry/StrictV.hs view
@@ -0,0 +1,43 @@+-- |+-- Module      :  DobutokO.Poetry.StrictV+-- Copyright   :  (c) OleksandrZhabenko 2020+-- License     :  MIT+-- Stability   :  Experimental+-- Maintainer  :  olexandr543@yahoo.com+--+-- Helps to order the 7 or less Ukrainian words (or their concatenations) +-- to obtain (to some extent) suitable for poetry or music text. The main +-- module in the library that imports all other ones except Main.++{-# LANGUAGE BangPatterns #-}++module DobutokO.Poetry.StrictV where++--import Data.Maybe (fromJust)+--import Data.Char (isPunctuation)+import qualified Data.Vector as V+import qualified Data.List as L (permutations)+--import MMSyn7s+--import DobutokO.Poetry.Norms+--import DobutokO.Poetry.UniquenessPeriodsG++-- | Given a 'String' consisting of no more than 7 Ukrainian words [some of them can be created by concatenation with preserving the Ukrainian +-- pronunciation of the parts, e. g. \"так як\" (actually two correct Ukrainian words and a single conjunction) can be written \"такйак\" +-- (one phonetical Ukrainian word transformed literally with preserving phonetical structure), if you would not like to treat them separately], +-- it returns a 'V.Vector' of possible combinations without repeating of the words in different order and for each of them appends also +-- the information about 'uniquenessPeriods' to it and finds out three different metrics -- named \"norms\". +-- +-- Afterwards, depending on these norms it can be specified some phonetical properties of the words that +-- allow to use them poetically or to create a varied melody with them. +uniquenessVariants2GN :: V.Vector ([Int] -> Int) -> (String -> [Int]) -> String -> V.Vector ([Int],V.Vector Int, String)+uniquenessVariants2GN vN g !xs = uniquenessVariants2GNP [] [] vN g xs +{-# INLINE uniquenessVariants2GN #-}+        +-- | Generalized variant of 'uniquenessVariants2GN' with prepending and appending 'String' (given as the first and the second argument). +uniquenessVariants2GNP :: String -> String -> V.Vector ([Int] -> Int) -> (String -> [Int]) -> String -> V.Vector ([Int],V.Vector Int, String)+uniquenessVariants2GNP !ts !us vN g !xs +  | null . words $ xs = V.empty+  | otherwise = let !v0 = V.fromList . take 8 . words $ xs in+     V.fromList . map ((\vs -> let !rs = g vs in (rs, (V.map (\f -> f rs) vN), vs)) . unwords . (ts:) . (++ [us]) . V.toList . +        V.backpermute v0 . V.fromList) . L.permutations $ ([0..(V.length v0 - 1)]::[Int])+{-# INLINE uniquenessVariants2GNP #-}
DobutokO/Poetry/UniquenessPeriodsG.hs view
@@ -16,7 +16,7 @@ import MMSyn7s import Melodics.Ukrainian (convertToProperUkrainian) --- | More complicated and longer variant of the 'uniquenessPeriods' that takes into account the second order structure of uniqueness with 'uniquenessP2' and +-- | More complicated and longer variant of the 'MMSyn7s.uniquenessPeriods' that takes into account the second order structure of uniqueness with 'uniquenessP2' and  -- can be therefore more fruitful (probably, it is a hypothesis itself that is needed to be tested). Is provided here as an example of the more complex  -- \"uniqueness function\". Uses both 'uniqueness2' and 'uniqueness2n' inside and is actually their composition with some (hopefully, natural) parameter functions. uniquenessPeriods2 :: Int -> String -> [Int]@@ -72,7 +72,7 @@ show7snc xss = let (tss,vss) = show7sn4' xss in if null vss then [length tss] else length tss:show7snc vss  -- | Filters a given arguments so that each element 'String' in the result is filtered from the element, which is doubled the first in the next 'String' --- (usually, it equals to the head of it, if used as expected). Can be interpreted as a preparation to the second application of the 'uniquenessPeriods' +-- (usually, it equals to the head of it, if used as expected). Can be interpreted as a preparation to the second application of the 'MMSyn7s.uniquenessPeriods'  -- function because it removes the elements that splitted the input into lists and can be seen as a second deeper (so, probably less significant) factor  -- of the uniqueness phonetical structure.  uniquenessP2 :: [[String]] -> [[String]]
Main.hs view
@@ -20,7 +20,7 @@ import EndOfExe (showE) import Data.Maybe (fromJust,isJust) --- | The first command line argument specifies which function to run. If given \"4\" it runs 'uniqNPoeticalG norm4', otherwise 'uniqNPoeticalG norm5'. +-- | The first command line argument specifies which function to run. If given \"4\" it runs 'uniqNPoeticalG' 'norm4', otherwise 'uniqNPoeticalG' 'norm5'.  -- The second command line argument (by default is considered equal to 10::Int) is an 'Int' number of the needed printed variants. The next 7  -- are treated as the Ukrainian words to be ordered accordingly to the norm. For more information, please, refer to the documentation for the abovementioned  -- functions. 
dobutokO-poetry.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                dobutokO-poetry-version:             0.6.0.0+version:             0.7.0.0 synopsis:            Helps to order the 7 or less Ukrainian words to obtain somewhat suitable for poetry or music text description:         Helps to order the 7 or less Ukrainian words (or their concatenations) to obtain somewhat suitable for poetry or music text. Can be also used as a research instrument with generalized functions. @@ -18,17 +18,17 @@ cabal-version:       >=1.10  library-  exposed-modules:     DobutokO.Poetry, DobutokO.Poetry.Norms, DobutokO.Poetry.Auxiliary, DobutokO.Poetry.UniquenessPeriodsG, Main+  exposed-modules:     DobutokO.Poetry.Basic, DobutokO.Poetry, DobutokO.Poetry.PrependAppend, DobutokO.Poetry.StrictV, DobutokO.Poetry.Auxiliary, DobutokO.Poetry.Norms, DobutokO.Poetry.UniquenessPeriodsG, Main   -- other-modules:   other-extensions:    BangPatterns-  build-depends:       base >=4.7 && <4.15, vector >=0.11 && <0.14, mmsyn3 >= 0.1.5 && <1, mmsyn7s >=0.6.7 && <1, mmsyn6ukr >=0.7.3 && <1+  build-depends:       base >=4.7 && <4.15, vector >=0.11 && <0.14, mmsyn3 >=0.1.5 && <1, mmsyn7s >=0.6.7 && <1, mmsyn6ukr >=0.7.3 && <1   -- hs-source-dirs:   default-language:    Haskell2010  executable dobutokO-poetry   main-is:             Main.hs-  other-modules:       DobutokO.Poetry, DobutokO.Poetry.Norms, DobutokO.Poetry.Auxiliary, DobutokO.Poetry.UniquenessPeriodsG+  other-modules:       DobutokO.Poetry.Basic, DobutokO.Poetry, DobutokO.Poetry.PrependAppend, DobutokO.Poetry.StrictV, DobutokO.Poetry.Auxiliary, DobutokO.Poetry.Norms, DobutokO.Poetry.UniquenessPeriodsG   other-extensions:    BangPatterns-  build-depends:       base >=4.7 && <4.15, vector >=0.11 && <0.14, mmsyn3 >= 0.1.5 && <1, mmsyn7s >=0.6.7 && <1, mmsyn6ukr >=0.7.3 && <1+  build-depends:       base >=4.7 && <4.15, vector >=0.11 && <0.14, mmsyn3 >=0.1.5 && <1, mmsyn7s >=0.6.7 && <1, mmsyn6ukr >=0.7.3 && <1   -- hs-source-dirs:   default-language:    Haskell2010