{-|
Module      : Gargantext.Core
Description : Supported Natural language
Copyright   : (c) CNRS, 2017-Present
License     : AGPL + CECILL v3
Maintainer  : team@gargantext.org
Stability   : experimental
Portability : POSIX

-}

{-# LANGUAGE DeriveAnyClass             #-}

module Gargantext.Core
  where

import Data.Aeson
import Data.Either(Either(Left))
import Data.Hashable (Hashable)
import Data.Morpheus.Types (GQLType)
import Data.Swagger
import Data.Text (Text)
import GHC.Generics (Generic)
import Gargantext.Prelude
import Servant.API

------------------------------------------------------------------------
-- | Language of a Text
-- For simplicity, we suppose text has an homogenous language
-- 
-- Next steps: | DE | IT | SP
--
--  - EN == english
--  - FR == french
--  - DE == deutch  (not implemented yet)
--  - IT == italian (not implemented yet)
--  - SP == spanish (not implemented yet)
--
--  ... add your language and help us to implement it (:

-- | All languages supported
-- TODO : DE | SP | CH
data Lang = EN | FR | All
  deriving (Int -> Lang -> ShowS
[Lang] -> ShowS
Lang -> String
(Int -> Lang -> ShowS)
-> (Lang -> String) -> ([Lang] -> ShowS) -> Show Lang
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Lang] -> ShowS
$cshowList :: [Lang] -> ShowS
show :: Lang -> String
$cshow :: Lang -> String
showsPrec :: Int -> Lang -> ShowS
$cshowsPrec :: Int -> Lang -> ShowS
Show, Lang -> Lang -> Bool
(Lang -> Lang -> Bool) -> (Lang -> Lang -> Bool) -> Eq Lang
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Lang -> Lang -> Bool
$c/= :: Lang -> Lang -> Bool
== :: Lang -> Lang -> Bool
$c== :: Lang -> Lang -> Bool
Eq, Eq Lang
Eq Lang
-> (Lang -> Lang -> Ordering)
-> (Lang -> Lang -> Bool)
-> (Lang -> Lang -> Bool)
-> (Lang -> Lang -> Bool)
-> (Lang -> Lang -> Bool)
-> (Lang -> Lang -> Lang)
-> (Lang -> Lang -> Lang)
-> Ord Lang
Lang -> Lang -> Bool
Lang -> Lang -> Ordering
Lang -> Lang -> Lang
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Lang -> Lang -> Lang
$cmin :: Lang -> Lang -> Lang
max :: Lang -> Lang -> Lang
$cmax :: Lang -> Lang -> Lang
>= :: Lang -> Lang -> Bool
$c>= :: Lang -> Lang -> Bool
> :: Lang -> Lang -> Bool
$c> :: Lang -> Lang -> Bool
<= :: Lang -> Lang -> Bool
$c<= :: Lang -> Lang -> Bool
< :: Lang -> Lang -> Bool
$c< :: Lang -> Lang -> Bool
compare :: Lang -> Lang -> Ordering
$ccompare :: Lang -> Lang -> Ordering
$cp1Ord :: Eq Lang
Ord, Lang
Lang -> Lang -> Bounded Lang
forall a. a -> a -> Bounded a
maxBound :: Lang
$cmaxBound :: Lang
minBound :: Lang
$cminBound :: Lang
Bounded, Int -> Lang
Lang -> Int
Lang -> [Lang]
Lang -> Lang
Lang -> Lang -> [Lang]
Lang -> Lang -> Lang -> [Lang]
(Lang -> Lang)
-> (Lang -> Lang)
-> (Int -> Lang)
-> (Lang -> Int)
-> (Lang -> [Lang])
-> (Lang -> Lang -> [Lang])
-> (Lang -> Lang -> [Lang])
-> (Lang -> Lang -> Lang -> [Lang])
-> Enum Lang
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: Lang -> Lang -> Lang -> [Lang]
$cenumFromThenTo :: Lang -> Lang -> Lang -> [Lang]
enumFromTo :: Lang -> Lang -> [Lang]
$cenumFromTo :: Lang -> Lang -> [Lang]
enumFromThen :: Lang -> Lang -> [Lang]
$cenumFromThen :: Lang -> Lang -> [Lang]
enumFrom :: Lang -> [Lang]
$cenumFrom :: Lang -> [Lang]
fromEnum :: Lang -> Int
$cfromEnum :: Lang -> Int
toEnum :: Int -> Lang
$ctoEnum :: Int -> Lang
pred :: Lang -> Lang
$cpred :: Lang -> Lang
succ :: Lang -> Lang
$csucc :: Lang -> Lang
Enum, (forall x. Lang -> Rep Lang x)
-> (forall x. Rep Lang x -> Lang) -> Generic Lang
forall x. Rep Lang x -> Lang
forall x. Lang -> Rep Lang x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Lang x -> Lang
$cfrom :: forall x. Lang -> Rep Lang x
Generic, ToValue (KIND Lang)
ToValue (KIND Lang)
-> (forall (f :: * -> *). f Lang -> [SchemaT OUT TypeName])
-> (forall (f :: * -> *). f Lang -> Maybe Text)
-> (forall (f :: * -> *). f Lang -> Map Text Text)
-> (forall (f :: * -> *).
    f Lang -> GQLTypeOptions -> GQLTypeOptions)
-> (forall (f :: * -> *). f Lang -> Map Text (Directives CONST))
-> (forall (f :: * -> *).
    f Lang
    -> Map
         FieldName (Maybe (Value CONST), Maybe (ArgumentsDefinition CONST)))
-> (forall (f :: * -> *). f Lang -> Bool)
-> (forall (f :: * -> *). f Lang -> TypeCategory -> TypeData)
-> GQLType Lang
forall a.
ToValue (KIND a)
-> (forall (f :: * -> *). f a -> [SchemaT OUT TypeName])
-> (forall (f :: * -> *). f a -> Maybe Text)
-> (forall (f :: * -> *). f a -> Map Text Text)
-> (forall (f :: * -> *). f a -> GQLTypeOptions -> GQLTypeOptions)
-> (forall (f :: * -> *). f a -> Map Text (Directives CONST))
-> (forall (f :: * -> *).
    f a
    -> Map
         FieldName (Maybe (Value CONST), Maybe (ArgumentsDefinition CONST)))
-> (forall (f :: * -> *). f a -> Bool)
-> (forall (f :: * -> *). f a -> TypeCategory -> TypeData)
-> GQLType a
forall (f :: * -> *). f Lang -> Bool
forall (f :: * -> *). f Lang -> [SchemaT OUT TypeName]
forall (f :: * -> *). f Lang -> Maybe Text
forall (f :: * -> *). f Lang -> Map Text (Directives CONST)
forall (f :: * -> *). f Lang -> Map Text Text
forall (f :: * -> *).
f Lang
-> Map
     FieldName (Maybe (Value CONST), Maybe (ArgumentsDefinition CONST))
forall (f :: * -> *). f Lang -> GQLTypeOptions -> GQLTypeOptions
forall (f :: * -> *). f Lang -> TypeCategory -> TypeData
__type :: f Lang -> TypeCategory -> TypeData
$c__type :: forall (f :: * -> *). f Lang -> TypeCategory -> TypeData
__isEmptyType :: f Lang -> Bool
$c__isEmptyType :: forall (f :: * -> *). f Lang -> Bool
getFieldContents :: f Lang
-> Map
     FieldName (Maybe (Value CONST), Maybe (ArgumentsDefinition CONST))
$cgetFieldContents :: forall (f :: * -> *).
f Lang
-> Map
     FieldName (Maybe (Value CONST), Maybe (ArgumentsDefinition CONST))
getDirectives :: f Lang -> Map Text (Directives CONST)
$cgetDirectives :: forall (f :: * -> *). f Lang -> Map Text (Directives CONST)
typeOptions :: f Lang -> GQLTypeOptions -> GQLTypeOptions
$ctypeOptions :: forall (f :: * -> *). f Lang -> GQLTypeOptions -> GQLTypeOptions
getDescriptions :: f Lang -> Map Text Text
$cgetDescriptions :: forall (f :: * -> *). f Lang -> Map Text Text
description :: f Lang -> Maybe Text
$cdescription :: forall (f :: * -> *). f Lang -> Maybe Text
implements :: f Lang -> [SchemaT OUT TypeName]
$cimplements :: forall (f :: * -> *). f Lang -> [SchemaT OUT TypeName]
$cp1GQLType :: ToValue (KIND Lang)
GQLType)

instance ToJSON Lang
instance FromJSON Lang
instance ToSchema Lang
instance FromHttpApiData Lang
  where
    parseUrlPiece :: Text -> Either Text Lang
parseUrlPiece Text
"EN"  = Lang -> Either Text Lang
forall (f :: * -> *) a. Applicative f => a -> f a
pure Lang
EN
    parseUrlPiece Text
"FR"  = Lang -> Either Text Lang
forall (f :: * -> *) a. Applicative f => a -> f a
pure Lang
FR
    parseUrlPiece Text
"All" = Lang -> Either Text Lang
forall (f :: * -> *) a. Applicative f => a -> f a
pure Lang
All
    parseUrlPiece Text
_     = Text -> Either Text Lang
forall a b. a -> Either a b
Left Text
"Unexpected value of OrderBy"
instance Hashable Lang

allLangs :: [Lang]
allLangs :: [Lang]
allLangs = [Lang
forall a. Bounded a => a
minBound ..]

class HasDBid a where
  toDBid   :: a   -> Int
  fromDBid :: Int -> a

instance HasDBid Lang where
  toDBid :: Lang -> Int
toDBid Lang
All = Int
0
  toDBid Lang
FR  = Int
1
  toDBid Lang
EN  = Int
2

  fromDBid :: Int -> Lang
fromDBid Int
0 = Lang
All
  fromDBid Int
1 = Lang
FR
  fromDBid Int
2 = Lang
EN
  fromDBid Int
_ = Text -> Lang
forall a. HasCallStack => Text -> a
panic Text
"HasDBid lang, not implemented"

------------------------------------------------------------------------
type Form = Text
type Lem  = Text
------------------------------------------------------------------------
data PosTagAlgo = CoreNLP
  deriving (Int -> PosTagAlgo -> ShowS
[PosTagAlgo] -> ShowS
PosTagAlgo -> String
(Int -> PosTagAlgo -> ShowS)
-> (PosTagAlgo -> String)
-> ([PosTagAlgo] -> ShowS)
-> Show PosTagAlgo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PosTagAlgo] -> ShowS
$cshowList :: [PosTagAlgo] -> ShowS
show :: PosTagAlgo -> String
$cshow :: PosTagAlgo -> String
showsPrec :: Int -> PosTagAlgo -> ShowS
$cshowsPrec :: Int -> PosTagAlgo -> ShowS
Show, ReadPrec [PosTagAlgo]
ReadPrec PosTagAlgo
Int -> ReadS PosTagAlgo
ReadS [PosTagAlgo]
(Int -> ReadS PosTagAlgo)
-> ReadS [PosTagAlgo]
-> ReadPrec PosTagAlgo
-> ReadPrec [PosTagAlgo]
-> Read PosTagAlgo
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PosTagAlgo]
$creadListPrec :: ReadPrec [PosTagAlgo]
readPrec :: ReadPrec PosTagAlgo
$creadPrec :: ReadPrec PosTagAlgo
readList :: ReadS [PosTagAlgo]
$creadList :: ReadS [PosTagAlgo]
readsPrec :: Int -> ReadS PosTagAlgo
$creadsPrec :: Int -> ReadS PosTagAlgo
Read, PosTagAlgo -> PosTagAlgo -> Bool
(PosTagAlgo -> PosTagAlgo -> Bool)
-> (PosTagAlgo -> PosTagAlgo -> Bool) -> Eq PosTagAlgo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PosTagAlgo -> PosTagAlgo -> Bool
$c/= :: PosTagAlgo -> PosTagAlgo -> Bool
== :: PosTagAlgo -> PosTagAlgo -> Bool
$c== :: PosTagAlgo -> PosTagAlgo -> Bool
Eq, Eq PosTagAlgo
Eq PosTagAlgo
-> (PosTagAlgo -> PosTagAlgo -> Ordering)
-> (PosTagAlgo -> PosTagAlgo -> Bool)
-> (PosTagAlgo -> PosTagAlgo -> Bool)
-> (PosTagAlgo -> PosTagAlgo -> Bool)
-> (PosTagAlgo -> PosTagAlgo -> Bool)
-> (PosTagAlgo -> PosTagAlgo -> PosTagAlgo)
-> (PosTagAlgo -> PosTagAlgo -> PosTagAlgo)
-> Ord PosTagAlgo
PosTagAlgo -> PosTagAlgo -> Bool
PosTagAlgo -> PosTagAlgo -> Ordering
PosTagAlgo -> PosTagAlgo -> PosTagAlgo
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: PosTagAlgo -> PosTagAlgo -> PosTagAlgo
$cmin :: PosTagAlgo -> PosTagAlgo -> PosTagAlgo
max :: PosTagAlgo -> PosTagAlgo -> PosTagAlgo
$cmax :: PosTagAlgo -> PosTagAlgo -> PosTagAlgo
>= :: PosTagAlgo -> PosTagAlgo -> Bool
$c>= :: PosTagAlgo -> PosTagAlgo -> Bool
> :: PosTagAlgo -> PosTagAlgo -> Bool
$c> :: PosTagAlgo -> PosTagAlgo -> Bool
<= :: PosTagAlgo -> PosTagAlgo -> Bool
$c<= :: PosTagAlgo -> PosTagAlgo -> Bool
< :: PosTagAlgo -> PosTagAlgo -> Bool
$c< :: PosTagAlgo -> PosTagAlgo -> Bool
compare :: PosTagAlgo -> PosTagAlgo -> Ordering
$ccompare :: PosTagAlgo -> PosTagAlgo -> Ordering
$cp1Ord :: Eq PosTagAlgo
Ord, (forall x. PosTagAlgo -> Rep PosTagAlgo x)
-> (forall x. Rep PosTagAlgo x -> PosTagAlgo) -> Generic PosTagAlgo
forall x. Rep PosTagAlgo x -> PosTagAlgo
forall x. PosTagAlgo -> Rep PosTagAlgo x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PosTagAlgo x -> PosTagAlgo
$cfrom :: forall x. PosTagAlgo -> Rep PosTagAlgo x
Generic)

instance Hashable PosTagAlgo

instance HasDBid PosTagAlgo where
  toDBid :: PosTagAlgo -> Int
toDBid PosTagAlgo
CoreNLP = Int
1
  fromDBid :: Int -> PosTagAlgo
fromDBid Int
1 = PosTagAlgo
CoreNLP
  fromDBid Int
_ = Text -> PosTagAlgo
forall a. HasCallStack => Text -> a
panic Text
"HasDBid posTagAlgo : Not implemented"