Commits

Grzegorz Chrupała committed 90dbd15

Added Monoid instance for NLP.Scores.Counts

Comments (0)

Files changed (2)

nlp-scores/NLP/Scores.hs

   { joint :: !(Map.Map (P a b) Count) -- ^ Counts of both components
   , marginalFst :: !(Map.Map a Count) -- ^ Counts of the first component
   , marginalSnd :: !(Map.Map b Count) -- ^ Counts of the second component
-  }
+  } 
 data P a b = P !a !b deriving (Eq, Ord)
 
+instance (Ord a, Ord b) => Monoid (Counts a b) where
+    mempty = empty
+    c `mappend` k = 
+        Counts { joint = Map.unionWith (+) (joint c) (joint k)
+               , marginalFst = Map.unionWith (+) (marginalFst c) (marginalFst k)
+               , marginalSnd = Map.unionWith (+) (marginalSnd c) (marginalSnd k)
+               }
+
 -- | The empty count table
 empty :: (Ord a, Ord b) => Counts a b
 empty = Counts Map.empty Map.empty Map.empty

nlp-scores/nlp-scores.cabal

 -- The package version. See the Haskell package versioning policy
 -- (http://www.haskell.org/haskellwiki/Package_versioning_policy) for
 -- standards guiding when and how versions should be incremented.
-Version:             0.4.2
+Version:             0.4.3
 
 -- A short (one-line) description of the package.
 Synopsis:            Scoring functions commonly used for evaluation in NLP and IR