packages feed

dobutokO-poetry 0.9.0.1 → 0.10.0.0

raw patch · 5 files changed

+128/−5 lines, 5 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ DobutokO.Poetry.Norms: flSplitNorms :: Vector ([Int] -> Int) -> [Int] -> [Int]
+ DobutokO.Poetry.Norms: norm54 :: [Int] -> Int
+ DobutokO.Poetry.Norms: norm6r :: [Int] -> Int
+ DobutokO.Poetry.Norms: norm8 :: [Int] -> Int
+ DobutokO.Poetry.Norms: normSplit :: Vector ([Int] -> Int) -> [Int] -> Int
+ DobutokO.Poetry.Norms: normSplitShifted :: [Int] -> Vector ([Int] -> Int) -> [Int] -> Int
+ DobutokO.Poetry.Norms: normSplitWeighted :: [Int] -> Vector ([Int] -> Int) -> [Int] -> Int
+ DobutokO.Poetry.Norms: normSplitWeightedG :: (Int -> Int -> Int) -> [Int] -> Vector ([Int] -> Int) -> [Int] -> Int
+ DobutokO.Poetry.Norms.Extended: norm45n :: Int -> Int -> [Int] -> Int
+ DobutokO.Poetry.Norms.Extended: norm54n :: Int -> Int -> [Int] -> Int
+ DobutokO.Poetry.Norms.Extended: norm7 :: Int -> [Int] -> Int
+ DobutokO.Poetry.Norms.Extended: norm7n :: Int -> [Int] -> Int

Files

