Grzegorz Chrupała avatar Grzegorz Chrupała committed 90dbd15

Added Monoid instance for NLP.Scores.Counts

Comments (0)

Files changed (2)


   { 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


 -- The package version. See the Haskell 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
Tip: Use camelCasing e.g. ProjME to search for