]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Core.hs
[REFACT] Indexed type more generic
[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 Gargantext.Prelude
16 import GHC.Generics (Generic)
17 import Data.Aeson
18 import Data.Either(Either(Left))
19 import Data.Swagger
20 import Servant.API
21
22 ------------------------------------------------------------------------
23 -- | Language of a Text
24 -- For simplicity, we suppose text has an homogenous language
25 --
26 -- Next steps: | DE | IT | SP
27 --
28 -- - EN == english
29 -- - FR == french
30 -- - DE == deutch (not implemented yet)
31 -- - IT == italian (not implemented yet)
32 -- - SP == spanish (not implemented yet)
33 --
34 -- ... add your language and help us to implement it (:
35
36 -- | All languages supported
37 -- TODO : DE | SP | CH
38 data Lang = EN | FR | All
39 deriving (Show, Eq, Ord, Bounded, Enum, Generic)
40
41 instance ToJSON Lang
42 instance FromJSON Lang
43 instance ToSchema Lang
44 instance FromHttpApiData Lang
45 where
46 parseUrlPiece "EN" = pure EN
47 parseUrlPiece "FR" = pure FR
48 parseUrlPiece "All" = pure All
49 parseUrlPiece _ = Left "Unexpected value of OrderBy"
50 allLangs :: [Lang]
51 allLangs = [minBound ..]
52
53 class HasDBid a where
54 toDBid :: a -> Int
55 fromDBid :: Int -> a
56
57 instance HasDBid Lang where
58 toDBid All = 0
59 toDBid FR = 1
60 toDBid EN = 2
61
62 fromDBid 0 = All
63 fromDBid 1 = FR
64 fromDBid 2 = EN
65 fromDBid _ = panic "HasDBid lang, not implemented"
66
67
68 ------------------------------------------------------------------------
69 data PostTagAlgo = CoreNLP
70 deriving (Show, Read)
71
72 instance HasDBid PostTagAlgo where
73 toDBid CoreNLP = 1
74 fromDBid 1 = CoreNLP
75 fromDBid _ = panic "HasDBid posTagAlgo : Not implemented"
76