ChangeLog.md view
@@ -57,3 +57,8 @@ ## 0.9.0.1 -- 2020-08-05  * Ninth version revised A. Some documentation improvements for README.md file.++## 0.10.0.0 -- 2020-08-14++* Tenth version. Added a new module DobutokO.Poetry.Norms.Extended, added a new possibility to split norms and to use more complex than just one norm evaluation +procedure on the each stage of evaluation. Added some new norms to the corresponding modules. Some minor code improvements. 
DobutokO/Poetry/General.hs view
@@ -23,6 +23,7 @@ import qualified Data.Vector as V import MMSyn7s import DobutokO.Poetry.Norms+import DobutokO.Poetry.Norms.Extended import DobutokO.Poetry.Auxiliary import DobutokO.Poetry.UniquenessPeriodsG import DobutokO.Poetry.StrictV
DobutokO/Poetry/Norms.hs view
@@ -19,8 +19,17 @@   , norm5   , norm51   , norm513+  , norm54   , norm6+  , norm6r+  , norm8+  -- * Norms combining   , splitNorm+  , flSplitNorms+  , normSplit+  , normSplitWeighted+  , normSplitShifted+  , normSplitWeightedG ) where  import qualified Data.Vector as V@@ -71,7 +80,7 @@       0 -> sum xs       1 -> (3 * sum xs) `quot` (minimum ys + maximum ys)       _ -> (3 * sum xs) `quot` (minimum ys + minimum (ys \\ [minimum ys]))- | length xs == 1 = (3 * sum xs) `quot` (minimum xs + maximum xs)+ | length xs == 1 = 1  | otherwise = (3 * sum xs) `quot` (minimum xs + minimum (xs \\ [minimum xs])) {-# INLINE norm51 #-}  @@ -98,9 +107,28 @@  -- | 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 = (norm5 xs * sum xs) `quot` norm3 xs {-# INLINE norm6 #-} +-- | The sixth modified norm for the list of non-negative 'Int'.+norm6r :: [Int] -> Int+norm6r xs = (norm513 xs * norm3 xs) `quot` sum xs+{-# INLINE norm6r #-}++-- | The fifth-fourth norm for the list of non-negative 'Int'. Tries to generate more suitable for poetry text.+norm54 :: [Int] -> Int+norm54 xs = (norm513 xs * norm6r xs) `quot` norm4 xs+{-# INLINE norm54 #-}++-- | The eigth norm for the list of the non-negative 'Int'. Similarly to 'norm4' is used to quickly evaluate the possibly more diverse texts, +-- which are not simple to quickly pronounce. Is not informative (and therefore, is not intended to be used) for the lists of no more than 1 element.+norm8 :: [Int] -> Int+norm8 xs + | null xs = 0+ | length xs == 1 = 1+ | otherwise =  (5040 * maximum xs) `quot` minimum xs+{-# INLINE norm8 #-} + -- | 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. splitNorm :: [Int] -> V.Vector ([Int] -> Int) -> [Int]@@ -110,3 +138,37 @@     let (ys,zs) = break (== 0) xs          zzs = drop 1 zs         in (V.unsafeIndex vN (V.length vN - 1)) ys:splitNorm zzs (V.unsafeSlice 0 (V.length vN - 1) vN)++-- | The flipped variant of the 'splitNorm' (can be more convenient for applications).+flSplitNorms :: V.Vector ([Int] -> Int) -> [Int] -> [Int]+flSplitNorms = flip splitNorm+{-# INLINE flSplitNorms #-}++-- | Using 'splitNorm' and given a group of norms (represented as a 'V.Vector') returns the sum of their applications. These norms are equally important +-- and their order can be volatile.+normSplit :: V.Vector ([Int] -> Int) -> ([Int] -> Int)+normSplit v = sum . flSplitNorms v+{-# INLINE normSplit #-}++-- | Using 'splitNorm' and given a group of norms (represented as a 'V.Vector') returns the sum of their applications. The importance of these norms can be +-- easily controlled by the first function argument. The corresponding greater numbers in the first argument list signify the greater importance of the +-- norm in the 'V.Vector' of norms all being applied (so these numbers are multiplicative weights in the sum). If some of the numbers are equal to zero then +-- the corresponding norm is not taken into account. If some of the numbers are negative then the corresponding norms are weightly subtracted from the sum.+normSplitWeighted :: [Int] -> V.Vector ([Int] -> Int) -> ([Int] -> Int)+normSplitWeighted = normSplitWeightedG (*)+{-# INLINE normSplitWeighted #-}++-- | Similar to 'normSplitWeighted', but uses more complex modification instead of multiplication. +-- Using 'splitNorm' and given a group of norms (represented as a 'V.Vector') returns the sum of their applications. The importance of these norms can be +-- controlled by the first function argument. The corresponding greater numbers in the first argument list signify the greater importance of the +-- norm in the 'V.Vector' of norms all being applied. If some of the numbers are negative then the corresponding norms reduces the sum in some way.+normSplitShifted :: [Int] -> V.Vector ([Int] -> Int) -> ([Int] -> Int)+normSplitShifted = normSplitWeightedG (\x y -> x * (x + y))+{-# INLINE normSplitShifted #-}++-- | Generalization for the 'normSplitWeighted' and 'normSplitShifted' with the possibility to define and use the volatile function that influences the +-- weights for the norms in the 'V.Vector'. This function used in the 'zipWith' is given as the first argument.+normSplitWeightedG :: (Int -> Int -> Int) -> [Int] -> V.Vector ([Int] -> Int) -> ([Int] -> Int)+normSplitWeightedG h xs v+ | null xs = \ys -> 0+ | otherwise = let g ts = zipWith h (flSplitNorms v ts) xs in sum . g
+ DobutokO/Poetry/Norms/Extended.hs view
@@ -0,0 +1,55 @@+-- |+-- Module      :  DobutokO.Poetry.Norms.Extended+-- 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 norms here +-- are more complex and/or use other ones and can be controlled by some additional +-- parameters.++module DobutokO.Poetry.Norms.Extended (+  norm7+  , norm7n+  , norm54n+  , norm45n+) where++import qualified Data.Vector as V+import Data.List ((\\),sort)+import DobutokO.Poetry.Norms++-- | The seventh norm 'norm7' has more complex behaviour. The possible range of the first argument is [1..100]. Is provided for exploration.+norm7 :: Int -> [Int] -> Int+norm7 l xs + | null xs = 0+ | otherwise = +    let n = ((abs l `rem` 101) * length xs) `quot` 10 +        m = abs (length xs - (24 `quot` n))+        ys = if compare (minimum xs) 1 /= GT then filter (\t -> compare t 1 == GT) xs else xs \\ [minimum xs] in +     if null ys then sum xs else (n * sum xs) `quot` ((sum . take n . sort $ xs) + m * maximum xs)+{-# INLINE norm7 #-}   ++-- | The seventh norm 'norm7n' (the variant of the 'norm7' without the maximum evaluation) has more complex behaviour. The possible range of the +-- first argument is [1..100]. Is provided for exploration.+norm7n :: Int -> [Int] -> Int+norm7n l xs + | null xs = 0+ | otherwise = +    let n = ((abs l `rem` 101) * length xs) `quot` 10 +        ys = if compare (minimum xs) 1 /= GT then filter (\t -> compare t 1 == GT) xs else xs \\ [minimum xs] in +     if null ys then sum xs else (n * sum xs) `quot` (sum . take n . sort $ xs)+{-# INLINE norm7n #-}   ++-- | The fifth-fourth norm for the list of non-negative 'Int'. Is provided for exploration.+norm54n :: Int -> Int -> [Int] -> Int+norm54n n m xs = (norm513 xs ^ n * norm6r xs) `quot` (norm4 xs ^ m)+{-# INLINE norm54n #-}++-- | The fourth-fifth norm for the list of non-negative 'Int'. Is provided for exploration.+norm45n :: Int -> Int -> [Int] -> Int+norm45n n m xs = (norm4 xs ^ n * norm6r xs) `quot` (norm513 xs ^ m)+{-# INLINE norm45n #-}+
dobutokO-poetry.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                dobutokO-poetry-version:             0.9.0.1+version:             0.10.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,7 +18,7 @@ cabal-version:       >=1.10  library-  exposed-modules:     DobutokO.Poetry.Basic, DobutokO.Poetry, DobutokO.Poetry.StrictV, DobutokO.Poetry.Auxiliary, DobutokO.Poetry.Norms, DobutokO.Poetry.UniquenessPeriodsG, Main, DobutokO.Poetry.General+  exposed-modules:     DobutokO.Poetry.Basic, DobutokO.Poetry, DobutokO.Poetry.StrictV, DobutokO.Poetry.Auxiliary, DobutokO.Poetry.Norms, DobutokO.Poetry.Norms.Extended, DobutokO.Poetry.UniquenessPeriodsG, Main, DobutokO.Poetry.General   -- other-modules:   other-extensions:    BangPatterns, CPP, FlexibleInstances, MultiParamTypeClasses   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.Basic, DobutokO.Poetry, DobutokO.Poetry.StrictV, DobutokO.Poetry.Auxiliary, DobutokO.Poetry.Norms, DobutokO.Poetry.UniquenessPeriodsG, DobutokO.Poetry.General+  other-modules:       DobutokO.Poetry.Basic, DobutokO.Poetry, DobutokO.Poetry.StrictV, DobutokO.Poetry.Auxiliary, DobutokO.Poetry.Norms, DobutokO.Poetry.Norms.Extended, DobutokO.Poetry.UniquenessPeriodsG, DobutokO.Poetry.General   other-extensions:    BangPatterns, CPP, FlexibleInstances, MultiParamTypeClasses   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: