uniqueness-periods-vector-common (empty) → 0.1.0.0
raw patch · 7 files changed
+248/−0 lines, 7 filesdep +basedep +vectorsetup-changed
Dependencies added: base, vector
Files
- ChangeLog.md +5/−0
- LICENSE +20/−0
- Languages/UniquenessPeriods/Vector/Auxiliary.hs +31/−0
- Languages/UniquenessPeriods/Vector/Data.hs +82/−0
- Languages/UniquenessPeriods/Vector/StrictV.hs +83/−0
- Setup.hs +2/−0
- uniqueness-periods-vector-common.cabal +25/−0
+ ChangeLog.md view
@@ -0,0 +1,5 @@+# Revision history for uniqueness-periods-vector-common++## 0.1.0.0 -- 2020-08-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/Auxiliary.hs view
@@ -0,0 +1,31 @@+-- |+-- Module : Languages.UniquenessPeriods.Vector.Auxiliary+-- Copyright : (c) OleksandrZhabenko 2020+-- License : MIT+-- Stability : Experimental+-- Maintainer : olexandr543@yahoo.com+--+-- Is from the @dobutokO-poetry-general@ package. Is included here +-- to minimize dependencies of the package. +-- Similar functionality is provided by the packages MissingH, extra, ghc +-- and other packages, but they have a lot of dependencies, so here there are +-- less dependencies module and package.++module Languages.UniquenessPeriods.Vector.Auxiliary (+ -- * Help functions+ lastFrom3+ , firstFrom3+ , secondFrom3+) where++lastFrom3 :: (a,b,c) -> c+lastFrom3 (_,_,z) = z+{-# INLINE lastFrom3 #-}++firstFrom3 :: (a, b, c) -> a+firstFrom3 (x, _, _) = x+{-# INLINE firstFrom3 #-}++secondFrom3 :: (a, b, c) -> b+secondFrom3 (_, y, _) = y+{-# INLINE secondFrom3 #-}
+ Languages/UniquenessPeriods/Vector/Data.hs view
@@ -0,0 +1,82 @@+-- |+-- Module : Languages.UniquenessPeriods.Vector.Data+-- 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.Data where++import Data.Maybe (fromJust)+import qualified Data.Vector as V+import Languages.UniquenessPeriods.Vector.Auxiliary (lastFrom3)++type UniquenessG1 a b = ([b],V.Vector b,[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 a = K | PA [a] [a] deriving Eq++class UGG1 a b where+ get1m :: a -> [b]+ get2m :: a -> [b]+ getm :: Bool -> a -> [b]+ getm True = get1m+ getm _ = get2m+ preapp :: a -> [[b]] -> [[b]]+ setm :: [b] -> [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++type Preapp a = PreApp a++isPA :: PreApp a -> Bool+isPA K = False+isPA _ = True++isK :: PreApp a -> Bool+isK K = True+isK _ = False++-- | Is used to control whether to return data or only to print the needed information. The 'U' contstuctor corresponds to the information printing and 'UL' to +-- returning also data. The last one so can be further used.+data UniquenessG a b = U b | UL ([a],b) deriving Eq++instance (Show a, Show b) => Show (UniquenessG a (V.Vector (UniquenessG1 a b))) where+ show (U v) = show . V.map lastFrom3 $ v+ show (UL (wss,_)) = show wss++type UniqG a b = UniquenessG [a] (V.Vector (UniquenessG1 a b)) ++-- | Decomposes the data type 'UniqG' into its components. The inverse to the 'set2'.+get2 :: UniqG a b -> (Maybe [[a]], V.Vector (UniquenessG1 a b))+get2 (U v) = (Nothing,v)+get2 (UL (wss,v)) = (Just wss,v)++-- | Compose the data type 'UniqG' from its components. The inverse to the 'get2'.+set2 :: (Maybe [[a]], V.Vector (UniquenessG1 a b)) -> UniqG a b+set2 (Just wss, v) = UL (wss,v)+set2 (Nothing, v) = U v++isU :: UniqG a b -> Bool+isU (U _) = True+isU _ = False++isUL :: UniqG a b -> Bool+isUL (UL _) = True+isUL _ = False+
+ Languages/UniquenessPeriods/Vector/StrictV.hs view
@@ -0,0 +1,83 @@+-- |+-- Module : Languages.UniquenessPeriods.Vector.StrictV+-- 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 #-}++module Languages.UniquenessPeriods.Vector.StrictV where++#ifdef __GLASGOW_HASKELL__+#if __GLASGOW_HASKELL__>=804+/* code that applies only to GHC 8.4.* and higher versions */+import Data.Semigroup ((<>))+import Prelude hiding ((<>))+#endif+#endif++import qualified Data.Vector as V+import qualified Data.List as L (permutations,intersperse)++-- | Given a [a] consisting of no more than 7 sublists interspersed with the elements of the first argument, +-- it returns a 'V.Vector' of possible combinations without repeating of the sublists in different order and for each of them appends also +-- the information about generalized \"uniqueness periods\" (see @uniqueness-periods-vector@ package) to it and finds out +-- some different metrics -- named \"norms\". +-- +-- Afterwards, depending on these norms some (usually phonetic for the words) properties of the sublists can be specified that +-- allow to use them for special cases of repetitions (usually, for the words -- poetically or to create a varied melody with them). +uniquenessVariants2GN :: + (Eq a, Ord b) => [a] + -> V.Vector ([b] -> b) + -> ([a] -> V.Vector c) + -> (V.Vector c -> [b])+ -> [a] + -> V.Vector ([b],V.Vector b, [a])+uniquenessVariants2GN whspss vN g1 g2 !xs = uniquenessVariants2GNP whspss [] [] vN g1 g2 xs +{-# INLINE uniquenessVariants2GN #-}+ +-- | Generalized variant of 'uniquenessVariants2GN' with prepending and appending @[a]@ (given as the first and the second argument). +uniquenessVariants2GNP :: + (Eq a, Ord b) => [a] + -> [a] + -> [a] + -> V.Vector ([b] -> b) + -> ([a] -> V.Vector c) + -> (V.Vector c -> [b]) + -> [a] + -> V.Vector ([b],V.Vector b, [a])+uniquenessVariants2GNP !ts !us whspss vN g1 g2 !xs + | null . sublistsG whspss $ xs = V.empty+ | not . null $ whspss = let !v0 = V.fromList . take 8 . sublistsG whspss $ xs in+ V.fromList . map ((\vs -> let !rs = g2 . g1 $ vs in (rs, (V.map (\f -> f rs) vN), vs)) . concat . L.intersperse (take 1 whspss) . preAppend ts [us] . V.toList . + V.backpermute v0 . V.fromList) . L.permutations $ ([0..(V.length v0 - 1)]::[Int])+ | otherwise = error "Languages.UniquenessPeriods.Vector.StrictV.uniquenessVariants2GNP: undefined for the empty third argument. "++-- | Inspired by: https://hackage.haskell.org/package/base-4.14.0.0/docs/src/Data.OldList.html#words+sublistsG :: Eq a => [a] -> [a] -> [[a]]+sublistsG whspss xs = + case dropWhile (`elem` whspss) xs of+ [] -> []+ s' -> w : sublistsG whspss s''+ where (w, s'') = break (`elem` whspss) s'++-- | Prepends and appends the given two first arguments to the third one. +preAppend :: [a] -> [[a]] -> [[a]] -> [[a]]+#ifdef __GLASGOW_HASKELL__+#if __GLASGOW_HASKELL__>=804+preAppend ts !uss tss = ts:tss <> uss+#endif+#endif+#ifdef __GLASGOW_HASKELL__+#if __GLASGOW_HASKELL__<804+preAppend ts !uss tss = ts:tss ++ uss+#endif+#endif+{-# INLINE preAppend #-}
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ uniqueness-periods-vector-common.cabal view
@@ -0,0 +1,25 @@+-- Initial uniqueness-periods-vector-common.cabal generated by cabal init.+-- For further documentation, see http://haskell.org/cabal/users-guide/++name: uniqueness-periods-vector-common+version: 0.1.0.0+synopsis: Generalization of the dobutokO-poetry-general package functionality+description: Generalization of the dobutokO-poetry-general package functionality. Can be used to rearrange 7 sublists in the list to obtain somewhat more suitable list for some purposes.+homepage: https://hackage.haskell.org/package/uniqueness-periods-vector-common+license: MIT+license-file: LICENSE+author: OleksandrZhabenko+maintainer: olexandr543@yahoo.com+copyright: Oleksandr Zhabenko+category: Language, Game, Math+build-type: Simple+extra-source-files: ChangeLog.md+cabal-version: >=1.10++library+ exposed-modules: Languages.UniquenessPeriods.Vector.StrictV, Languages.UniquenessPeriods.Vector.Data, Languages.UniquenessPeriods.Vector.Auxiliary+ -- other-modules:+ other-extensions: CPP, BangPatterns, FlexibleInstances, MultiParamTypeClasses+ build-depends: base >=4.7 && <4.15, vector >=0.11 && <0.14+ -- hs-source-dirs:+ default-language: Haskell2010