packages feed

phonetic-languages-constraints 0.3.0.1 → 0.3.1.0

raw patch · 6 files changed

+262/−277 lines, 6 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Languages.UniquenessPeriods.Vector.ConstraintsG: filterOrderIJ :: Int -> Int -> Vector (Vector Int) -> Vector (Vector Int)
- Languages.UniquenessPeriods.Vector.ConstraintsG: unsafeOrderIJ :: Int -> Int -> Vector Int -> Bool
- Languages.UniquenessPeriods.Vector.ConstraintsG: unsafeQuadruples :: Int -> Int -> Int -> Int -> Vector (Vector Int) -> Vector (Vector Int)
- Languages.UniquenessPeriods.Vector.ConstraintsG: unsafeSeveralA :: Int -> Vector Int -> Vector (Vector Int) -> Vector (Vector Int)
- Languages.UniquenessPeriods.Vector.ConstraintsG: unsafeSeveralB :: Int -> Vector Int -> Vector (Vector Int) -> Vector (Vector Int)
- Languages.UniquenessPeriods.Vector.ConstraintsG: unsafeTriples :: Int -> Int -> Int -> Vector (Vector Int) -> Vector (Vector Int)
- Languages.UniquenessPeriods.Vector.ConstraintsG.Encoded: E :: a -> EncodedContraints a b
- Languages.UniquenessPeriods.Vector.ConstraintsG.Encoded: F :: a -> a -> a -> EncodedContraints a b
- Languages.UniquenessPeriods.Vector.ConstraintsG.Encoded: Q :: a -> a -> a -> a -> a -> EncodedContraints a b
- Languages.UniquenessPeriods.Vector.ConstraintsG.Encoded: SA :: a -> a -> b -> EncodedContraints a b
- Languages.UniquenessPeriods.Vector.ConstraintsG.Encoded: SB :: a -> a -> b -> EncodedContraints a b
- Languages.UniquenessPeriods.Vector.ConstraintsG.Encoded: T :: a -> a -> a -> a -> EncodedContraints a b
- Languages.UniquenessPeriods.Vector.ConstraintsG.Encoded: data EncodedContraints a b
- Languages.UniquenessPeriods.Vector.ConstraintsG.Encoded: decodeConstraint1 :: EncodedCnstrs -> Vector (Vector Int) -> Vector (Vector Int)
- Languages.UniquenessPeriods.Vector.ConstraintsG.Encoded: decodeLConstraints :: [EncodedCnstrs] -> Vector (Vector Int) -> Vector (Vector Int)
- Languages.UniquenessPeriods.Vector.ConstraintsG.Encoded: getIEl :: EncodedCnstrs -> Int
- Languages.UniquenessPeriods.Vector.ConstraintsG.Encoded: instance (GHC.Classes.Eq a, GHC.Classes.Eq b) => GHC.Classes.Eq (Languages.UniquenessPeriods.Vector.ConstraintsG.Encoded.EncodedContraints a b)
- Languages.UniquenessPeriods.Vector.ConstraintsG.Encoded: instance (GHC.Classes.Ord a, GHC.Classes.Ord b) => GHC.Classes.Ord (Languages.UniquenessPeriods.Vector.ConstraintsG.Encoded.EncodedContraints a b)
- Languages.UniquenessPeriods.Vector.ConstraintsG.Encoded: isE :: EncodedCnstrs -> Bool
- Languages.UniquenessPeriods.Vector.ConstraintsG.Encoded: isF :: EncodedCnstrs -> Bool
- Languages.UniquenessPeriods.Vector.ConstraintsG.Encoded: isQ :: EncodedCnstrs -> Bool
- Languages.UniquenessPeriods.Vector.ConstraintsG.Encoded: isSA :: EncodedCnstrs -> Bool
- Languages.UniquenessPeriods.Vector.ConstraintsG.Encoded: isSB :: EncodedCnstrs -> Bool
- Languages.UniquenessPeriods.Vector.ConstraintsG.Encoded: isT :: EncodedCnstrs -> Bool
- Languages.UniquenessPeriods.Vector.ConstraintsG.Encoded: readMaybeEC :: Int -> String -> Maybe EncodedCnstrs
- Languages.UniquenessPeriods.Vector.ConstraintsG.Encoded: readMaybeECG :: Int -> String -> Maybe EncodedCnstrs
- Languages.UniquenessPeriods.Vector.ConstraintsG.Encoded: setIEl :: Int -> EncodedCnstrs -> EncodedCnstrs
- Languages.UniquenessPeriods.Vector.ConstraintsG.Encoded: type EncodedCnstrs = EncodedContraints Int (Vector Int)
+ Languages.UniquenessPeriods.Vector.Constraints: filterOrderIJ :: Int -> Int -> Vector (Vector Int) -> Vector (Vector Int)
+ Languages.UniquenessPeriods.Vector.Constraints: unsafeOrderIJ :: Int -> Int -> Vector Int -> Bool
+ Languages.UniquenessPeriods.Vector.Constraints: unsafeQuadruples :: Int -> Int -> Int -> Int -> Vector (Vector Int) -> Vector (Vector Int)
+ Languages.UniquenessPeriods.Vector.Constraints: unsafeSeveralA :: Int -> Vector Int -> Vector (Vector Int) -> Vector (Vector Int)
+ Languages.UniquenessPeriods.Vector.Constraints: unsafeSeveralB :: Int -> Vector Int -> Vector (Vector Int) -> Vector (Vector Int)
+ Languages.UniquenessPeriods.Vector.Constraints: unsafeTriples :: Int -> Int -> Int -> Vector (Vector Int) -> Vector (Vector Int)
+ Languages.UniquenessPeriods.Vector.Constraints.Encoded: E :: a -> EncodedContraints a b
+ Languages.UniquenessPeriods.Vector.Constraints.Encoded: F :: a -> a -> a -> EncodedContraints a b
+ Languages.UniquenessPeriods.Vector.Constraints.Encoded: Q :: a -> a -> a -> a -> a -> EncodedContraints a b
+ Languages.UniquenessPeriods.Vector.Constraints.Encoded: SA :: a -> a -> b -> EncodedContraints a b
+ Languages.UniquenessPeriods.Vector.Constraints.Encoded: SB :: a -> a -> b -> EncodedContraints a b
+ Languages.UniquenessPeriods.Vector.Constraints.Encoded: T :: a -> a -> a -> a -> EncodedContraints a b
+ Languages.UniquenessPeriods.Vector.Constraints.Encoded: data EncodedContraints a b
+ Languages.UniquenessPeriods.Vector.Constraints.Encoded: decodeConstraint1 :: EncodedCnstrs -> Vector (Vector Int) -> Vector (Vector Int)
+ Languages.UniquenessPeriods.Vector.Constraints.Encoded: decodeLConstraints :: [EncodedCnstrs] -> Vector (Vector Int) -> Vector (Vector Int)
+ Languages.UniquenessPeriods.Vector.Constraints.Encoded: getIEl :: EncodedCnstrs -> Int
+ Languages.UniquenessPeriods.Vector.Constraints.Encoded: instance (GHC.Classes.Eq a, GHC.Classes.Eq b) => GHC.Classes.Eq (Languages.UniquenessPeriods.Vector.Constraints.Encoded.EncodedContraints a b)
+ Languages.UniquenessPeriods.Vector.Constraints.Encoded: instance (GHC.Classes.Ord a, GHC.Classes.Ord b) => GHC.Classes.Ord (Languages.UniquenessPeriods.Vector.Constraints.Encoded.EncodedContraints a b)
+ Languages.UniquenessPeriods.Vector.Constraints.Encoded: isE :: EncodedCnstrs -> Bool
+ Languages.UniquenessPeriods.Vector.Constraints.Encoded: isF :: EncodedCnstrs -> Bool
+ Languages.UniquenessPeriods.Vector.Constraints.Encoded: isQ :: EncodedCnstrs -> Bool
+ Languages.UniquenessPeriods.Vector.Constraints.Encoded: isSA :: EncodedCnstrs -> Bool
+ Languages.UniquenessPeriods.Vector.Constraints.Encoded: isSB :: EncodedCnstrs -> Bool
+ Languages.UniquenessPeriods.Vector.Constraints.Encoded: isT :: EncodedCnstrs -> Bool
+ Languages.UniquenessPeriods.Vector.Constraints.Encoded: readMaybeEC :: Int -> String -> Maybe EncodedCnstrs
+ Languages.UniquenessPeriods.Vector.Constraints.Encoded: readMaybeECG :: Int -> String -> Maybe EncodedCnstrs
+ Languages.UniquenessPeriods.Vector.Constraints.Encoded: setIEl :: Int -> EncodedCnstrs -> EncodedCnstrs
+ Languages.UniquenessPeriods.Vector.Constraints.Encoded: type EncodedCnstrs = EncodedContraints Int (Vector Int)

