Hlint fixes
This commit is contained in:
parent
e347b4753b
commit
7c8a298f71
@ -1,6 +1,5 @@
|
|||||||
{-# LANGUAGE DataKinds #-}
|
{-# LANGUAGE DataKinds #-}
|
||||||
{-# LANGUAGE DeriveGeneric #-}
|
{-# LANGUAGE DeriveGeneric #-}
|
||||||
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
|
|
||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
{-# LANGUAGE RecordWildCards #-}
|
{-# LANGUAGE RecordWildCards #-}
|
||||||
{-# LANGUAGE TypeFamilies #-}
|
{-# LANGUAGE TypeFamilies #-}
|
||||||
@ -63,6 +62,6 @@ handler =
|
|||||||
findBest :: Model -> Text -> Either Text Text
|
findBest :: Model -> Text -> Either Text Text
|
||||||
findBest model sentence =
|
findBest model sentence =
|
||||||
let caesared = map (\n -> T.map (caesar n) . T.toLower $ sentence) [0..29]
|
let caesared = map (\n -> T.map (caesar n) . T.toLower $ sentence) [0..29]
|
||||||
ranked = sortOn fst $ [(goodness model x, x) | x <- caesared]
|
ranked = sortOn fst [(goodness model x, x) | x <- caesared]
|
||||||
found = find (\(rank, _) -> rank > -7.9) (reverse ranked)
|
found = find (\(rank, _) -> rank > -7.9) (reverse ranked)
|
||||||
in maybe (Left sentence) (Right . snd) found
|
in maybe (Left sentence) (Right . snd) found
|
||||||
|
@ -22,18 +22,18 @@ instance HasModel Model where
|
|||||||
getModel = id
|
getModel = id
|
||||||
setModel = const
|
setModel = const
|
||||||
|
|
||||||
ngram_size :: Int
|
ngramSize :: Int
|
||||||
ngram_size = 3
|
ngramSize = 3
|
||||||
|
|
||||||
buildModel :: Text -> Model
|
buildModel :: Text -> Model
|
||||||
buildModel str =
|
buildModel str =
|
||||||
let parts = ngram ngram_size str
|
let parts = ngram ngramSize str
|
||||||
total = fold parts
|
total = fold parts
|
||||||
in Model{..}
|
in Model{..}
|
||||||
|
|
||||||
goodness :: Model -> Text -> Double
|
goodness :: Model -> Text -> Double
|
||||||
goodness Model{..} str =
|
goodness Model{..} str =
|
||||||
let comparison = M.keys $ ngram ngram_size str
|
let comparison = M.keys $ ngram ngramSize str
|
||||||
ranksum = getSum $ foldMap (Sum . log . elm) comparison
|
ranksum = getSum $ foldMap (Sum . log . elm) comparison
|
||||||
in ranksum / fromIntegral (length comparison)
|
in ranksum / fromIntegral (length comparison)
|
||||||
where
|
where
|
||||||
|
Loading…
Reference in New Issue
Block a user