uniqueness-periods-vector 0.1.0.0 → 0.2.0.0
raw patch · 3 files changed
+34/−6 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ String.Languages.UniquenessPeriods.Vector: UG3 :: [b] -> Vector b -> UniquenessGeneral1 a b
+ String.Languages.UniquenessPeriods.Vector: helpUPV3 :: [Int] -> [Int] -> [Int]
+ String.Languages.UniquenessPeriods.Vector: uniquenessPeriodsVector3 :: Eq a => [a] -> Vector a -> UniquenessGeneral2 a
Files
- ChangeLog.md +5/−0
- String/Languages/UniquenessPeriods/Vector.hs +28/−5
- uniqueness-periods-vector.cabal +1/−1
ChangeLog.md view
@@ -3,3 +3,8 @@ ## 0.1.0.0 -- 2020-08-30 * First version. Released on an unsuspecting world.++## 0.2.0.0 -- 2020-09-07++* Second version. Added the new type constuctor UG3 to the UniquenessGeneral1 data type. Added new functions related to uniquenessPeriodsVector3. +
String/Languages/UniquenessPeriods/Vector.hs view
@@ -15,7 +15,7 @@ import qualified Data.Vector as V -data UniquenessGeneral1 a b = UG1 a [b] (V.Vector b) | UG2 a [b] (V.Vector b) deriving Eq+data UniquenessGeneral1 a b = UG1 a [b] (V.Vector b) | UG2 a [b] (V.Vector b) | UG3 [b] (V.Vector b) deriving Eq class UniquenessGeneral a b where get :: a -> b@@ -25,6 +25,7 @@ instance (Eq a) => UniquenessGeneral (UniquenessGeneral1 Bool a) (UniquenessGeneral2 a) where get (UG1 y whspss v) = uniquenessPeriodsVector1 y whspss v get (UG2 y whspss v) = uniquenessPeriodsVector2 y whspss v + get (UG3 whspss v) = uniquenessPeriodsVector3 whspss v -- | List of 'Int' in the result is a list of indexes for the occurrences of the value of the @a@ (usually, @a@ is a sound representation or its duration). -- The first 'Bool' argument defines whether to apply the filtering for not informative (possibly) \"whitespace symbols\" given as the @@ -33,11 +34,11 @@ uniquenessPeriodsVector1 :: Eq a => Bool -> [a] -> V.Vector a -> UniquenessGeneral2 a uniquenessPeriodsVector1 y whspss v | V.null v = V.empty- | otherwise = let !v1 = V.force . V.indexed $ v in + | otherwise = let !v1 = V.indexed v in let f !x = if V.null x then Nothing else Just . (\(v2,v3) -> ((V.toList . V.map fst $ v2,snd . V.unsafeIndex v2 $ 0),v3)) . V.partition (\(_,xs) -> xs == (snd . V.unsafeIndex x $ 0)) $ x in - V.force . (if y then V.filter (\(_,!zs) -> zs `notElem` whspss) else id) . V.unfoldr f $ v1 + (if y then V.filter (\(_,!zs) -> zs `notElem` whspss) else id) . V.unfoldr f $ v1 -- | List of 'Int' in the result is a list of distances between the consequential occurrences of the @a@ (usually, @a@ is a sound representation or its duration) -- in the given 'V.Vector'. The first 'Bool' argument defines whether to apply the filtering for not informative@@ -46,8 +47,30 @@ uniquenessPeriodsVector2 :: Eq a => Bool -> [a] -> V.Vector a -> UniquenessGeneral2 a uniquenessPeriodsVector2 y whspss v | V.null v = V.empty- | otherwise = let !v1 = V.force . V.indexed $ v in + | otherwise = let !v1 = V.indexed v in let f !x = if V.null x then Nothing else Just . (\(v2,v3) -> ((V.toList . (\v4 -> V.zipWith subtract v4 (V.unsafeSlice 1 (V.length v4 -1) v4)) . V.map fst $ v2,snd . V.unsafeIndex v2 $ 0),v3)) . V.partition (\(_,xs) -> xs == (snd . V.unsafeIndex x $ 0)) $ x in - V.force . (if y then V.filter (\(ys,!zs) -> not (null ys) && zs `notElem` whspss) else id) . V.unfoldr f $ v1+ (if y then V.filter (\(ys,!zs) -> not (null ys) && zs `notElem` whspss) else id) . V.unfoldr f $ v1++-- | List of 'Int' in the result is a list of distances between the consequential occurrences of the @a@ (usually, @a@ is a sound representation or its duration)+-- in the given 'V.Vector'. But unlikely the 'uniquenessPeriodsVector2' function it finds out only the distances for the repeated not \"whitespece symbols\" +-- occurring in different sublists separated with these \"whitespace symbols\". Therefore, it is much more perceptable for the words order than the former one. +-- The resulting 'V.Vector' is sorted in the order of the first occurrence of each of +-- the @a@ (usually, @a@ is the sound representation or its duration, or some other its characteristics) in the given second argument.+uniquenessPeriodsVector3 :: Eq a => [a] -> V.Vector a -> UniquenessGeneral2 a+uniquenessPeriodsVector3 whspss v + | V.null v = V.empty+ | otherwise = let !v1 = V.indexed v in let !vs = V.toList . V.findIndices (`elem` whspss) $ v in + let f !x = if V.null x then Nothing + else Just . (\vws (v2,v3) -> ((helpUPV3 vws . V.toList . V.map fst $ v2,snd . + V.unsafeIndex v2 $ 0),v3)) vs . V.partition (\(_,xs) -> xs == (snd . V.unsafeIndex x $ 0)) $ x in + V.filter (\(ys,!zs) -> not (null ys) && (zs `notElem` whspss)) . V.unfoldr f $ v1++-- | Is used inside the 'uniquenessPeriodsVector3'. +helpUPV3 :: [Int] -> [Int] -> [Int]+helpUPV3 (z:zs) (x:y:xs) + | compare ((x - z) * (y - z)) 0 == LT = (y - x):helpUPV3 zs (y:xs)+ | otherwise = helpUPV3 zs (x:y:xs)+helpUPV3 _ _ = []+
uniqueness-periods-vector.cabal view
@@ -2,7 +2,7 @@ -- further documentation, see http://haskell.org/cabal/users-guide/ name: uniqueness-periods-vector-version: 0.1.0.0+version: 0.2.0.0 synopsis: Generalization of the uniqueness-periods and uniqueness-periods-general packages functionality. description: Generalization of the uniqueness-periods and uniqueness-periods-general packages functionality. homepage: https://hackage.haskell.org/package/uniqueness-periods-vector