Files

CHANGELOG.md view
@@ -1,25 +1,10 @@ # Revision history for phonetic-languages-constraints -## 0.1.0.0 -- 2020-11-11--* First version. Released on an unsuspecting world.--## 0.2.0.0 -- 2020-11-11--* Second version. Added a function filterOrderIJ to the module Languages.UniquenessPeriods.Vector.ConstaintsG and added a new module -Languages.UniquenessPeriods.Vector.ConstraintsG.Encoded. The last one allows to parse the needed constraints from the command line arguments (generally -speaking, from the String).--## 0.2.1.0 -- 2020-11-11--* Second version revised A. Some code improvements. Added some new functions-predicates to check variants of the EncodedCnstrs.--## 0.3.0.0 -- 2020-11-12--* Third version. Added new function to the module Languages.UniquenessPeriods.Vector.ConstraintsG for quadruples. Changed the data type EncodedConstraints and -EncodedCnstrs and the related functions, added new functions to the module Languages.UniquenessPeriods.Vector.ConstraintsG.Encoded. Some documentation improvements.- ## 0.3.0.1 -- 2020-11-12  * Third version revised A. Fixed incorrect name of the package.++## 0.3.1.0 -- 2020-11-12++* Third version revised B. Changed the names of the modules so that now they are not ambiguous with those analogous ones from the deprecated package phonetic-languages-constaints. 
+ Languages/UniquenessPeriods/Vector/Constraints.hs view
@@ -0,0 +1,78 @@+-- |+-- Module      :  Languages.UniquenessPeriods.Vector.Constraints+-- Copyright   :  (c) OleksandrZhabenko 2020+-- License     :  MIT+-- Stability   :  Experimental+-- Maintainer  :  olexandr543@yahoo.com+--+-- Provides several the most important variants of constraints for the+-- 'VB.Vector' of 'VB.Vector' 'Int' that are permutations. All the 'VB.Vector'+-- here must consists of unique 'Int' starting from 0 to n and the 'Int'+-- arguments must be in the range [0..n] though these inner constraints are+-- not checked. It is up to user to check them.+--++{-# LANGUAGE BangPatterns #-}++module Languages.UniquenessPeriods.Vector.Constraints (+  -- * Basic predicate+  unsafeOrderIJ+  -- * Functions to work with permutations with basic constraints+  , filterOrderIJ+  , unsafeTriples+  , unsafeQuadruples+  -- ** With multiple elements specified+  , unsafeSeveralA+  , unsafeSeveralB+) where++import qualified Data.Vector as VB+import Data.Maybe (fromJust)++-- | Being given the data satisfying the constraints in the module header checks whether in the 'VB.Vector' the first argument stands before the second one.+unsafeOrderIJ :: Int -> Int -> VB.Vector Int -> Bool+unsafeOrderIJ i j v = fromJust (VB.findIndex (== i) v) < fromJust (VB.findIndex (== j) v)++-- | Being given the data satisfying the constraints in the module header returns the elements that satisfy 'unsafeOrderIJ' as a predicate.+filterOrderIJ :: Int -> Int -> VB.Vector (VB.Vector Int) -> VB.Vector (VB.Vector Int)+filterOrderIJ i j = VB.filter (unsafeOrderIJ i j)++-- | Being given the data satisfying the constraints in the module header reduces the number of further computations in the 'VB.Vector' of+-- the permutations each one being represented as 'VB.Vector' 'Int' where 'Int' are all the numbers in the range [0..n] without duplication if the+-- arguments are the indeces of the duplicated words or their concatenated combinations in the corresponding line.+-- The first three arguments+-- are the indices of the the triple duplicated elements (words or their concatenated combinations in the @phonetic-languages@ series of packages).+unsafeTriples :: Int -> Int -> Int -> VB.Vector (VB.Vector Int) -> VB.Vector (VB.Vector Int)+unsafeTriples i j k = VB.filter (\v -> unsafeOrderIJ i j v && unsafeOrderIJ j k v)++-- | Being given the data satisfying the constraints in the module header reduces the number of further computations in the 'VB.Vector' of+-- the permutations each one being represented as 'VB.Vector' 'Int' where 'Int' are all the numbers in the range [0..n] without duplication if the+-- arguments are the indeces of the duplicated words or their concatenated combinations in the corresponding line.+-- The first four arguments+-- are the indices of the the quadruple duplicated elements (words or their concatenated combinations in the @phonetic-languages@ series of packages).+unsafeQuadruples :: Int -> Int -> Int -> Int -> VB.Vector (VB.Vector Int) -> VB.Vector (VB.Vector Int)+unsafeQuadruples i j k l = VB.filter (\v -> unsafeOrderIJ i j v && unsafeOrderIJ j k v && unsafeOrderIJ k l v)++-- | Being given the data satisfying the constraints in the module header reduces the number of further computations in the 'VB.Vector' of+-- the permutations each one being represented as 'VB.Vector' 'Int' where 'Int' are all the numbers in the range [0..n] without duplication.+-- The first argument+-- is the index of the the element (a word or their concatenated combination in the @phonetic-languages@ series of packages), the second argument+-- is 'VB.Vector' of indices that are in the range [0..n]. Filters (and reduces further complex computtions) the permutations so that only the+-- variants with the indices in the second argument all stand AFTER the element with the index equal to the first argument.+unsafeSeveralA :: Int -> VB.Vector Int -> VB.Vector (VB.Vector Int) -> VB.Vector (VB.Vector Int)+unsafeSeveralA !i0 v1 v2 =+ let j !i !v = fromJust (VB.findIndex (== i) v) in+  VB.filter (\v -> g i0 j v v1) v2+   where g !i j !v v3 = VB.all (> j i v) . VB.findIndices (`VB.elem` v3) $ v++-- | Being given the data satisfying the constraints in the module header reduces the number of further computations in the 'VB.Vector' of+-- the permutations each one being represented as 'VB.Vector' 'Int' where 'Int' are all the numbers in the range [0..n] without duplication.+-- The first argument+-- is the index of the the element (a word or their concatenated combination in the @phonetic-languages@ series of packages), the second argument+-- is 'VB.Vector' of indices that are in the range [0..n]. Filters (and reduces further complex computtions) the permutations so that only the+-- variants with the indices in the second argument all stand BEFORE the element with the index equal to the first argument.+unsafeSeveralB :: Int -> VB.Vector Int -> VB.Vector (VB.Vector Int) -> VB.Vector (VB.Vector Int)+unsafeSeveralB !i0 v1 v2 =+ let j !i !v = fromJust (VB.findIndex (== i) v) in+  VB.filter (\v -> g i0 j v v1) v2+   where g !i j !v v3 = VB.all (< j i v) . VB.findIndices (`VB.elem` v3) $ v
+ Languages/UniquenessPeriods/Vector/Constraints/Encoded.hs view
@@ -0,0 +1,178 @@+-- |+-- Module      :  Languages.UniquenessPeriods.Vector.Constraints.Encoded+-- Copyright   :  (c) OleksandrZhabenko 2020+-- License     :  MIT+-- Stability   :  Experimental+-- Maintainer  :  olexandr543@yahoo.com+--+-- Provides a way to encode the needed constraint with possibly less symbols.+--++{-# LANGUAGE FlexibleInstances #-}++module Languages.UniquenessPeriods.Vector.Constraints.Encoded (+  -- * Data types+  EncodedContraints(..)+  , EncodedCnstrs+  -- * Functions to work with them+  -- ** Read functions+  , readMaybeEC+  , readMaybeECG+  -- ** Process-encoding functions+  , decodeConstraint1+  , decodeLConstraints+  -- ** Modifiers and getters+  , getIEl+  , setIEl+  -- ** Predicates+  , isE+  , isF+  , isQ+  , isT+  , isSA+  , isSB+) where++import Data.Monoid (mappend)+import Text.Read (readMaybe)+import Data.Maybe+import qualified Data.Vector as VB+import Data.List (sort,nub)+import Languages.UniquenessPeriods.Vector.Constraints++data EncodedContraints a b = E a | Q a a a a a | T a a a a | SA a a b | SB a a b | F a a a deriving (Eq, Ord)++-- | Inspired by the: https://hackage.haskell.org/package/base-4.14.0.0/docs/Data-Maybe.html+-- Is provided here as a more general way to read the 'String' into a 'EncodedCnstrs' than more restricted+-- but safer 'readMaybeECG'. It is up to user to check whether the parameters are in the correct form, the function does+-- not do the full checking. For phonetic-languages applications, it is better to use 'readMaybeECG' function instead.+readMaybeEC :: Int -> String -> Maybe EncodedCnstrs+readMaybeEC n xs+ | null xs = Nothing+ | n >=0 && n <= 9 =+     let h = take 1 xs+         ts = nub . sort . filter (\x -> x >= '0' && [x] <= show n) . drop 1 $ xs in+      case h of+       "E" -> Just (E (fromMaybe 0 (readMaybe (take 1 . tail $ xs)::Maybe Int)))+       "F" -> let (y,z) = (readMaybe (take 1 ts)::Maybe Int, readMaybe (take 1 . drop 1 $ ts)) in+         case (y,z) of+          (Nothing,_) -> Nothing+          (_,Nothing) -> Nothing+          ~(Just x1, Just x2) -> Just (F undefined x1 x2)+       "T" -> let (y,z,u) = (readMaybe (take 1 ts)::Maybe Int, readMaybe (take 1 . drop 1 $ ts)::Maybe Int, readMaybe (take 1 . drop 2 $ ts)::Maybe Int) in+         case (y,z,u) of+          (Nothing,_,_) -> Nothing+          (_,Nothing,_) -> Nothing+          (_,_,Nothing) -> Nothing+          ~(Just x1, Just x2, Just x3) -> Just (T undefined x1 x2 x3)+       "A" -> let y = readMaybe (take 1 ts)::Maybe Int in+               if isJust y then+                let y0 = fromJust y+                    zs = filter (/= y0) . catMaybes . map (\t -> readMaybe [t]::Maybe Int) . drop 1 $ ts in+                     case zs of+                       [] -> Nothing+                       ~x2 -> Just (SA undefined y0 (VB.fromList x2))+               else Nothing+       "B" -> let y = readMaybe (take 1 ts)::Maybe Int in+               if isJust y then+                let y0 = fromJust y+                    zs = filter (/= y0) . catMaybes . map (\t -> readMaybe [t]::Maybe Int) . drop 1 $ ts in+                     case zs of+                       [] -> Nothing+                       ~x2 -> Just (SB undefined y0 (VB.fromList x2))+               else Nothing+       "Q" -> let (y,z,u,w) = (readMaybe (take 1 ts)::Maybe Int, readMaybe (take 1 . drop 1 $ ts)::Maybe Int, readMaybe (take 1 . drop 2 $ ts)::Maybe Int,+                    readMaybe (take 1 . drop 3 $ ts)::Maybe Int) in+         case (y,z,u,w) of+          (Nothing,_,_,_) -> Nothing+          (_,Nothing,_,_) -> Nothing+          (_,_,Nothing,_) -> Nothing+          (_,_,_,Nothing) -> Nothing+          ~(Just x1, Just x2, Just x3, Just x4) -> Just (Q undefined x1 x2 x3 x4)+       _   -> Nothing+ | otherwise = Nothing++-- | Is used inside 'readMaybeECG' to remove the 'undefined' inside the 'EncodedCnstrs'.+setWordsN :: Int -> Maybe EncodedCnstrs -> Maybe EncodedCnstrs+setWordsN _ Nothing = Nothing+setWordsN _ (Just (E x)) = Just (E x)+setWordsN n (Just (T _ i j k)) = Just (T n i j k)+setWordsN n (Just (Q _ i j k l)) = Just (Q n i j k l)+setWordsN n (Just (SA _ i v)) = Just (SA n i v)+setWordsN n (Just (SB _ i v)) = Just (SB n i v)+setWordsN n (Just (F _ i j)) = Just (F n i j)++-- | A safer variant of the 'readMaybeEC' more suitable for applications, e. g. for phonetic-languages series of packages.+readMaybeECG :: Int -> String -> Maybe EncodedCnstrs+readMaybeECG n xs+  | n <= 6 && n >=0 = setWordsN n . readMaybeEC n $ xs+  | otherwise = Nothing++type EncodedCnstrs = EncodedContraints Int (VB.Vector Int)++-- | Must be applied to the correct vector of permutation indeces. Otherwise, it gives runtime error (exception). All the integers inside the+-- 'EncodedCnstrs' must be in the range [0..n] where @n@ corresponds to the maximum element in the permutation 'VB.Vector' 'Int'. Besides,+-- @n@ is (probably must be) not greater than 6.+decodeConstraint1 :: EncodedCnstrs -> VB.Vector (VB.Vector Int) -> VB.Vector (VB.Vector Int)+decodeConstraint1 (E _) = id+decodeConstraint1 (Q _ i j k l) = unsafeQuadruples i j k l+decodeConstraint1 (T _ i j k) = unsafeTriples i j k+decodeConstraint1 (SA _ i v) = unsafeSeveralA i v+decodeConstraint1 (SB _ i v) = unsafeSeveralB i v+decodeConstraint1 (F _ i j) = filterOrderIJ i j++-- | Must be applied to the correct vector of permutation indeces. Otherwise, it gives runtime error (exception). All the integers inside the+-- 'EncodedCnstrs' must be in the range [0..n] where @n@ corresponds to the maximum element in the permutation 'VB.Vector' 'Int'. Besides,+-- @n@ is (probably must be) not greater than 6.+decodeLConstraints :: [EncodedCnstrs] -> VB.Vector (VB.Vector Int) -> VB.Vector (VB.Vector Int)+decodeLConstraints (x:xs) = decodeLConstraints' ys . decodeConstraint1 y+  where y = minimum (x:xs)+        ys = filter (/= y) . g $ (x:xs)+        g ((E _):zs) = g zs+        g (z:zs) = z : g zs+        g _ = []+        decodeLConstraints' (z:zs) = decodeLConstraints' zs . decodeConstraint1 z+        decodeLConstraints' _ = id+decodeLConstraints _ = id++isE :: EncodedCnstrs -> Bool+isE (E _) = True+isE _ = False++isF :: EncodedCnstrs -> Bool+isF (F _ _ _) = True+isF _ = False++isT :: EncodedCnstrs -> Bool+isT (T _ _ _ _) = True+isT _ = False++isQ :: EncodedCnstrs -> Bool+isQ (Q _ _ _ _ _) = True+isQ _ = False++isSA :: EncodedCnstrs -> Bool+isSA (SA _ _ _) = True+isSA _ = False++isSB :: EncodedCnstrs -> Bool+isSB (SB _ _ _) = True+isSB _ = False++getIEl :: EncodedCnstrs -> Int+getIEl (E i) = i+getIEl (Q _ i _ _ _) = i+getIEl (T _ i _ _) = i+getIEl (SA _ i _) = i+getIEl (SB _ i _) = i+getIEl (F _ i _) = i++setIEl :: Int -> EncodedCnstrs -> EncodedCnstrs+setIEl i (E _) = E i+setIEl i (Q n _ j k l) = Q n i j k l+setIEl i (T n _ j k) = T n i j k+setIEl i (SA n _ v) = SA n i v+setIEl i (SB n _ v) = SB n i v+setIEl i (F n _ j) = F n i j++
− Languages/UniquenessPeriods/Vector/ConstraintsG.hs
@@ -1,78 +0,0 @@--- |--- Module      :  Languages.UniquenessPeriods.Vector.ConstraintsG--- Copyright   :  (c) OleksandrZhabenko 2020--- License     :  MIT--- Stability   :  Experimental--- Maintainer  :  olexandr543@yahoo.com------ Provides several the most important variants of constraints for the--- 'VB.Vector' of 'VB.Vector' 'Int' that are permutations. All the 'VB.Vector'--- here must consists of unique 'Int' starting from 0 to n and the 'Int'--- arguments must be in the range [0..n] though these inner constraints are--- not checked. It is up to user to check them.-----{-# LANGUAGE BangPatterns #-}--module Languages.UniquenessPeriods.Vector.ConstraintsG (-  -- * Basic predicate-  unsafeOrderIJ-  -- * Functions to work with permutations with basic constraints-  , filterOrderIJ-  , unsafeTriples-  , unsafeQuadruples-  -- ** With multiple elements specified-  , unsafeSeveralA-  , unsafeSeveralB-) where--import qualified Data.Vector as VB-import Data.Maybe (fromJust)---- | Being given the data satisfying the constraints in the module header checks whether in the 'VB.Vector' the first argument stands before the second one.-unsafeOrderIJ :: Int -> Int -> VB.Vector Int -> Bool-unsafeOrderIJ i j v = fromJust (VB.findIndex (== i) v) < fromJust (VB.findIndex (== j) v)---- | Being given the data satisfying the constraints in the module header returns the elements that satisfy 'unsafeOrderIJ' as a predicate.-filterOrderIJ :: Int -> Int -> VB.Vector (VB.Vector Int) -> VB.Vector (VB.Vector Int)-filterOrderIJ i j = VB.filter (unsafeOrderIJ i j)---- | Being given the data satisfying the constraints in the module header reduces the number of further computations in the 'VB.Vector' of--- the permutations each one being represented as 'VB.Vector' 'Int' where 'Int' are all the numbers in the range [0..n] without duplication if the--- arguments are the indeces of the duplicated words or their concatenated combinations in the corresponding line.--- The first three arguments--- are the indices of the the triple duplicated elements (words or their concatenated combinations in the @phonetic-languages@ series of packages).-unsafeTriples :: Int -> Int -> Int -> VB.Vector (VB.Vector Int) -> VB.Vector (VB.Vector Int)-unsafeTriples i j k = VB.filter (\v -> unsafeOrderIJ i j v && unsafeOrderIJ j k v)---- | Being given the data satisfying the constraints in the module header reduces the number of further computations in the 'VB.Vector' of--- the permutations each one being represented as 'VB.Vector' 'Int' where 'Int' are all the numbers in the range [0..n] without duplication if the--- arguments are the indeces of the duplicated words or their concatenated combinations in the corresponding line.--- The first four arguments--- are the indices of the the quadruple duplicated elements (words or their concatenated combinations in the @phonetic-languages@ series of packages).-unsafeQuadruples :: Int -> Int -> Int -> Int -> VB.Vector (VB.Vector Int) -> VB.Vector (VB.Vector Int)-unsafeQuadruples i j k l = VB.filter (\v -> unsafeOrderIJ i j v && unsafeOrderIJ j k v && unsafeOrderIJ k l v)---- | Being given the data satisfying the constraints in the module header reduces the number of further computations in the 'VB.Vector' of--- the permutations each one being represented as 'VB.Vector' 'Int' where 'Int' are all the numbers in the range [0..n] without duplication.--- The first argument--- is the index of the the element (a word or their concatenated combination in the @phonetic-languages@ series of packages), the second argument--- is 'VB.Vector' of indices that are in the range [0..n]. Filters (and reduces further complex computtions) the permutations so that only the--- variants with the indices in the second argument all stand AFTER the element with the index equal to the first argument.-unsafeSeveralA :: Int -> VB.Vector Int -> VB.Vector (VB.Vector Int) -> VB.Vector (VB.Vector Int)-unsafeSeveralA !i0 v1 v2 =- let j !i !v = fromJust (VB.findIndex (== i) v) in-  VB.filter (\v -> g i0 j v v1) v2-   where g !i j !v v3 = VB.all (> j i v) . VB.findIndices (`VB.elem` v3) $ v---- | Being given the data satisfying the constraints in the module header reduces the number of further computations in the 'VB.Vector' of--- the permutations each one being represented as 'VB.Vector' 'Int' where 'Int' are all the numbers in the range [0..n] without duplication.--- The first argument--- is the index of the the element (a word or their concatenated combination in the @phonetic-languages@ series of packages), the second argument--- is 'VB.Vector' of indices that are in the range [0..n]. Filters (and reduces further complex computtions) the permutations so that only the--- variants with the indices in the second argument all stand BEFORE the element with the index equal to the first argument.-unsafeSeveralB :: Int -> VB.Vector Int -> VB.Vector (VB.Vector Int) -> VB.Vector (VB.Vector Int)-unsafeSeveralB !i0 v1 v2 =- let j !i !v = fromJust (VB.findIndex (== i) v) in-  VB.filter (\v -> g i0 j v v1) v2-   where g !i j !v v3 = VB.all (< j i v) . VB.findIndices (`VB.elem` v3) $ v
− Languages/UniquenessPeriods/Vector/ConstraintsG/Encoded.hs
@@ -1,178 +0,0 @@--- |--- Module      :  Languages.UniquenessPeriods.Vector.ConstraintsG.Encoded--- Copyright   :  (c) OleksandrZhabenko 2020--- License     :  MIT--- Stability   :  Experimental--- Maintainer  :  olexandr543@yahoo.com------ Provides a way to encode the needed constraint with possibly less symbols.-----{-# LANGUAGE FlexibleInstances #-}--module Languages.UniquenessPeriods.Vector.ConstraintsG.Encoded (-  -- * Data types-  EncodedContraints(..)-  , EncodedCnstrs-  -- * Functions to work with them-  -- ** Read functions-  , readMaybeEC-  , readMaybeECG-  -- ** Process-encoding functions-  , decodeConstraint1-  , decodeLConstraints-  -- ** Modifiers and getters-  , getIEl-  , setIEl-  -- ** Predicates-  , isE-  , isF-  , isQ-  , isT-  , isSA-  , isSB-) where--import Data.Monoid (mappend)-import Text.Read (readMaybe)-import Data.Maybe-import qualified Data.Vector as VB-import Data.List (sort,nub)-import Languages.UniquenessPeriods.Vector.ConstraintsG--data EncodedContraints a b = E a | Q a a a a a | T a a a a | SA a a b | SB a a b | F a a a deriving (Eq, Ord)---- | Inspired by the: https://hackage.haskell.org/package/base-4.14.0.0/docs/Data-Maybe.html--- Is provided here as a more general way to read the 'String' into a 'EncodedCnstrs' than more restricted--- but safer 'readMaybeECG'. It is up to user to check whether the parameters are in the correct form, the function does--- not do the full checking. For phonetic-languages applications, it is better to use 'readMaybeECG' function instead.-readMaybeEC :: Int -> String -> Maybe EncodedCnstrs-readMaybeEC n xs- | null xs = Nothing- | n >=0 && n <= 9 =-     let h = take 1 xs-         ts = nub . sort . filter (\x -> x >= '0' && [x] <= show n) . drop 1 $ xs in-      case h of-       "E" -> Just (E (fromMaybe 0 (readMaybe (take 1 . tail $ xs)::Maybe Int)))-       "F" -> let (y,z) = (readMaybe (take 1 ts)::Maybe Int, readMaybe (take 1 . drop 1 $ ts)) in-         case (y,z) of-          (Nothing,_) -> Nothing-          (_,Nothing) -> Nothing-          ~(Just x1, Just x2) -> Just (F undefined x1 x2)-       "T" -> let (y,z,u) = (readMaybe (take 1 ts)::Maybe Int, readMaybe (take 1 . drop 1 $ ts)::Maybe Int, readMaybe (take 1 . drop 2 $ ts)::Maybe Int) in-         case (y,z,u) of-          (Nothing,_,_) -> Nothing-          (_,Nothing,_) -> Nothing-          (_,_,Nothing) -> Nothing-          ~(Just x1, Just x2, Just x3) -> Just (T undefined x1 x2 x3)-       "A" -> let y = readMaybe (take 1 ts)::Maybe Int in-               if isJust y then-                let y0 = fromJust y-                    zs = filter (/= y0) . catMaybes . map (\t -> readMaybe [t]::Maybe Int) . drop 1 $ ts in-                     case zs of-                       [] -> Nothing-                       ~x2 -> Just (SA undefined y0 (VB.fromList x2))-               else Nothing-       "B" -> let y = readMaybe (take 1 ts)::Maybe Int in-               if isJust y then-                let y0 = fromJust y-                    zs = filter (/= y0) . catMaybes . map (\t -> readMaybe [t]::Maybe Int) . drop 1 $ ts in-                     case zs of-                       [] -> Nothing-                       ~x2 -> Just (SB undefined y0 (VB.fromList x2))-               else Nothing-       "Q" -> let (y,z,u,w) = (readMaybe (take 1 ts)::Maybe Int, readMaybe (take 1 . drop 1 $ ts)::Maybe Int, readMaybe (take 1 . drop 2 $ ts)::Maybe Int,-                    readMaybe (take 1 . drop 3 $ ts)::Maybe Int) in-         case (y,z,u,w) of-          (Nothing,_,_,_) -> Nothing-          (_,Nothing,_,_) -> Nothing-          (_,_,Nothing,_) -> Nothing-          (_,_,_,Nothing) -> Nothing-          ~(Just x1, Just x2, Just x3, Just x4) -> Just (Q undefined x1 x2 x3 x4)-       _   -> Nothing- | otherwise = Nothing---- | Is used inside 'readMaybeECG' to remove the 'undefined' inside the 'EncodedCnstrs'.-setWordsN :: Int -> Maybe EncodedCnstrs -> Maybe EncodedCnstrs-setWordsN _ Nothing = Nothing-setWordsN _ (Just (E x)) = Just (E x)-setWordsN n (Just (T _ i j k)) = Just (T n i j k)-setWordsN n (Just (Q _ i j k l)) = Just (Q n i j k l)-setWordsN n (Just (SA _ i v)) = Just (SA n i v)-setWordsN n (Just (SB _ i v)) = Just (SB n i v)-setWordsN n (Just (F _ i j)) = Just (F n i j)---- | A safer variant of the 'readMaybeEC' more suitable for applications, e. g. for phonetic-languages series of packages.-readMaybeECG :: Int -> String -> Maybe EncodedCnstrs-readMaybeECG n xs-  | n <= 6 && n >=0 = setWordsN n . readMaybeEC n $ xs-  | otherwise = Nothing--type EncodedCnstrs = EncodedContraints Int (VB.Vector Int)---- | Must be applied to the correct vector of permutation indeces. Otherwise, it gives runtime error (exception). All the integers inside the--- 'EncodedCnstrs' must be in the range [0..n] where @n@ corresponds to the maximum element in the permutation 'VB.Vector' 'Int'. Besides,--- @n@ is (probably must be) not greater than 6.-decodeConstraint1 :: EncodedCnstrs -> VB.Vector (VB.Vector Int) -> VB.Vector (VB.Vector Int)-decodeConstraint1 (E _) = id-decodeConstraint1 (Q _ i j k l) = unsafeQuadruples i j k l-decodeConstraint1 (T _ i j k) = unsafeTriples i j k-decodeConstraint1 (SA _ i v) = unsafeSeveralA i v-decodeConstraint1 (SB _ i v) = unsafeSeveralB i v-decodeConstraint1 (F _ i j) = filterOrderIJ i j---- | Must be applied to the correct vector of permutation indeces. Otherwise, it gives runtime error (exception). All the integers inside the--- 'EncodedCnstrs' must be in the range [0..n] where @n@ corresponds to the maximum element in the permutation 'VB.Vector' 'Int'. Besides,--- @n@ is (probably must be) not greater than 6.-decodeLConstraints :: [EncodedCnstrs] -> VB.Vector (VB.Vector Int) -> VB.Vector (VB.Vector Int)-decodeLConstraints (x:xs) = decodeLConstraints' ys . decodeConstraint1 y-  where y = minimum (x:xs)-        ys = filter (/= y) . g $ (x:xs)-        g ((E _):zs) = g zs-        g (z:zs) = z : g zs-        g _ = []-        decodeLConstraints' (z:zs) = decodeLConstraints' zs . decodeConstraint1 z-        decodeLConstraints' _ = id-decodeLConstraints _ = id--isE :: EncodedCnstrs -> Bool-isE (E _) = True-isE _ = False--isF :: EncodedCnstrs -> Bool-isF (F _ _ _) = True-isF _ = False--isT :: EncodedCnstrs -> Bool-isT (T _ _ _ _) = True-isT _ = False--isQ :: EncodedCnstrs -> Bool-isQ (Q _ _ _ _ _) = True-isQ _ = False--isSA :: EncodedCnstrs -> Bool-isSA (SA _ _ _) = True-isSA _ = False--isSB :: EncodedCnstrs -> Bool-isSB (SB _ _ _) = True-isSB _ = False--getIEl :: EncodedCnstrs -> Int-getIEl (E i) = i-getIEl (Q _ i _ _ _) = i-getIEl (T _ i _ _) = i-getIEl (SA _ i _) = i-getIEl (SB _ i _) = i-getIEl (F _ i _) = i--setIEl :: Int -> EncodedCnstrs -> EncodedCnstrs-setIEl i (E _) = E i-setIEl i (Q n _ j k l) = Q n i j k l-setIEl i (T n _ j k) = T n i j k-setIEl i (SA n _ v) = SA n i v-setIEl i (SB n _ v) = SB n i v-setIEl i (F n _ j) = F n i j--
phonetic-languages-constraints.cabal view
@@ -2,7 +2,7 @@ -- For further documentation, see http://haskell.org/cabal/users-guide/  name:                phonetic-languages-constraints-version:             0.3.0.1+version:             0.3.1.0 synopsis:            Constraints to filter the needed permutations description:         Provides several the most important variants of constraints. Can be used with the phonetic-languages-common series of package. homepage:            https://hackage.haskell.org/package/phonetic-languages-constraints@@ -17,7 +17,7 @@ cabal-version:       >=1.10  library-  exposed-modules:     Languages.UniquenessPeriods.Vector.ConstraintsG, Languages.UniquenessPeriods.Vector.ConstraintsG.Encoded+  exposed-modules:     Languages.UniquenessPeriods.Vector.Constraints, Languages.UniquenessPeriods.Vector.Constraints.Encoded   -- other-modules:   other-extensions:    BangPatterns, FlexibleInstances   build-depends:       base >=4.7 && <4.15, vector >=0.11 && <0.14