packages feed

phladiprelio-general-datatype 0.7.0.0 → 0.10.0.0

raw patch · 5 files changed

+89/−41 lines, 5 filesdep +quantizerPVP ok

version bump matches the API change (PVP)

Dependencies added: quantizer

API changes (from Hackage documentation)

+ Phladiprelio.General.Datatype3: zippedDouble2Word8 :: (Fractional b, Num b, Enum b, Ord b) => [(a, b)] -> [(a, b)]
+ Phladiprelio.General.Distance: sumAbsDistNorm :: Integral a => [a] -> [a] -> a
- Phladiprelio.General.Datatype3: read3 :: (String -> Bool) -> Double -> (String -> [Double]) -> String -> [Double]
+ Phladiprelio.General.Datatype3: read3 :: (String -> Bool) -> Double -> (String -> [Word8]) -> String -> [Word8]
- Phladiprelio.General.Datatype3: readEq4 :: (String -> [Double]) -> (String -> [String]) -> Seq Read0 -> [(String, Double)]
+ Phladiprelio.General.Datatype3: readEq4 :: (String -> [Word8]) -> (String -> [String]) -> Seq Read0 -> [(String, Word8)]
- Phladiprelio.General.Datatype3: readEq4G :: (String -> Bool) -> (String -> [Double]) -> (String -> [String]) -> Seq Read0 -> [(String, Double)]
+ Phladiprelio.General.Datatype3: readEq4G :: (String -> Bool) -> (String -> [Word8]) -> (String -> [String]) -> Seq Read0 -> [(String, Word8)]
- Phladiprelio.General.Datatype3: readSimple3 :: (String -> Bool) -> Double -> (String -> [Double]) -> Seq Read0 -> [Double]
+ Phladiprelio.General.Datatype3: readSimple3 :: (String -> Bool) -> Double -> (String -> [Word8]) -> Seq Read0 -> [Word8]
- Phladiprelio.General.Distance: toEqLength :: Real a => [a] -> [a] -> ([a], [a], Int, Int, Int)
+ Phladiprelio.General.Distance: toEqLength :: [a] -> [a] -> ([a], [a], Int, Int, Int)
- Phladiprelio.General.Distance: toEqLengthL :: Real a => Int -> Int -> [a] -> [a] -> ([a], [a], Int, Int, Int)
+ Phladiprelio.General.Distance: toEqLengthL :: Int -> Int -> [a] -> [a] -> ([a], [a], Int, Int, Int)

Files

