packages feed

dobutokO-poetry 0.3.2.0 → 0.4.0.0

raw patch · 6 files changed

+242/−60 lines, 6 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- DobutokO.Poetry: fourFrom5 :: (a, b, b, b, c) -> (a, b, b, b)
- DobutokO.Poetry: lastFrom5 :: (a, b, b, b, c) -> c
- DobutokO.Poetry: norm1 :: [Int] -> Int
- DobutokO.Poetry: norm2 :: [Int] -> Int
- DobutokO.Poetry: norm3 :: [Int] -> Int
- DobutokO.Poetry: norm4 :: [Int] -> Int
- DobutokO.Poetry: norm5 :: [Int] -> Int
- DobutokO.Poetry: norm6 :: [Int] -> Int
+ DobutokO.Poetry: type Uniqueness = ([Int], Vector Int, String)
+ DobutokO.Poetry: uniqInMaxPoeticalN :: Int -> Vector ([Int] -> Int) -> Vector Uniqueness -> IO (Vector Uniqueness)
+ DobutokO.Poetry: uniqMaxPoetical2GN :: Int -> Vector ([Int] -> Int) -> (String -> [Int]) -> String -> Uniqueness
+ DobutokO.Poetry: uniqMaxPoeticalGN :: Int -> Vector ([Int] -> Int) -> String -> Uniqueness
+ DobutokO.Poetry: uniqMaxPoeticalGNV :: Int -> Vector ([Int] -> Int) -> Vector Uniqueness -> Uniqueness
+ DobutokO.Poetry: uniqNPoetical2GN :: Int -> Int -> Vector ([Int] -> Int) -> (String -> [Int]) -> String -> IO ()
+ DobutokO.Poetry: uniqNPoetical2VGN :: Int -> Int -> Vector ([Int] -> Int) -> (String -> [Int]) -> String -> IO (Vector Uniqueness)
+ DobutokO.Poetry: uniqNPoeticalGN :: Int -> Int -> Vector ([Int] -> Int) -> String -> IO ()
+ DobutokO.Poetry: uniqNPoeticalN :: Int -> Int -> Vector ([Int] -> Int) -> Vector Uniqueness -> IO ()
+ DobutokO.Poetry: uniqNPoeticalVGN :: Int -> Int -> Vector ([Int] -> Int) -> String -> IO (Vector Uniqueness)
+ 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: uniquenessVariantsGN :: Vector ([Int] -> Int) -> String -> Vector Uniqueness
+ DobutokO.Poetry.Auxiliary: fourFrom5 :: (a, b, b, b, c) -> (a, b, b, b)
+ DobutokO.Poetry.Auxiliary: lastFrom3 :: (a, b, c) -> c
+ DobutokO.Poetry.Auxiliary: lastFrom5 :: (a, b, b, b, c) -> c
+ DobutokO.Poetry.Auxiliary: twoFrom3 :: (a, b, c) -> (a, b)
+ DobutokO.Poetry.Norms: norm1 :: [Int] -> Int
+ DobutokO.Poetry.Norms: norm2 :: [Int] -> Int
+ DobutokO.Poetry.Norms: norm3 :: [Int] -> Int
+ DobutokO.Poetry.Norms: norm4 :: [Int] -> Int
+ DobutokO.Poetry.Norms: norm5 :: [Int] -> Int
+ DobutokO.Poetry.Norms: norm6 :: [Int] -> Int

Files

