Commit 10ee6b8d authored by Alexandre Delanoë's avatar Alexandre Delanoë

[COSMETICS] facto in Prelude.

parent fc00a623
{-| {-|
Module : Gargantext.Core Module : Gargantext.Core
Description : Description : Which Natural language is supported ?
Copyright : (c) CNRS, 2017-Present Copyright : (c) CNRS, 2017-Present
License : AGPL + CECILL v3 License : AGPL + CECILL v3
Maintainer : team@gargantext.org Maintainer : team@gargantext.org
Stability : experimental Stability : experimental
Portability : POSIX Portability : POSIX
Here is a longer description of this module, containing some
commentary with @some markup@.
-} -}
module Gargantext.Core module Gargantext.Core
...@@ -19,7 +17,6 @@ module Gargantext.Core ...@@ -19,7 +17,6 @@ module Gargantext.Core
-- For simplicity, we suppose text has an homogenous language -- For simplicity, we suppose text has an homogenous language
data Lang = EN | FR data Lang = EN | FR
-- | DE | IT | SP -- | DE | IT | SP
-- EN == english -- EN == english
-- FR == french -- FR == french
......
{-| {-|
Module : Gargantext.Prelude Module : Gargantext.Prelude
Description : Description : Specific Prelude of the project
Copyright : (c) CNRS, 2017-Present Copyright : (c) CNRS, 2017-Present
License : AGPL + CECILL v3 License : AGPL + CECILL v3
Maintainer : team@gargantext.org Maintainer : team@gargantext.org
...@@ -72,18 +72,12 @@ import Text.Show (Show(), show) ...@@ -72,18 +72,12 @@ import Text.Show (Show(), show)
import Text.Read (Read()) import Text.Read (Read())
import Data.String.Conversions (cs) import Data.String.Conversions (cs)
--pf :: (a -> Bool) -> [a] -> [a]
--pf = filter
pr :: [a] -> [a]
pr = reverse
--pm :: (a -> b) -> [a] -> [b]
--pm = map
map2 :: (t -> b) -> [[t]] -> [[b]] map2 :: (t -> b) -> [[t]] -> [[b]]
map2 fun = map (map fun) map2 fun = map (map fun)
-- Some Statistics sugar functions
-- Exponential Average -- Exponential Average
eavg :: [Double] -> Double eavg :: [Double] -> Double
eavg (x:xs) = a*x + (1-a)*(eavg xs) eavg (x:xs) = a*x + (1-a)*(eavg xs)
...@@ -95,6 +89,7 @@ mean :: Fractional a => [a] -> a ...@@ -95,6 +89,7 @@ mean :: Fractional a => [a] -> a
mean xs = if L.null xs then 0.0 mean xs = if L.null xs then 0.0
else sum xs / fromIntegral (length xs) else sum xs / fromIntegral (length xs)
sumMaybe :: Num a => [Maybe a] -> Maybe a sumMaybe :: Num a => [Maybe a] -> Maybe a
sumMaybe = fmap sum . M.sequence sumMaybe = fmap sum . M.sequence
...@@ -187,17 +182,17 @@ trunc' :: Int -> Double -> Double ...@@ -187,17 +182,17 @@ trunc' :: Int -> Double -> Double
trunc' n x = fromIntegral $ truncate $ (x * 10^n) trunc' n x = fromIntegral $ truncate $ (x * 10^n)
bool2int :: Num a => Bool -> a ------------------------------------------------------------------------
bool2int b = case b of bool2num :: Num a => Bool -> a
True -> 1 bool2num True = 1
False -> 0 bool2num False = 0
bool2double :: Bool -> Double bool2double :: Bool -> Double
bool2double bool = case bool of bool2double = bool2num
True -> 1.0
False -> 0.0
bool2int :: Bool -> Int
bool2int = bool2num
------------------------------------------------------------------------
-- Normalizing && scaling data -- Normalizing && scaling data
scale :: [Double] -> [Double] scale :: [Double] -> [Double]
...@@ -217,8 +212,6 @@ scaleNormalize xs = map (\x -> (x - v / (m + 1))) xs' ...@@ -217,8 +212,6 @@ scaleNormalize xs = map (\x -> (x - v / (m + 1))) xs'
m = mean xs' m = mean xs'
xs' = map abs xs xs' = map abs xs
normalize :: [Double] -> [Double] normalize :: [Double] -> [Double]
normalize as = normalizeWith identity as normalize as = normalizeWith identity as
...@@ -234,10 +227,6 @@ zipFst f xs = zip (f xs) xs ...@@ -234,10 +227,6 @@ zipFst f xs = zip (f xs) xs
zipSnd :: ([a] -> [b]) -> [a] -> [(a, b)] zipSnd :: ([a] -> [b]) -> [a] -> [(a, b)]
zipSnd f xs = zip xs (f xs) zipSnd f xs = zip xs (f xs)
-- Just
unMaybe :: [Maybe a] -> [a]
unMaybe = map fromJust . L.filter isJust
-- | maximumWith -- | maximumWith
maximumWith :: (Ord a1, Foldable t) => (a2 -> a1) -> t a2 -> a2 maximumWith :: (Ord a1, Foldable t) => (a2 -> a1) -> t a2 -> a2
maximumWith f = L.maximumBy (compare `on` f) maximumWith f = L.maximumBy (compare `on` f)
......
...@@ -51,7 +51,6 @@ import Data.Graph.Clustering.Louvain.CplusPlus (cLouvain, LouvainNode(..)) ...@@ -51,7 +51,6 @@ import Data.Graph.Clustering.Louvain.CplusPlus (cLouvain, LouvainNode(..))
| |_| | (_| | | | (_| | (_| | | | | || __/> <| |_ | |_| | (_| | | | (_| | (_| | | | | || __/> <| |_
\____|\__,_|_| \__, |\__,_|_| |_|\__\___/_/\_\\__| \____|\__,_|_| \__, |\__,_|_| |_|\__\___/_/\_\\__|
|___/ |___/
-} -}
printDebug :: (Show a, MonadIO m) => [Char] -> a -> m () printDebug :: (Show a, MonadIO m) => [Char] -> a -> m ()
......
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