Commit 6af8ff7b authored by Alexandre Delanoë's avatar Alexandre Delanoë

[Ngrams] cosmetics.

parent 8b76e18c
...@@ -25,19 +25,19 @@ example = map terminal ...@@ -25,19 +25,19 @@ example = map terminal
$ chunkAlong 3 1 $ chunkAlong 3 1
$ words "New York and New York is a big apple" $ words "New York and New York is a big apple"
data Terminal = Debut | Terminal Text | Fin data Terminal = Terminal Text | Fin
deriving (Ord, Eq, Show) deriving (Ord, Eq, Show)
isDebutFin :: Terminal -> Bool isFin :: Terminal -> Bool
isDebutFin x = case x of isFin x = case x of
Debut -> True
Fin -> True Fin -> True
_ -> False _ -> False
terminal :: [Text] -> [Terminal] terminal :: [Text] -> [Terminal]
--terminal xs = [Debut] <> (map Terminal xs) <> [Fin]
terminal xs = (map Terminal xs) <> [Fin] terminal xs = (map Terminal xs) <> [Fin]
data Arbre k e = Noeud { _noeud_count :: Double data Arbre k e = Noeud { _noeud_count :: Double
, _noeud_entropy :: e , _noeud_entropy :: e
, _noeud_fils :: Map k (Arbre k e) , _noeud_fils :: Map k (Arbre k e)
...@@ -69,7 +69,7 @@ entropyArbre :: Arbre Terminal () -> Arbre Terminal Double ...@@ -69,7 +69,7 @@ entropyArbre :: Arbre Terminal () -> Arbre Terminal Double
entropyArbre (Feuille c) = Feuille c entropyArbre (Feuille c) = Feuille c
entropyArbre (Noeud c _e fils) = (Noeud c e (map entropyArbre fils)) entropyArbre (Noeud c _e fils) = (Noeud c e (map entropyArbre fils))
where where
e = sum $ map (\(k, f) -> case isDebutFin k of e = sum $ map (\(k, f) -> case isFin k of
True -> (_noeud_count f) / c * log c True -> (_noeud_count f) / c * log c
False -> - c' * log c' False -> - c' * log c'
where where
...@@ -79,7 +79,7 @@ entropyArbre (Noeud c _e fils) = (Noeud c e (map entropyArbre fils)) ...@@ -79,7 +79,7 @@ entropyArbre (Noeud c _e fils) = (Noeud c e (map entropyArbre fils))
normalizeArbre :: Arbre Terminal Double -> Arbre Terminal Double normalizeArbre :: Arbre Terminal Double -> Arbre Terminal Double
normalizeArbre (Feuille c) = Feuille c normalizeArbre (Feuille c) = Feuille c
normalizeArbre (Noeud c e f) = Noeud c e (Map.map (\n -> normalizeLevel n $ Map.elems f) f) normalizeArbre (Noeud c e f) = Noeud c e (Map.map (\a -> normalizeLevel a $ Map.elems f) f)
normalizeLevel :: Arbre Terminal Double -> [Arbre Terminal Double] -> Arbre Terminal Double normalizeLevel :: Arbre Terminal Double -> [Arbre Terminal Double] -> Arbre Terminal Double
normalizeLevel (Feuille c) _ = Feuille c normalizeLevel (Feuille c) _ = Feuille c
...@@ -95,3 +95,4 @@ buildArbre = normalizeArbre . entropyArbre . insertArbres ...@@ -95,3 +95,4 @@ buildArbre = normalizeArbre . entropyArbre . insertArbres
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment