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
12 {-# LANGUAGE DeriveAnyClass #-}
14 module Gargantext.Core
18 import Data.Either(Either(Left))
19 import Data.Hashable (Hashable)
20 import Data.Morpheus.Types (GQLType)
22 import Data.Text (Text, pack)
23 import Data.Tuple.Extra (swap)
24 import GHC.Generics (Generic)
25 import Gargantext.Prelude
27 import qualified Data.Map as Map
29 ------------------------------------------------------------------------
30 -- | Language of a Text
31 -- For simplicity, we suppose text has an homogenous language
41 -- ... add your language and help us to implement it (:
43 -- | All languages supported
44 -- NOTE: Use international country codes
45 -- https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes
58 deriving (Show, Eq, Ord, Enum, Bounded, Generic, GQLType)
61 instance FromJSON Lang
62 instance ToSchema Lang where
63 declareNamedSchema = genericDeclareNamedSchemaUnrestricted defaultSchemaOptions
64 instance FromHttpApiData Lang
66 parseUrlPiece "All" = pure All
67 parseUrlPiece "DE" = pure DE
68 parseUrlPiece "EL" = pure EL
69 parseUrlPiece "EN" = pure EN
70 parseUrlPiece "ES" = pure ES
71 parseUrlPiece "FR" = pure FR
72 parseUrlPiece "IT" = pure IT
73 parseUrlPiece "PL" = pure PL
74 parseUrlPiece "PT" = pure PT
75 parseUrlPiece "RU" = pure RU
76 parseUrlPiece "UK" = pure UK
77 parseUrlPiece "ZH" = pure ZH
78 parseUrlPiece _ = Left "Unexpected value of Lang"
79 instance ToHttpApiData Lang where
80 toUrlPiece = pack . show
81 instance Hashable Lang
84 allLangs = [minBound ..]
90 -- NOTE: We try to use numeric codes for countries
91 -- https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes
92 -- https://en.wikipedia.org/wiki/ISO_3166-1_numeric#004
93 dbIds :: [(Lang, Int)]
108 instance HasDBid Lang where
109 toDBid lang = case Map.lookup lang $ Map.fromList dbIds of
111 Nothing -> panic "[G.Core] Add this lang to DB ids"
113 fromDBid dbId = case Map.lookup dbId $ Map.fromList $ map swap dbIds of
115 Nothing -> panic "HasDBid lang, not implemented"
117 ------------------------------------------------------------------------
118 data NLPServerConfig = NLPServerConfig
119 { server :: !PosTagAlgo
121 deriving (Show, Eq, Generic)
122 ------------------------------------------------------------------------
125 ------------------------------------------------------------------------
126 data PosTagAlgo = CoreNLP | JohnSnowServer | Spacy
127 deriving (Show, Read, Eq, Ord, Generic, GQLType)
129 instance Hashable PosTagAlgo
131 instance HasDBid PosTagAlgo where
133 toDBid JohnSnowServer = 2
136 fromDBid 2 = JohnSnowServer
138 fromDBid _ = panic "HasDBid posTagAlgo : Not implemented"