]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Core.hs
[FEAT] SQL fun to get lems
[gargantext.git] / src / Gargantext / Core.hs
1 {-|
2 Module : Gargantext.Core
3 Description : Supported Natural language
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
8 Portability : POSIX
9
10 -}
11
12 module Gargantext.Core
13 where
14
15 import Data.Aeson
16 import Data.Either(Either(Left))
17 import Data.Hashable (Hashable)
18 import Data.Swagger
19 import GHC.Generics (Generic)
20 import Gargantext.Prelude
21 import Servant.API
22
23 ------------------------------------------------------------------------
24 -- | Language of a Text
25 -- For simplicity, we suppose text has an homogenous language
26 --
27 -- Next steps: | DE | IT | SP
28 --
29 -- - EN == english
30 -- - FR == french
31 -- - DE == deutch (not implemented yet)
32 -- - IT == italian (not implemented yet)
33 -- - SP == spanish (not implemented yet)
34 --
35 -- ... add your language and help us to implement it (:
36
37 -- | All languages supported
38 -- TODO : DE | SP | CH
39 data Lang = EN | FR | All
40 deriving (Show, Eq, Ord, Bounded, Enum, Generic)
41
42 instance ToJSON Lang
43 instance FromJSON Lang
44 instance ToSchema Lang
45 instance FromHttpApiData Lang
46 where
47 parseUrlPiece "EN" = pure EN
48 parseUrlPiece "FR" = pure FR
49 parseUrlPiece "All" = pure All
50 parseUrlPiece _ = Left "Unexpected value of OrderBy"
51 instance Hashable Lang
52
53 allLangs :: [Lang]
54 allLangs = [minBound ..]
55
56 class HasDBid a where
57 toDBid :: a -> Int
58 fromDBid :: Int -> a
59
60 instance HasDBid Lang where
61 toDBid All = 0
62 toDBid FR = 1
63 toDBid EN = 2
64
65 fromDBid 0 = All
66 fromDBid 1 = FR
67 fromDBid 2 = EN
68 fromDBid _ = panic "HasDBid lang, not implemented"
69
70 ------------------------------------------------------------------------
71 data PosTagAlgo = CoreNLP
72 deriving (Show, Read, Eq, Ord, Generic)
73
74 instance Hashable PosTagAlgo
75
76 instance HasDBid PosTagAlgo where
77 toDBid CoreNLP = 1
78 fromDBid 1 = CoreNLP
79 fromDBid _ = panic "HasDBid posTagAlgo : Not implemented"
80