CHANGELOG.md view
@@ -65,3 +65,7 @@  * Seventh version. Switched to more time efficient imlementation using Data.Sequence functionality from the containers package. Added it as a new (widely used in many cases) dependency. Some code and documentation improvements. Added readU2 to the export list of the Phladiprelio.General.Datatype3 module. +## 0.10.0.0 -- 2024-04-07++* Tenth version. Switched to another model of computation with mostly Word8 instead of Double. Made a window of versions for the subtle updates of the versions prior to 0.10.0.0. Added a sumAbsDistNorm function.+
Phladiprelio/General/Datatype3.hs view
@@ -1,3 +1,10 @@+-- |+-- Module      :  Phladiprelio.General.Datatype3 +-- Copyright   :  (c) OleksandrZhabenko 2023-2024+-- License     :  MIT+-- Stability   :  Experimental+-- Maintainer  :  oleksandr.zhabenko@yahoo.com+ {-# OPTIONS_GHC -funbox-strict-fields #-} {-# LANGUAGE NoImplicitPrelude, BangPatterns #-} @@ -13,23 +20,28 @@    , read3    , readEq4G     , readEq4 +   , zippedDouble2Word8  ) where  import GHC.Base import GHC.List-import Data.List (groupBy)+import GHC.Word+import GHC.Real (floor,fromIntegral,(/)) +import GHC.Float (int2Double) +import Data.List (groupBy,find) import Data.Char (isDigit, isSpace,isLetter) import Text.Read (readMaybe) import Text.Show (Show(..))-import GHC.Num ((*),(+))+import GHC.Num ((*),(+),(-)) import Data.Maybe (fromMaybe)-import Data.Tuple (snd)+import Data.Tuple (fst,snd) import qualified Data.Foldable as F (foldr)  import qualified Data.Sequence as S+import ListQuantizer (round2GL)   -- | Is a way to read duration of the additional added time period into the line. readU2 :: String -> Double-readU2 xs@(y:ys) = fromMaybe 1.0 (readMaybe (y:'.':(if null ys then "0" else ys))::Maybe Double)+readU2 (y:ys) = fromMaybe 1.0 (readMaybe (y:'.':(if null ys then "0" else ys))::Maybe Double) readU2 _ = 1.0 {-# INLINE readU2 #-} @@ -74,61 +86,71 @@ readSimple3    :: (String -> Bool) -- ^ A special function to check whether the 'String' contains needed information. Must return 'True' for the 'String' that contains the needed for usual processment information, otherwise — 'False'.   -> Double-  -> (String -> [Double])+  -> (String -> [Word8])   -> S.Seq Read0 -- ^ Is should be obtained using 'basicSplit' function here.-  -> [Double]+  -> [Word8] readSimple3 p temp fConvA rs@(C xs S.:<| A x S.:<| ts) -- This branch is fixed in the version 0.6.0.0 because earlier it has an issue.  | null qs = readSimple3 p temp fConvA ts- | null q1 = xl1 : readSimple3 p xl1 fConvA ts- | otherwise = q1 `mappend` (xl1 : readSimple3 p xl1 fConvA ts)+ | null q1 = floor xl1 : readSimple3 p xl1 fConvA ts+ | otherwise = q1 `mappend` (floor xl1 : readSimple3 p xl1 fConvA ts)   where qs            | p xs = fConvA xs           | otherwise = []         (q1,q2s) = splitAtEnd 1 qs         ql1 = head q2s-        xl1=x*ql1+        xl1=min (x*word8ToDouble ql1) 255.0 readSimple3 p temp fConvA rs@(C xs S.:<| ys@(B x S.:<| ts)) = qs `mappend` qqs `mappend` readSimple3 p ql fConvA ws  -  where (ks, ws) = S.spanl isB ys-        qs +  where (!ks, ws) = S.spanl isB ys+        !qs            | p xs = fConvA xs           | otherwise = []-        ql+        !ql           | null qs = 0.0-          | otherwise = last qs-        qqs = F.foldr (\(B k) js -> k * ql:js) [] ks+          | otherwise = word8ToDouble . last $ qs+        qqs = F.foldr (\(B k) js -> double2Word8 (k * ql):js) [] ks readSimple3 p temp fConvA rs@(B x S.:<| ts) = qqs `mappend` readSimple3 p temp fConvA ws    where (ks, ws) = S.spanl isB rs-        qqs = F.foldr (\(B k) js -> k * temp:js) [] ks+        qqs = F.foldr (\(B k) js -> double2Word8 (k * temp) : js) [] ks readSimple3 p temp fConvA (C xs S.:<| _) = qs   where qs            | p xs = fConvA xs           | otherwise = [] readSimple3 _ _ _ _ = [] +-- | Is intended to 'floor' the values greater than 255.0 to 255::'Word8' and to be used for non-negative 'Double'.+double2Word8 :: Double -> Word8+double2Word8 = floor . min 255.0+{-# INLINE double2Word8 #-}++-- | Is done using intermediate 'Int' representation.+word8ToDouble :: Word8 -> Double+word8ToDouble = int2Double . fromIntegral+{-# INLINE word8ToDouble #-}+ read3   :: (String -> Bool) -- ^ A special function to check whether the 'String' contains needed information. Must return 'True' for the 'String' that contains the needed for usual processment information, otherwise — 'False'.  -> Double- -> (String -> [Double])+ -> (String -> [Word8])  -> String - -> [Double]-read3 p temp fConvA = filter (/= 0.0) . readSimple3 p temp fConvA . basicSplit+ -> [Word8]+read3 p temp fConvA = filter (/= 0) . readSimple3 p temp fConvA . basicSplit {-# INLINE read3 #-}  splitAtEnd :: Int -> [a] -> ([a], [a])-splitAtEnd n = (\(x,y,_,_) -> (y,x)) . foldr f v- where v = ([],[],0,n)-       f x (zs,ts,k,n)-        | k < n = (x : zs,[],k + 1,n)-        | otherwise = (zs,x : ts,k + 1,n)+splitAtEnd n = (\(x,y,_) -> (y,x)) . foldr f v+ where v = ([],[],0)+       f x (zs,ts,k)+        | k < n = (x : zs,[],k + 1)+        | otherwise = (zs,x : ts,k + 1)  -- | Is a specialized version of 'Data.InsertLeft.dropFromEndG' function variant from the @subG@ package. Is taken from there to -- reduce the dependencies. Is not intended to be exported at all. dropFromEnd :: Int -> [a] -> [a]-dropFromEnd n = (\(xs,_,_) -> xs) . foldr f v- where v = ([],0,n)-       f x (zs,k,n)-        | k < n = ([],k + 1,n)-        | otherwise = (x : zs,k,n)+dropFromEnd n = (\(xs,_) -> xs) . foldr f v+ where v = ([],0)+       f x (zs,k)+        | k < n = ([],k + 1)+        | otherwise = (x : zs,k)  line2Strings   :: (String -> Bool) -- ^ A special function to check whether the 'String' contains needed information. Must return 'True' for the 'String' that contains the needed for usual processment information, otherwise — 'False'.@@ -149,20 +171,20 @@ -- | Is intended to be used in the "music" mode for PhLADiPreLiO. readEq4G   :: (String -> Bool) -- ^ A special function to check whether the 'String' contains needed information. Must return 'True' for the 'String' that contains the needed for usual processment information, otherwise — 'False'.- -> (String -> [Double])+ -> (String -> [Word8])  -> (String -> [String])  -> S.Seq Read0 -- ^ Is should be obtained using 'basicSplit' function here.- -> [(String, Double)]+ -> [(String, Word8)] readEq4G p fConvA gConvC xs = zip ks rs    where ks = line2Strings p gConvC xs-         rs = filter (/= 0.0) . readSimple3 p 1.0 fConvA $ xs+         rs = filter (/= 0) . readSimple3 p 1.0 fConvA $ xs {-# INLINE readEq4G #-}  readEq4- :: (String -> [Double])+ :: (String -> [Word8])  -> (String -> [String])  -> S.Seq Read0 -- ^ Is should be obtained using 'basicSplit' function here.- -> [(String, Double)]+ -> [(String, Word8)] readEq4 = readEq4G (not . null . filter (not . isSpace)) {-# INLINE readEq4 #-} @@ -171,4 +193,15 @@ showRead0AsInsert d@(B t) = '_':(filter (/= '.') . show $ t) showRead0AsInsert d@(C ts) = ts {-# INLINE showRead0AsInsert #-}++-- | Is intended to be used to transform the earlier data for PhLADiPreLiO representations durations from 'Double' to 'Word8' values. It was used during the transition from the ukrainian-phonetics-basic-array-0.7.1.1 to ukrainian-phonetics-basic-array-0.10.0.0.+zippedDouble2Word8 xs = map (\(t, u) -> (t,fromMaybe 15 . hh $ u)) xs +  where !h = snd . head $ xs+        !lt = snd . last $ xs+        !del = (lt - h)/14.0+        !ys  = take 15 . iterate (+del) $ h+        !zs = zip [1..15] ys+        gg !u = fromMaybe lt . round2GL True (\_ _ -> EQ) ys $ u+        hh !u = fmap fst . find ((== gg u) . snd) $ zs+ 
Phladiprelio/General/Distance.hs view
@@ -3,15 +3,15 @@ module Phladiprelio.General.Distance where  import GHC.Base-import GHC.Real (Fractional(..),Real(..),gcd,quot,(/),fromIntegral)+import GHC.Real (Integral,Fractional(..),Real(..),gcd,quot,(/),fromIntegral,toInteger) import GHC.Float (Floating(..),sqrt) import GHC.List import Data.List (replicate)-import GHC.Num ((*),(-))+import GHC.Num ((*),(-),subtract,abs) --- | 'toEqLength' changes two given lists of non-negative 'Real' numbers into two lists of equal+-- | 'toEqLength' changes two given lists into two lists of equal -- minimal lengths and also returs its new length and initial lengths of the lists given.-toEqLength :: Real a => [a] -> [a] -> ([a],[a],Int,Int,Int)+toEqLength :: [a] -> [a] -> ([a],[a],Int,Int,Int) toEqLength xs ys    | null xs = ([],[],0,0,0)   | null ys = ([],[],0,0,0)@@ -22,11 +22,11 @@              ts = concatMap (replicate (ly `quot` dc)) $ xs              vs = concatMap (replicate (lx `quot` dc)) $ ys --- | 'toEqLengthL' changes two given lists of non-negative 'Real' numbers into two lists of equal+-- | 'toEqLengthL' changes two given lists into two lists of equal -- minimal lengths and also returs its new length and initial lengths of the lists given. Is -- intended to be used when the length of the lists are known and given as the first and the second parameters -- here respectively.-toEqLengthL :: Real a => Int -> Int -> [a] -> [a] -> ([a],[a],Int,Int,Int)+toEqLengthL :: Int -> Int -> [a] -> [a] -> ([a],[a],Int,Int,Int) toEqLengthL lx ly xs ys    | lx == 0 = ([],[],0,0,0)   | ly == 0 = ([],[],0,0,0)@@ -34,6 +34,13 @@        where dc = gcd lx ly              ts = concatMap (replicate (ly `quot` dc)) $ xs              vs = concatMap (replicate (lx `quot` dc)) $ ys++-- | Is also a simplified distance between the lists. Intended to be used with 'Word8'.+sumAbsDistNorm :: (Integral a) => [a] -> [a] -> a+sumAbsDistNorm xs ys + | lc == 0 = 0+ | otherwise = fromIntegral $ sum (zipWith (\x y -> toInteger . abs . subtract x $ y) ts vs) `quot` fromIntegral lc+     where (ts, vs, lc, lx, ly) = toEqLength xs ys   sumSqrDistNorm :: (Real a, Fractional a) => [a] -> [a] -> a sumSqrDistNorm xs ys 
README.md view
@@ -29,6 +29,10 @@  On the 06/01/2024 there was Sophie's Kok, a sister of Emma Kok, 19th Birthday (she is 18). Therefore, the version 0.7.0.0 is additionally devoted also to her. +On the 12/03/2024 there was a Birthday of Emma Kok. She turned 16. Therefore, the version 0.10.0.0 is devoted i.e. tributed to her.++Besides, you can support Ukrainian people in various forms. + All support is welcome, including donations for the needs of the Ukrainian army, IDPs and refugees.   If you would like to share some financial support with the Foundation Gastrostars, please, contact the mentioned foundation
phladiprelio-general-datatype.cabal view
@@ -1,6 +1,6 @@ cabal-version:      1.24 name:               phladiprelio-general-datatype-version:            0.7.0.0+version:            0.10.0.0 synopsis:           Extended functionality of PhLADiPreLiO description:        Can be used not only for language, but also for simpler music and lyrics composing. homepage:           https://hackage.haskell.org/package/phladiprelio-general-datatype@@ -20,6 +20,6 @@     -- other-modules:     other-extensions: NoImplicitPrelude, BangPatterns     ghc-options:      -funbox-strict-fields-    build-depends:    base >=4.13 && <5, containers >=0.5.11.0 && <1+    build-depends:    base >=4.13 && <5, containers >=0.5.11.0 && <1, quantizer ==0.3.1.0     hs-source-dirs:   .     default-language: Haskell2010