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
17 import Data.Text (Text, pack)
19 import Data.Either(Either(Left))
20 import Data.Hashable (Hashable)
21 import Data.Morpheus.Types (GQLType)
23 import GHC.Generics (Generic)
24 import Gargantext.Prelude
27 ------------------------------------------------------------------------
28 -- | Language of a Text
29 -- For simplicity, we suppose text has an homogenous language
39 -- ... add your language and help us to implement it (:
41 -- | All languages supported
42 -- NOTE: Use international country codes
43 -- https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes
44 data Lang = EN | FR | DE | IT | PL | ES | CN | All
45 deriving (Show, Eq, Ord, Enum, Bounded, Generic, GQLType)
48 instance FromJSON Lang
49 instance ToSchema Lang where
50 declareNamedSchema = genericDeclareNamedSchemaUnrestricted defaultSchemaOptions
51 instance FromHttpApiData Lang
53 parseUrlPiece "EN" = pure EN
54 parseUrlPiece "FR" = pure FR
55 parseUrlPiece "DE" = pure DE
56 parseUrlPiece "ES" = pure ES
57 parseUrlPiece "IT" = pure IT
58 parseUrlPiece "PL" = pure PL
59 parseUrlPiece "CN" = pure CN
60 parseUrlPiece "All" = pure All
61 parseUrlPiece _ = Left "Unexpected value of Lang"
62 instance ToHttpApiData Lang where
63 toUrlPiece = pack . show
64 instance Hashable Lang
67 allLangs = [minBound ..]
73 -- NOTE: We try to use numeric codes for countries
74 -- https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes
75 -- https://en.wikipedia.org/wiki/ISO_3166-1_numeric#004
76 instance HasDBid Lang where
94 fromDBid _ = panic "HasDBid lang, not implemented"
96 ------------------------------------------------------------------------
97 data NLPServerConfig = NLPServerConfig
98 { server :: !PosTagAlgo
101 ------------------------------------------------------------------------
104 ------------------------------------------------------------------------
105 data PosTagAlgo = CoreNLP | JohnSnowServer | Spacy
106 deriving (Show, Read, Eq, Ord, Generic)
108 instance Hashable PosTagAlgo
110 instance HasDBid PosTagAlgo where
112 toDBid JohnSnowServer = 2
115 fromDBid 2 = JohnSnowServer
117 fromDBid _ = panic "HasDBid posTagAlgo : Not implemented"