]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Core.hs
[annuaire] remove duplicated AsyncJobs type
[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 {-# LANGUAGE DeriveAnyClass #-}
13
14 module Gargantext.Core
15 where
16
17 import Data.Text (Text, pack)
18 import Data.Aeson
19 import Data.Either(Either(Left))
20 import Data.Hashable (Hashable)
21 import Data.Morpheus.Types (GQLType)
22 import Data.Swagger
23 import GHC.Generics (Generic)
24 import Gargantext.Prelude
25 import Servant.API
26
27 ------------------------------------------------------------------------
28 -- | Language of a Text
29 -- For simplicity, we suppose text has an homogenous language
30 --
31 -- Next steps: | DE | IT | SP
32 --
33 -- - EN == english
34 -- - FR == french
35 -- - DE == deutch (not implemented yet)
36 -- - IT == italian (not implemented yet)
37 -- - SP == spanish (not implemented yet)
38 --
39 -- ... add your language and help us to implement it (:
40
41 -- | All languages supported
42 -- TODO : DE | SP | CH
43 data Lang = EN | FR | All
44 deriving (Show, Eq, Ord, Bounded, Enum, Generic, GQLType)
45
46 instance ToJSON Lang
47 instance FromJSON Lang
48 instance ToSchema Lang
49 instance FromHttpApiData Lang
50 where
51 parseUrlPiece "EN" = pure EN
52 parseUrlPiece "FR" = pure FR
53 parseUrlPiece "All" = pure All
54 parseUrlPiece _ = Left "Unexpected value of OrderBy"
55 instance ToHttpApiData Lang where
56 toUrlPiece = pack . show
57 instance Hashable Lang
58
59 allLangs :: [Lang]
60 allLangs = [minBound ..]
61
62 class HasDBid a where
63 toDBid :: a -> Int
64 fromDBid :: Int -> a
65
66 instance HasDBid Lang where
67 toDBid All = 0
68 toDBid FR = 1
69 toDBid EN = 2
70
71 fromDBid 0 = All
72 fromDBid 1 = FR
73 fromDBid 2 = EN
74 fromDBid _ = panic "HasDBid lang, not implemented"
75
76 ------------------------------------------------------------------------
77 data NLPServerConfig = NLPServerConfig
78 { server :: !PosTagAlgo
79 , url :: !URI }
80 deriving (Show, Eq)
81 ------------------------------------------------------------------------
82 type Form = Text
83 type Lem = Text
84 ------------------------------------------------------------------------
85 data PosTagAlgo = CoreNLP | JohnSnowServer | Spacy
86 deriving (Show, Read, Eq, Ord, Generic)
87
88 instance Hashable PosTagAlgo
89
90 instance HasDBid PosTagAlgo where
91 toDBid CoreNLP = 1
92 toDBid JohnSnowServer = 2
93 toDBid Spacy = 3
94 fromDBid 1 = CoreNLP
95 fromDBid 2 = JohnSnowServer
96 fromDBid 3 = Spacy
97 fromDBid _ = panic "HasDBid posTagAlgo : Not implemented"