-- Copyright (c) 2016-present, Facebook, Inc.
-- All rights reserved.
--
-- This source code is licensed under the BSD-style license found in the
-- LICENSE file in the root directory of this source tree.


{-# LANGUAGE NoRebindableSyntax #-}


module Duckling.Ranking.Types
  ( Feature
  , BagOfFeatures
  , Class
  , Datum
  , Dataset

  , Classifier(..)
  , Classifiers
  , ClassData(..)

  , infinity
  ) where
import Data.HashMap.Strict (HashMap)
import Data.Text (Text)
import Prelude

-- -----------------------------------------------------------------
-- Aliases

type Feature = Text
type BagOfFeatures = HashMap Feature Int
type Class = Bool
type Datum = (BagOfFeatures, Class)
type Dataset = HashMap Text [Datum]

-- -----------------------------------------------------------------
-- Classification

data Classifier = Classifier
  { Classifier -> ClassData
okData :: ClassData
  , Classifier -> ClassData
koData :: ClassData
  }
  deriving (Classifier -> Classifier -> Bool
(Classifier -> Classifier -> Bool)
-> (Classifier -> Classifier -> Bool) -> Eq Classifier
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Classifier -> Classifier -> Bool
$c/= :: Classifier -> Classifier -> Bool
== :: Classifier -> Classifier -> Bool
$c== :: Classifier -> Classifier -> Bool
Eq, Int -> Classifier -> ShowS
[Classifier] -> ShowS
Classifier -> String
(Int -> Classifier -> ShowS)
-> (Classifier -> String)
-> ([Classifier] -> ShowS)
-> Show Classifier
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Classifier] -> ShowS
$cshowList :: [Classifier] -> ShowS
show :: Classifier -> String
$cshow :: Classifier -> String
showsPrec :: Int -> Classifier -> ShowS
$cshowsPrec :: Int -> Classifier -> ShowS
Show)

type Classifiers = HashMap Text Classifier

data ClassData = ClassData
  { ClassData -> Double
prior :: Double
  , ClassData -> Double
unseen :: Double
  , ClassData -> HashMap Feature Double
likelihoods :: HashMap Feature Double
  , ClassData -> Int
n :: Int
  }
  deriving (ClassData -> ClassData -> Bool
(ClassData -> ClassData -> Bool)
-> (ClassData -> ClassData -> Bool) -> Eq ClassData
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ClassData -> ClassData -> Bool
$c/= :: ClassData -> ClassData -> Bool
== :: ClassData -> ClassData -> Bool
$c== :: ClassData -> ClassData -> Bool
Eq, Int -> ClassData -> ShowS
[ClassData] -> ShowS
ClassData -> String
(Int -> ClassData -> ShowS)
-> (ClassData -> String)
-> ([ClassData] -> ShowS)
-> Show ClassData
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ClassData] -> ShowS
$cshowList :: [ClassData] -> ShowS
show :: ClassData -> String
$cshow :: ClassData -> String
showsPrec :: Int -> ClassData -> ShowS
$cshowsPrec :: Int -> ClassData -> ShowS
Show)

infinity :: Double
infinity :: Double
infinity = Double
1 Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ Double
0