packages feed

chatter 0.5.2.1 → 0.6.0.0

raw patch · 5 files changed

+34/−23 lines, 5 filesdep +cereal-textdep +hashabledep +unordered-containersPVP ok

version bump matches the API change (PVP)

Dependencies added: cereal-text, hashable, unordered-containers

API changes (from Hackage documentation)

- Data.DefaultMap: instance (Arbitrary k, Arbitrary v, Ord k) => Arbitrary (DefaultMap k v)
- Data.DefaultMap: instance (NFData k, NFData v, Ord k) => NFData (DefaultMap k v)
- Data.DefaultMap: instance (Ord k, Ord v) => Ord (DefaultMap k v)
- Data.DefaultMap: instance (Ord k, Read k, Read v) => Read (DefaultMap k v)
- Data.DefaultMap: instance (Ord k, Serialize k, Serialize v) => Serialize (DefaultMap k v)
- NLP.Types.Tags: instance Serialize Text
+ Data.DefaultMap: instance (Arbitrary k, Arbitrary v, Hashable k, Eq k) => Arbitrary (DefaultMap k v)
+ Data.DefaultMap: instance (Eq k, Hashable k, Serialize k, Serialize v) => Serialize (DefaultMap k v)
+ Data.DefaultMap: instance (Eq k, Read k, Read v, Hashable k) => Read (DefaultMap k v)
+ Data.DefaultMap: instance (NFData k, NFData v, Hashable k) => NFData (DefaultMap k v)
- Data.DefaultMap: DefMap :: v -> Map k v -> DefaultMap k v
+ Data.DefaultMap: DefMap :: v -> HashMap k v -> DefaultMap k v
- Data.DefaultMap: defMap :: DefaultMap k v -> Map k v
+ Data.DefaultMap: defMap :: DefaultMap k v -> HashMap k v
- Data.DefaultMap: fromList :: Ord k => v -> [(k, v)] -> DefaultMap k v
+ Data.DefaultMap: fromList :: (Eq k, Hashable k) => v -> [(k, v)] -> DefaultMap k v
- Data.DefaultMap: lookup :: Ord k => k -> DefaultMap k v -> v
+ Data.DefaultMap: lookup :: (Eq k, Hashable k) => k -> DefaultMap k v -> v

Files