ChangeLog.md view
@@ -20,3 +20,8 @@ ## 0.3.2.0 -- 2020-06-02  * Third version revised B. Fixed issues with being not accurate printing.++## 0.4.0.0 -- 2020-06-03++* Fourth version. Changed the module structure to simplify the usage in research purposes. Added new generalized variants of the functions with different+norms and different String -> [Int] conversion functions. Some documentation improvements.
DobutokO/Poetry.hs view
@@ -6,35 +6,42 @@ -- Maintainer  :  olexandr543@yahoo.com -- -- Helps to order the 7 or less Ukrainian words (or their concatenations) --- to obtain somewhat suitable for poetry or music text.+-- 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-  -- * Different norms-  , norm1-  , norm2-  , norm3-  , norm4-  , norm5-  , norm6-  -- * Help functions-  , fourFrom5-  , lastFrom5  +  , uniqInMaxPoeticalN+  -- * Generalized variants+  -- ** Main ones+  , uniqNPoetical2GN+  , uniqNPoetical2VGN+  -- ** Additional functions+  , uniquenessVariants2GN+  , uniqMaxPoetical2GN ) where  import Control.Monad@@ -42,7 +49,11 @@ import qualified Data.Vector as V import Data.List ((\\)) import MMSyn7s +import DobutokO.Poetry.Norms+import DobutokO.Poetry.Auxiliary +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@@ -52,10 +63,12 @@ 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 correnc Ukrainian words) can be written \"такйак\" (one phonetical Ukrainian word --- obtained 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 differnet order and for every one of them appends also 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 +-- 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)@@ -90,49 +103,23 @@        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-         --- | A first norm for the list of positive 'Int'. For not empty lists equals to the maximum element.-norm1 :: [Int] -> Int -norm1 xs -  | null xs = 0-  | otherwise = maximum xs --- | A second norm for the list of positive 'Int'. For not empty lists equals to the sum of the elements.-norm2 :: [Int] -> Int-norm2 xs = sum xs ---- | A third norm for the list of positive 'Int'. For not empty lists equals to the sum of the doubled maximum element and a rest elements of the list.-norm3 :: [Int] -> Int-norm3 xs - | null xs = 0- | otherwise = maximum xs + sum xs---- | A fourth norm for the list of positive 'Int'. Equals to the sum of the 'norm3' and 'norm2'.-norm4 :: [Int] -> Int-norm4 xs - | null xs = 0- | otherwise = maximum xs + sum xs + maximum (xs \\ [maximum xs])---- | A fifth norm for the list of positive '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 - | null xs = 0- | otherwise = sum xs `quot` (minimum xs + minimum (xs \\ [minimum xs]))---- | A sixth norm for the list of positive 'Int'.-norm6 :: [Int] -> Int-norm6 xs = floor (fromIntegral (norm5 xs * sum xs) / fromIntegral (norm3 xs))---- | 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+-- | 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 -fourFrom5 :: (a,b,b,b,c) -> (a,b,b,b)-fourFrom5 (x,y0,y1,y2,_) = (x,y0,y1,y2)--lastFrom5 :: (a,b,b,b,c) -> c-lastFrom5 (_,_,_,_,z) = z+-- | 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.+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.@@ -142,6 +129,13 @@   putStrLn (filter (not . isPunctuation) . lastFrom5 $ uniq) >> print (fourFrom5 uniq) >> putStrLn ""    return . V.filter (/= uniq) $ v +-- | 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  + -- | A variant of the 'uniqNPoeticalG' function with the @n@ equal to 10. uniq10PoeticalG :: ([Int] -> Int) -> String -> IO () uniq10PoeticalG = uniqNPoeticalG 10@@ -165,6 +159,13 @@  | 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) + -- | 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))@@ -172,6 +173,12 @@  | 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.@@ -184,6 +191,10 @@      then V.mapM_ (\x -> putStrLn (filter (not . isPunctuation) . lastFrom5 $ x) >> print (fourFrom5 x) >> putStrLn "" ) v       else (uniqInMaxPoetical v >>= uniqNPoetical (n - 1)) +-- | Generalized variant of the 'uniqNPoeticalG' with usage of several norms. +uniqNPoeticalGN :: Int -> Int -> V.Vector ([Int] -> Int) -> String -> IO ()+uniqNPoeticalGN n k vN = uniqNPoetical2GN n k vN (uniquenessPeriods)    + -- | 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))@@ -193,3 +204,83 @@    let v = uniquenessVariantsG g xs    if compare (V.length v) n == LT then return v else uniqNPoeticalV n v +-- | 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)++-- | 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 +-- 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 + | compare k (V.length vN) == GT = error "DobutokO.Poetry.Uniqueness.uniqMaxPoetical2GN: undefined for that amount of norms. "+ | 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 +         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.Uniqueness.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 ++-- | Generalized variant of the 'uniqNPoeticalG' with usage of the several norms. +uniqNPoetical2GN :: Int -> Int -> V.Vector ([Int] -> Int) -> (String -> [Int]) -> String -> IO ()+uniqNPoetical2GN n k vN g xs + | n == 0 = return ()+ | 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)     ++-- | Generalized variant of the 'uniqNPoeticalVG' with usage of the several norms. +uniqNPoetical2VGN :: Int -> Int -> V.Vector ([Int] -> Int) -> (String -> [Int]) -> String -> IO (V.Vector Uniqueness)+uniqNPoetical2VGN n k vN g xs + | n == 0 = return V.empty+ | otherwise = do +   let v = uniquenessVariants2GN vN g xs+   if compare (V.length v) n == LT then return v else uniqNPoeticalVN n k vN v
+ DobutokO/Poetry/Auxiliary.hs view
@@ -0,0 +1,29 @@+-- |+-- Module      :  DobutokO.Poetry.Auxiliary+-- 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.++module DobutokO.Poetry.Auxiliary (+  -- * Help functions+  fourFrom5+  , lastFrom5  +  , twoFrom3+  , 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)++lastFrom5 :: (a,b,b,b,c) -> c+lastFrom5 (_,_,_,_,z) = z
+ DobutokO/Poetry/Norms.hs view
@@ -0,0 +1,56 @@+-- |+-- Module      :  DobutokO.Poetry.Norms+-- 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.++++module DobutokO.Poetry.Norms (+  -- * Different norms+  norm1+  , norm2+  , norm3+  , norm4+  , norm5+  , norm6+) where++import qualified Data.Vector as V+import Data.List ((\\))++-- | The first norm for the list of positive 'Int'. For not empty lists equals to the maximum element.+norm1 :: [Int] -> Int +norm1 xs +  | null xs = 0+  | otherwise = maximum xs++-- | The second norm for the list of positive 'Int'. For not empty lists equals to the sum of the elements.+norm2 :: [Int] -> Int+norm2 xs = sum xs ++-- | The third norm for the list of positive '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 + | null xs = 0+ | otherwise = maximum xs + sum xs++-- | The fourth norm for the list of positive 'Int'. Equals to the sum of the 'norm3' and 'norm2'.+norm4 :: [Int] -> Int+norm4 xs + | null xs = 0+ | otherwise = maximum xs + sum xs + maximum (xs \\ [maximum xs])++-- | The fifth norm for the list of positive '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 + | null xs = 0+ | otherwise = sum xs `quot` (minimum xs + minimum (xs \\ [minimum xs]))++-- | The sixth norm for the list of positive 'Int'.+norm6 :: [Int] -> Int+norm6 xs = floor (fromIntegral (norm5 xs * sum xs) / fromIntegral (norm3 xs))
Main.hs view
@@ -6,13 +6,14 @@ -- Maintainer  :  olexandr543@yahoo.com -- -- Helps to order the 7 or less Ukrainian words (or their concatenations) --- to obtain somewhat suitable for poetry or music text.+-- to obtain (to some extent) suitable for poetry or music text.  module Main where  import Control.Exception (onException) import System.IO-import DobutokO.Poetry (uniq10Poetical4,uniq10Poetical5,norm4,norm5,uniqNPoeticalG)+import DobutokO.Poetry (uniq10Poetical4,uniq10Poetical5,uniqNPoeticalG)+import DobutokO.Poetry.Norms (norm4,norm5) import System.Environment (getArgs) import Melodics.Executable (recFileName, printInfoF, rawToSoundFile) import Melodics.Ukrainian (appendS16LEFile, convertToProperUkrainian)
dobutokO-poetry.cabal view
@@ -2,9 +2,9 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                dobutokO-poetry-version:             0.3.2.0+version:             0.4.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.+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.  homepage:            https://hackage.haskell.org/package/dobutokO-poetry license:             MIT@@ -18,7 +18,7 @@ cabal-version:       >=1.10  library-  exposed-modules:     DobutokO.Poetry, Main+  exposed-modules:     DobutokO.Poetry, DobutokO.Poetry.Norms, DobutokO.Poetry.Auxiliary, 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@@ -27,7 +27,7 @@  executable dobutokO-poetry   main-is:             Main.hs-  other-modules:       DobutokO.Poetry+  other-modules:       DobutokO.Poetry, DobutokO.Poetry.Norms, DobutokO.Poetry.Auxiliary   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   -- hs-source-dirs: