packages feed

cookbook 2.1.2.0 → 2.1.2.1

raw patch · 4 files changed

+43/−47 lines, 4 files

Files

Cookbook/Ingredients/Lists/Modify.hs view
@@ -41,6 +41,7 @@ intersperse [x] _ = [x] intersperse (x:xs) c =  x:c : intersperse xs c +-- | An equivelant to the terenary operator for Haskell. (?) :: a -> a -> Bool -> a (?) a b c = if c then a else b 
Cookbook/Ingredients/Lists/Stats.hs view
@@ -1,3 +1,13 @@+{- |+   Module      :   Cookbook.Ingredients.Lists.Stats+   Copyright   :   (c) 2014 by Nate Pisarski+   License     :   BSD3+   Maintainer  :   nathanpisarski@gmail.com+   Stability   :   Stable+   Portability :   Portable (Cookbook)+Library for determining mathematically whether two lists are similar.+-}+ module Cookbook.Ingredients.Lists.Stats where  import qualified Cookbook.Ingredients.Lists.Access     as Ac@@ -6,19 +16,22 @@ import qualified Cookbook.Recipes.Sanitize             as Sn import qualified Cookbook.Recipes.Math                 as Ma +-- | Creates a list with the frequency of elements in a list. frequency :: (Eq a) => [a] -> [(a,Int)]  frequency x = let y = map (\c -> (c,Ac.count x c)) x in As.rmDb y +-- | Returns the x-amount of most frequent elements in a list. If there is a "tie", the order it appears in a list takes precedence.  mostFrequent :: (Eq a) => [a] -> Int -> [a] mostFrequent x c = take c $ Md.rev (As.assemble  $ frequency x) +-- | Provides a mathematical score out of 1 based on the similarities between the two words. This is freqScore, but it takes into account length. wordscore :: (Eq a) => [a] -> [a] -> Double wordscore a b = (freqScore a b - 0.1) + (0.1 / realToFrac (if diffLen == 0 then 1 else diffLen))   where diffLen = (abs $(length a) - (length b)) +-- | Provides a frequency score between two lists. freqScore :: (Eq a) => [a] -> [a] -> Double freqScore a b =  (rawFreq / (fromIntegral diffLen))-  where diffLen = fromIntegral (if (length (frequency a)) < (length (frequency b)) then length (frequency a) else length (frequency b))+  where diffLen = fromIntegral  $ length (if (length (frequency a)) < (length (frequency b)) then (frequency a) else (frequency b))         rawFreq = fromIntegral ((sum $ (map (\e -> if e `elem` d then 1 else 0) c)))-        (c:d:_) = map ((flip mostFrequent) diffLen) [a,b] -+        (c:d:_) = map ((flip mostFrequent) diffLen) [a,b]
Cookbook/Recipes/Sanitize.hs view
@@ -1,42 +1,59 @@+{- |+   Module      :   Cookbook.Recipes.Sanitize+   Copyright   :   (c) 2014 by Nate Pisarski+   License     :   BSD3+   Maintainer  :   nathanpisarski@gmail.com+   Stability   :   Stable+   Portability :   Portable (Cookbook)+Library for sanitizing data, mainly strings.+-}+ module Cookbook.Recipes.Sanitize where---"Sanization" is quite the overloaded term. The purpose of this sanitzation lib---is to be as unobtrusive yet flexible as possible. This will generally work with---strings, so some domain-specific solutions for strings are present in this lib  import qualified Cookbook.Essential.Common             as Cm import qualified Cookbook.Ingredients.Lists.Modify     as Md import qualified Cookbook.Ingredients.Lists.Access     as Ac import qualified Cookbook.Ingredients.Functional.Break as Br +-- | Restricts an entire list of information from appearing in another list bit-by-bit. blacklist :: (Eq a) => [a] -> [a] -> [a] blacklist x c = Cm.apply (map (flip Md.rm) c) x +-- | Removes a leading character from a list. rmleading :: (Eq a) => [a] -> a -> [a] rmleading x c = Br.filterBreak (==c) x +-- | Refpos wrapper for two lists, last to first. up :: (Eq a) => ([a],[a]) -> [a] -> [a] up (a,b) c = map (Ac.refpos (a,b)) c +-- | Refpos wrapper for two lists, first to last. down :: (Eq a) => ([a],[a]) -> [a] -> [a] down (a,b) c = map (Ac.refpos (b,a)) c +-- | Removes all doubles in the list, turning them into just one occurrence. rmdb :: (Eq a) => [a] -> [a] rmdb [] = [] rmdb [x] = [x] rmdb (x:y:zs) = if x == y then x: rmdb (Br.removeBreak (== x) (y:zs)) else x : rmdb (y:zs) +-- | Wholly removes doubles from a list. rmdbAll :: (Eq a) => [a] -> [a] rmdbAll [] = [] rmdbAll (x:xs) = x : rmdb (Md.rm xs x) +-- | Moves a string to lower-case. tolower :: String -> String tolower = down (['a'..'z'],['A'..'Z']) +-- | Moves a string to upper-case. toupper :: String -> String toupper = up (['a'..'z'],['A'..'Z']) +-- | Removes all of the leading whitespace from a string. rmlws :: String -> String rmlws = ((flip rmleading) ' ') +-- | Removes all "symbols" from a string. rmsymbols :: String -> String rmsymbols = ((flip blacklist) (['\\'..'`']))
cookbook.cabal view
@@ -1,58 +1,23 @@--- Initial cookbook.cabal generated by cabal init.  For further --- documentation, see http://haskell.org/cabal/users-guide/---- The name of the package. name:                cookbook --- The package version.  See the Haskell package versioning policy (PVP) --- for standards guiding when and how versions should be incremented.--- http://www.haskell.org/haskellwiki/Package_versioning_policy -- PVP summary:      +-+------- breaking API changes --                   | | +----- non-breaking API additions --                   | | | +--- code changes with no API change-version:             2.1.2.0---- A short (one-line) description of the package.+version:             2.1.2.1 synopsis:	Tiered general-purpose libraries with domain-specific applications.---- A longer description of the package.--- description:         ---- The license under which the package is released.+description:		Cookbook is a line of libraries covering a wide variety of Haskell applications. Every application that I make, I add its functions to Cookbook, turning Cookbook into an all-encompassing general-purpose library over time. The claim-to-fame for the library is its use of overloaded typeclasses, called "Continuities".  license:             BSD3---- The file containing the license text. license-file:        LICENSE---- The package author(s). author:              Nate Pisarski---- An email address to which users can send suggestions, bug reports, and --- patches. maintainer:          nathanpisarski@gmail.com- --This package's github repository --https://github.com/natepisarski/Cookbook-hs---- A copyright notice.--- copyright:           - category:            Development-- build-type:          Simple---- Constraint on the version of Cabal needed to build this package. cabal-version:       >=1.8---library-  -- Modules exported by the library.+library    exposed-modules:      Cookbook.Essential.Common, Cookbook.Essential.Continuous, Cookbook.Essential.IO,   Cookbook.Project.Configuration.Configuration, Cookbook.Project.Preprocess.Preprocess, Cookbook.Ingredients.Functional.Break, Cookbook.Ingredients.Lists.Access, Cookbook.Ingredients.Lists.Modify, Cookbook.Ingredients.Lists.Stats, Cookbook.Ingredients.Tupples.Look, Cookbook.Ingredients.Tupples.Assemble,  Cookbook.Recipes.Sanitize, Cookbook.Recipes.Math,Cookbook.Recipes.DataStructures,Cookbook.Recipes.Algorithm, Cookbook.Project.Quill.Quill-  -  -- Modules included in this library but not exported.-  -- other-modules:       -  -  -- Other library packages from which modules are imported.   build-depends:       base ==4.6.*, directory, strict- +source-repository head+  type: git+  location: https://github.com/natepisarski/Cookbook-hs