changelog.md view
@@ -1,3 +1,8 @@+= 0.6.0.0 =++ - Switched to using Hashmap for the DefaultMap implementation;+   this *may* break compatibility with old binary stores.+ = 0.5.2.1 =   - Removed an orphan instance for Text.
chatter.cabal view
@@ -1,5 +1,5 @@ name:                chatter-version:             0.5.2.1+version:             0.6.0.0 synopsis:            A library of simple NLP algorithms. description:         chatter is a collection of simple Natural Language                      Processing algorithms.@@ -78,6 +78,7 @@                      random-shuffle >= 0.0.4,                      MonadRandom    >= 0.1.2,                      cereal         >= 0.4.0.1,+                     cereal-text    >= 0.1 && < 0.2,                      fullstop       >= 0.1.3.1,                      bytestring     >= 0.10.0.0,                      directory,@@ -92,7 +93,9 @@                      regex-tdfa-text,                      array,                      QuickCheck,-                     quickcheck-instances+                     quickcheck-instances,+                     unordered-containers,+                     hashable   
src/Data/DefaultMap.hs view
@@ -2,10 +2,12 @@ module Data.DefaultMap where +import Control.Applicative ((<$>), (<*>)) import Test.QuickCheck (Arbitrary(..)) import Control.DeepSeq (NFData)-import Data.Map (Map)-import qualified Data.Map as Map+import Data.Hashable+import Data.HashMap.Strict (HashMap)+import qualified Data.HashMap.Strict as Map import Data.Serialize import GHC.Generics @@ -13,12 +15,15 @@ -- for a key that does not exist. data DefaultMap k v =    DefMap { defDefault :: v-          , defMap :: Map k v-          } deriving (Read, Show, Eq, Ord, Generic)+          , defMap :: HashMap k v+          } deriving (Read, Show, Eq, Generic) -instance (Ord k, Serialize k, Serialize v) => Serialize (DefaultMap k v)-instance (NFData k, NFData v, Ord k) => NFData (DefaultMap k v)+instance (Eq k, Hashable k, Serialize k, Serialize v) => Serialize (DefaultMap k v) where+  put (DefMap d theMap) = put d >> put (Map.toList theMap)+  get = DefMap <$> get <*> (Map.fromList <$> get) +instance (NFData k, NFData v, Hashable k) => NFData (DefaultMap k v)+ -- | Create an empty `DefaultMap` empty :: v -> DefaultMap k v empty def = DefMap { defDefault = def@@ -26,11 +31,11 @@  -- | Query the map for a value.  Returns the default if the key is not -- found.-lookup :: Ord k => k -> DefaultMap k v ->  v-lookup k m = Map.findWithDefault (defDefault m) k (defMap m)+lookup :: (Eq k, Hashable k) => k -> DefaultMap k v ->  v+lookup k m = Map.lookupDefault (defDefault m) k (defMap m)  -- | Create a `DefaultMap` from a default value and a list.-fromList :: Ord k => v -> [(k, v)] -> DefaultMap k v+fromList :: (Eq k, Hashable k) => v -> [(k, v)] -> DefaultMap k v fromList def entries = DefMap { defDefault = def                               , defMap = Map.fromList entries } @@ -44,9 +49,9 @@ -- over the default value -- this fold behaves in the same way as a -- standard `Data.Map.foldl` foldl :: (a -> b -> a) -> a -> DefaultMap k b -> a-foldl fn acc m = Map.foldl fn acc (defMap m)+foldl fn acc m = Map.foldl' fn acc (defMap m) -instance (Arbitrary k, Arbitrary v, Ord k) => Arbitrary (DefaultMap k v) where+instance (Arbitrary k, Arbitrary v, Hashable k, Eq k) => Arbitrary (DefaultMap k v) where   arbitrary = do       def <- arbitrary       entries <- arbitrary
src/NLP/Similarity/VectorSim.hs view
@@ -20,7 +20,8 @@   -- | Invokes similarity on full strings, using `T.words` for--- tokenization, and no stemming.+-- tokenization, and no stemming. The return value will be in the+-- range [0, 1] -- -- There *must* be at least one document in the corpus. sim :: Corpus -> Text -> Text -> Double@@ -35,6 +36,8 @@ -- implementation.  If you need to run similarity against any single -- document more than once, then you should create `TermVector`s for -- each of your documents and use `tvSim` instead of `similarity`.+-- +-- The return value will be in the range [0, 1]. -- -- There *must* be at least one document in the corpus. similarity :: Corpus -> [Text] -> [Text] -> Double@@ -46,7 +49,8 @@ -- | Determine how similar two documents are. -- -- Calculates the similarity between two documents, represented as--- `TermVectors`+-- `TermVectors`, returning a double in the range [0, 1] where 1 represents+-- "most similar". tvSim :: TermVector -> TermVector -> Double tvSim doc1 doc2 = let   theCos = cosVec doc1 doc2
src/NLP/Types/Tags.hs view
@@ -1,13 +1,12 @@ {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE OverloadedStrings #-}-{-# OPTIONS_GHC -fno-warn-orphans #-} module NLP.Types.Tags where -import Data.Serialize (Serialize, get, put)+import Data.Serialize (Serialize)+import Data.Serialize.Text () import Data.Text (Text) import qualified Data.Text as T-import Data.Text.Encoding (encodeUtf8, decodeUtf8) import GHC.Generics import Text.Read (readEither) @@ -97,8 +96,3 @@   arbitrary = do     NonEmpty str <- arbitrary     return $ RawTag $ T.pack str--instance Serialize Text where-  put txt = put $ encodeUtf8 txt-  get     = fmap decodeUtf8 get-