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