]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Core.hs
Merge branch 'dev-merge' into dev
[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.Aeson
18 import Data.Either(Either(Left))
19 import Data.Hashable (Hashable)
20 import Data.Morpheus.Types (GQLType)
21 import Data.Swagger
22 import Data.Text (Text)
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 Hashable Lang
56
57 allLangs :: [Lang]
58 allLangs = [minBound ..]
59
60 class HasDBid a where
61 toDBid :: a -> Int
62 fromDBid :: Int -> a
63
64 instance HasDBid Lang where
65 toDBid All = 0
66 toDBid FR = 1
67 toDBid EN = 2
68
69 fromDBid 0 = All
70 fromDBid 1 = FR
71 fromDBid 2 = EN
72 fromDBid _ = panic "HasDBid lang, not implemented"
73
74 ------------------------------------------------------------------------
75 type Form = Text
76 type Lem = Text
77 ------------------------------------------------------------------------
78 data PosTagAlgo = CoreNLP
79 deriving (Show, Read, Eq, Ord, Generic)
80
81 instance Hashable PosTagAlgo
82
83 instance HasDBid PosTagAlgo where
84 toDBid CoreNLP = 1
85 fromDBid 1 = CoreNLP
86 fromDBid _ = panic "HasDBid posTagAlgo : Not implemented"
87