]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Core.hs
Switch to hsparql-0.3.8
[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 type Form = Text
78 type Lem = Text
79 ------------------------------------------------------------------------
80 data PosTagAlgo = CoreNLP | JohnSnowServer | Spacy
81 deriving (Show, Read, Eq, Ord, Generic)
82
83 instance Hashable PosTagAlgo
84
85 instance HasDBid PosTagAlgo where
86 toDBid CoreNLP = 1
87 toDBid JohnSnowServer = 2
88 toDBid Spacy = 3
89 fromDBid 1 = CoreNLP
90 fromDBid 2 = JohnSnowServer
91 fromDBid 3 = Spacy
92 fromDBid _ = panic "HasDBid posTagAlgo : Not implemented"
93