Commits

Grzegorz Chrupała committed db78b4b

Expose count* functions in NLP.Scores instead of the raw count Maps.

  • Participants
  • Parent commits 5372094

Comments (0)

Files changed (1)

nlp-scores/NLP/Scores.hs

     , jaccard
     , entropy
       -- * Extracting joint and marginal counts from 'Counts'
-    , joint 
-      -- ^ Joint counts 
-    , marginalFst
-      -- ^ Counts of the first element
-    , marginalSnd
-      -- ^ Counts of the second element
+    , countJoint
+    , countFst
+    , countSnd
     )
 where
 import qualified Data.Foldable as F
             cs { joint       = Map.insertWith' (+) (P x y) 1 cxy
                , marginalFst = Map.insertWith' (+) x 1 cx
                , marginalSnd = Map.insertWith' (+) y 1 cy }
+
+-- | Joint count
+countJoint :: (Ord a, Ord b) => a -> b -> Counts a b -> Count          
+countJoint x y = Map.findWithDefault 0 (P x y) . joint
+-- | Count of first element
+countFst :: Ord k => k -> Counts k b -> Count
+countFst x = Map.findWithDefault 0 x . marginalFst
+-- | Count of second element
+countSnd :: Ord k => k -> Counts a k -> Count
+countSnd y = Map.findWithDefault 0 y . marginalSnd