packages feed

phonetic-languages-common (empty) → 0.1.0.0

raw patch · 6 files changed

+294/−0 lines, 6 filesdep +basedep +subGdep +vectorsetup-changed

Dependencies added: base, subG, vector

Files

+ CHANGELOG.md view
@@ -0,0 +1,5 @@+# Revision history for phonetic-languages-common++## 0.1.0.0 -- 2020-10-30++* First version. Released on an unsuspecting world.
+ LICENSE view
@@ -0,0 +1,20 @@+Copyright (c) 2020 OleksandrZhabenko++Permission is hereby granted, free of charge, to any person obtaining+a copy of this software and associated documentation files (the+"Software"), to deal in the Software without restriction, including+without limitation the rights to use, copy, modify, merge, publish,+distribute, sublicense, and/or sell copies of the Software, and to+permit persons to whom the Software is furnished to do so, subject to+the following conditions:++The above copyright notice and this permission notice shall be included+in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ Languages/UniquenessPeriods/Vector/DataG.hs view
@@ -0,0 +1,91 @@+-- |+-- Module      :  Languages.UniquenessPeriods.Vector.DataG+-- Copyright   :  (c) OleksandrZhabenko 2020+-- License     :  MIT+-- Stability   :  Experimental+-- Maintainer  :  olexandr543@yahoo.com+--+-- Is a generalization of the DobutokO.Poetry.Data module+-- functionality from the @dobutokO-poetry-general@ package.+--++{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}++module Languages.UniquenessPeriods.Vector.DataG where++import qualified Data.Vector as VB+import Data.SubG++instance (Eq a) => InsertLeft VB.Vector a where+  (%@) = VB.cons+  (%^) = VB.cons++type UniquenessG1T2 t t2 a b = (t2 b,VB.Vector b, t a)++-- | The list in the 'PA' variant represent the prepending @[a]@ and the postpending one respectively. 'K' constuctor actually means no prepending and+-- postpending (usually of the text). Are used basically to control the behaviour of the functions.+data PreApp t a = K | PA (t a) (t a) deriving Eq++class (Foldable t) => UGG1 t a b where+  get1m :: a -> t b+  get2m :: a -> t b+  getm :: Bool -> a -> t b+  getm True = get1m+  getm _ = get2m+  preapp :: a -> t (t b) -> t (t b)+  setm :: t b -> t b -> a++instance Eq a => UGG1 [] (PreApp [] a) a where+  get1m K = []+  get1m (PA xs _) = xs+  get2m K = []+  get2m (PA _ ys) = ys+  preapp K xss = xss+  preapp (PA xs ys) yss = xs:yss ++ [ys]+  setm [] [] = K+  setm xs ys = PA xs ys++instance Eq a => UGG1 VB.Vector (PreApp VB.Vector a) a where+  get1m K = VB.empty+  get1m (PA v _) = v+  get2m K = VB.empty+  get2m (PA _ v) = v+  preapp K v = v+  preapp (PA v1 v2) v3 = preAppend v1 (VB.singleton v2) v3+  setm v1 v2+    | VB.null v1 && VB.null v2 = K+    | otherwise = PA v1 v2++isPA :: PreApp t a -> Bool+isPA K = False+isPA _ = True++isK :: PreApp t a -> Bool+isK K = True+isK _ = False++data UniquenessG2 a b = UL2 (VB.Vector a,b) deriving Eq++instance (Show a, Show b, InsertLeft t a, Foldable t2, Show (t2 b), Show (t a)) => Show (UniquenessG2 (UniquenessG1T2 t t2 a b) (VB.Vector (UniquenessG1T2 t t2 a b))) where+  show (UL2 (ws,_)) = show ws++type UniqG2T2 t t2 a b = UniquenessG2 (UniquenessG1T2 t t2 a b) (VB.Vector (UniquenessG1T2 t t2 a b))++get22 :: UniqG2T2 t t2 a b -> (VB.Vector (UniquenessG1T2 t t2 a b), VB.Vector (UniquenessG1T2 t t2 a b))+get22 (UL2 (ws, x)) = (ws, x)++-- | Is used to avoid significant code duplication.+data FuncRep a b c = U1 (a -> c) | D2 (a -> b) (b -> c)++getAC :: FuncRep a b c -> (a -> c)+getAC (U1 f) = f+getAC (D2 g1 g2) = g2 . g1++isU1 :: FuncRep a b c -> Bool+isU1 (U1 _) = True+isU1 _ = False++isD2 :: FuncRep a b c -> Bool+isD2 (D2 _ _) = True+isD2 _ = False+
+ Languages/UniquenessPeriods/Vector/StrictVG.hs view
@@ -0,0 +1,151 @@+-- |+-- Module      :  Languages.UniquenessPeriods.Vector.StrictVG+-- Copyright   :  (c) OleksandrZhabenko 2020+-- License     :  MIT+-- Stability   :  Experimental+-- Maintainer  :  olexandr543@yahoo.com+--+-- Generalization of the DobutokO.Poetry.StrictV module functionality from+-- the @dobutokO-poetry-general@ package.+-- Can be used to get possible permutations of no more than 7 sublists+-- in the list separated with the elements of the \"whitespace symbols\"+-- list.++{-# LANGUAGE CPP, BangPatterns, FlexibleInstances, MultiParamTypeClasses #-}++module Languages.UniquenessPeriods.Vector.StrictVG (+  universalSetG+  , result+  , resultB+  , uniquenessVariants2GN+  , uniquenessVariants2GNB+  , uniquenessVariants2GNP+  , uniquenessVariants2GNPB+  , genPermutations+  , genPermutationsV+) where++import qualified Data.Vector.Unboxed as V+import qualified Data.Vector as VB+import qualified Data.List as L (permutations)+import Languages.UniquenessPeriods.Vector.DataG+import qualified Data.Foldable as F+import Data.SubG+import Data.Monoid++-- | A generalized variant of the 'uniquenessVariants2GN' function from the @uniqueness-periods-vector-common@ package which, moreover, allows to specify the used permutations.+uniquenessVariants2GNB ::+  (Eq a, Foldable t, InsertLeft t a, Monoid (t a), Monoid (t (t a)), Ord b, Foldable t2) => a -- ^ The first most common element in the \"whitespace symbols\" structure+  -> (t a -> VB.Vector a) -- ^ The function that is used internally to convert to the boxed 'VB.Vector' of @a@ so that the function can process further the permutations+  -> ((t (t a)) -> VB.Vector (VB.Vector a)) -- ^ The function that is used internally to convert to the boxed 'VB.Vector' of 'VB.Vector' of @a@ so that the function can process further+  -> (VB.Vector a -> t a) -- ^ The function that is used internally to convert from the boxed 'VB.Vector' of @a@ so that the function can process further+  -> VB.Vector (VB.Vector Int) -- ^ The list of permutations of 'Int' indices starting from 0 and up to n (n is probably less than 8).+  -> VB.Vector (t2 b -> b)+  -> FuncRep (t a) (VB.Vector c) (t2 b) -- ^ It includes the defined earlier variant with data constructor 'D2', but additionally allows to use just single argument with data constructor 'U1'+  -> t (t a) -- ^ Must be obtained as 'subG' @whspss xs@+  -> VB.Vector (t2 b,VB.Vector b, t a)+uniquenessVariants2GNB !hd f1 f2 f3 perms vN frep !subs = uniquenessVariants2GNPB mempty mempty hd f1 f2 f3 perms vN frep subs+{-# INLINE uniquenessVariants2GNB #-}++-- | A variant of the 'uniquenessVariants2GNB' with the usage of the 'V.Vector' @c@ (an unboxed one) instead of the boxed variant 'VB.Vector' @c@. If @c@ is an instance of the+-- 'V.Unboxed' class then possibly it can be better from the performance point of view to use this variant.+uniquenessVariants2GN ::+  (Eq a, Foldable t, InsertLeft t a, Monoid (t a), Monoid (t (t a)), Ord b, Foldable t2) =>  a -- ^ The first most common element in the whitespace symbols structure+  -> (t a -> VB.Vector a) -- ^ The function that is used internally to convert to the boxed 'VB.Vector' of @a@ so that the function can process further the permutations+  -> ((t (t a)) -> VB.Vector (VB.Vector a)) -- ^ The function that is used internally to convert to the boxed 'VB.Vector' of 'VB.Vector' of @a@ so that the function can process further+  -> (VB.Vector a -> t a) -- ^ The function that is used internally to convert from the boxed 'VB.Vector' of @a@ so that the function can process further+  -> VB.Vector (VB.Vector Int) -- ^ The list of permutations of 'Int' indices starting from 0 and up to n (n is probably less than 8).+  -> VB.Vector (t2 b -> b)+  -> FuncRep (t a) (V.Vector c) (t2 b) -- ^ It includes the defined earlier variant with data constructor 'D2', but additionally allows to use just single argument with data constructor 'U1'+  -> t (t a) -- ^ Must be obtained as 'subG' @whspss xs@+  -> VB.Vector (t2 b,VB.Vector b, t a)+uniquenessVariants2GN !hd f1 f2 f3 perms vN frep !subs = uniquenessVariants2GNP mempty mempty hd f1 f2 f3 perms vN frep subs+{-# INLINE uniquenessVariants2GN #-}++-- | Generalized variant of 'uniquenessVariants2GN' with prepending and appending @[a]@ (given as the first and the second argument).+uniquenessVariants2GNPB ::+  (Eq a, Foldable t, InsertLeft t a, Monoid (t a), Monoid (t (t a)), Ord b, Foldable t2) => t a+  -> t a+  ->  a -- ^ The first most common element in the whitespace symbols structure+  -> (t a -> VB.Vector a) -- ^ The function that is used internally to convert to the boxed 'VB.Vector' of @a@ so that the function can process further the permutations+  -> ((t (t a)) -> VB.Vector (VB.Vector a)) -- ^ The function that is used internally to convert to the boxed 'VB.Vector' of 'VB.Vector' of @a@ so that the function can process further+  -> (VB.Vector a -> t a) -- ^ The function that is used internally to convert from the boxed 'VB.Vector' of @a@ so that the function can process further+  -> VB.Vector (VB.Vector Int) -- ^ The list of permutations of 'Int' indices starting from 0 and up to n (n is probably less than 7).+  -> VB.Vector (t2 b -> b)+  -> FuncRep (t a) (VB.Vector c) (t2 b) -- ^ Since version 0.5.0.0 it includes the previous variant with data constructor 'D2', but additionally allows to use just single argument with data constructor 'U1'+  -> t (t a) -- ^ Must be obtained as @subG whspss xs@+  -> VB.Vector (t2 b,VB.Vector b, t a)+uniquenessVariants2GNPB !ts !us !hd f1 f2 f3 perms vN frep !subs+  | F.null subs = VB.empty+  | otherwise =+     let !uss = (hd %@ us) %^ mempty+         !baseV = VB.map (hd `VB.cons`) . f2 $ subs+         !ns = universalSetG ts uss f1 f2 perms baseV in VB.map (resultB f3 vN frep) ns++-- | Is used internally in the 'uniquenessVariants2GNPB', 'uniquenessVariants2GNP' and related functions. A key point of the evaluation -- the universal set of the task represented as a+-- 'VB.Vector' of 'VB.Vector' of @a@.+universalSetG ::+  (Eq a, Foldable t, InsertLeft t a, Monoid (t a), Monoid (t (t a))) => t a+  -> t (t a)+  -> (t a -> VB.Vector a) -- ^ The function that is used internally to convert to the boxed 'VB.Vector' of @a@ so that the function can process further the permutations+  -> ((t (t a)) -> VB.Vector (VB.Vector a)) -- ^ The function that is used internally to convert to the boxed 'VB.Vector' of 'VB.Vector' of @a@ so that the function can process further+  -> VB.Vector (VB.Vector Int) -- ^ The list of permutations of 'Int' indices starting from 0 and up to n (n is probably less than 7).+  -> VB.Vector (VB.Vector a)+  -> VB.Vector (VB.Vector a)+universalSetG ts uss f1 f2 perms baseV = VB.map (VB.foldr' mappend mempty . VB.cons (f1 ts) . (`mappend` (f2 uss)) . VB.unsafeBackpermute baseV) perms+{-# INLINE universalSetG #-}++-- | A variant of the 'uniquenessVariants2GNPB' with the usage of the 'V.Vector' @c@ (an unboxed one) instead of the boxed variant 'VB.Vector' @c@. If @c@ is an instance of the+-- 'V.Unboxed' class then possibly it can be better from the performance point of view to use this variant.+uniquenessVariants2GNP ::+  (Eq a, Foldable t, InsertLeft t a, Monoid (t a), Monoid (t (t a)), Ord b, Foldable t2) => t a -- ^ The prepending structure.+  -> t a -- ^ The postpending structure.+  -> a -- ^ The first most common element in the whitespace symbols structure.+  -> (t a -> VB.Vector a) -- ^ The function that is used internally to convert to the boxed 'VB.Vector' of @a@ so that the function can process further the permutations+  -> ((t (t a)) -> VB.Vector (VB.Vector a)) -- ^ The function that is used internally to convert to the boxed 'VB.Vector' of 'VB.Vector' of @a@ so that the function can process further+  -> (VB.Vector a -> t a) -- ^ The function that is used internally to convert from the boxed 'VB.Vector' of @a@ so that the function can process further+  -> VB.Vector (VB.Vector Int) -- ^ The list of permutations of 'Int' indices starting from 0 and up to n (n is probably less than 7).+  -> VB.Vector (t2 b -> b)+  -> FuncRep (t a) (V.Vector c) (t2 b) -- ^ It includes the defined earlier variant with data constructor 'D2', but additionally allows to use just single argument with data constructor 'U1'+  -> t (t a) -- ^ Must be obtained as 'subG' @whspss xs@+  -> VB.Vector (t2 b,VB.Vector b, t a)+uniquenessVariants2GNP !ts !us !hd f1 f2 f3 perms vN frep !subs+  | F.null subs = VB.empty+  | otherwise =+     let !uss = (hd %@ us) %^ mempty+         !baseV = VB.map (hd `VB.cons`) . f2 $ subs+         !ns = universalSetG ts uss f1 f2 perms baseV in VB.map (result f3 vN frep) ns++result ::+  (Eq a, Foldable t, Foldable t2) =>+  (VB.Vector a -> t a) -- ^ The function that is used internally to convert from the boxed 'VB.Vector' of @a@ so that the function can process further+  -> VB.Vector (t2 b -> b)+  -> FuncRep (t a) (V.Vector c) (t2 b) -- ^ It includes the defined earlier variant with data constructor 'D2', but additionally allows to use just single argument with data constructor 'U1'+  -> VB.Vector a+  -> (t2 b,VB.Vector b, t a)+result f3 vN frep vs =+  (rs, (VB.map (\f -> f rs) vN), ws)+    where !ws = f3 vs+          !rs = getAC frep ws+{-# INLINE result #-}++resultB ::+  (Eq a, Foldable t, Foldable t2) =>+  (VB.Vector a -> t a) -- ^ The function that is used internally to convert from the boxed 'VB.Vector' of @a@ so that the function can process further+  -> VB.Vector (t2 b -> b)+  -> FuncRep (t a) (VB.Vector c) (t2 b) -- ^ It includes the defined earlier variant with data constructor 'D2', but additionally allows to use just single argument with data constructor 'U1'+  -> VB.Vector a+  -> (t2 b,VB.Vector b, t a)+resultB f3 vN frep vs =+  (rs, (VB.map (\f -> f rs) vN), ws)+    where !ws = f3 vs+          !rs = getAC frep ws+{-# INLINE resultB #-}++genPermutations :: Int -> VB.Vector (VB.Vector Int)+genPermutations n = VB.map VB.fromList . VB.fromList . L.permutations . take n $ [0..]+{-# INLINE genPermutations #-}++genPermutationsV :: VB.Vector (VB.Vector (VB.Vector Int))+genPermutationsV = VB.map (\n -> VB.map VB.fromList . VB.fromList . L.permutations . take n $ [0..]) . VB.enumFromTo 2 $ 7+{-# INLINE genPermutationsV #-}
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ phonetic-languages-common.cabal view
@@ -0,0 +1,25 @@+-- Initial phonetic-languages-common.cabal generated by cabal init.  For+-- further documentation, see http://haskell.org/cabal/users-guide/++name:                phonetic-languages-common+version:             0.1.0.0+synopsis:            A generalization of the uniqueness-periods-vector-common package.+description:         Is intended to use more Data.Vector, Data.Foldable and Data.Monoid functionality.+homepage:            https://hackage.haskell.org/package/phonetic-languages-common+license:             MIT+license-file:        LICENSE+author:              OleksandrZhabenko+maintainer:          olexandr543@yahoo.com+copyright:           (c) 2020 Oleksandr Zhabenko+category:            Language+build-type:          Simple+extra-source-files:  CHANGELOG.md+cabal-version:       >=1.10++library+  exposed-modules:     Languages.UniquenessPeriods.Vector.StrictVG, Languages.UniquenessPeriods.Vector.DataG+  -- other-modules:+  other-extensions:    CPP, BangPatterns, FlexibleInstances, MultiParamTypeClasses+  build-depends:       base >=4.7 && <4.15, vector >=0.11 && <0.14, subG >=0.1.1.1 && <1+  -- hs-source-dirs:+  default-language:    Haskell2010