Context.purs 4.6 KB
Newer Older
1
module Gargantext.Components.GraphQL.Context
2 3 4 5 6
  ( Context_
  , Context
  , Hyperdata_
  , Hyperdata
  , NodeContext
7
  , NodeContext_
8
  , nodeContextQuery
9
  , NodeContextCategoryM
10
  , contextsForNgramsQuery
11
  , NgramsTerms(..)
12 13 14 15
  ) where

import Gargantext.Prelude

16
import Data.Argonaut (class EncodeJson, encodeJson)
17 18
import Data.Lens (Lens', lens)
import Data.Maybe (Maybe(..), fromMaybe)
19
import GraphQL.Client.Args (Args, NotNull, (=>>), class ArgGql)
20
import GraphQL.Client.Variable (Var(..))
21
import GraphQL.Client.Variables.TypeName (class VarTypeName, varTypeName)
22 23
import Gargantext.Utils.GraphQL as GGQL
import Type.Proxy (Proxy(..))
24 25 26

import Data.Array as A

27 28 29 30
type Context_
  = ( c_id        :: Int
    , c_name      :: String
    , c_typename  :: Int
31 32
    , c_date      :: String
    , c_hash_id   :: Maybe String
33
    , c_user_id   :: Int
34 35 36
    , c_parent_id :: Maybe Int
    , c_category  :: Maybe Int
    , c_score     :: Maybe Int  -- TODO: Maybe Double
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
    , c_hyperdata :: Maybe Hyperdata )

type Context = Record Context_

type Hyperdata_
  = ( hrd_abstract           :: String
    , hrd_authors            :: String
    , hrd_bdd                :: String
    , hrd_doi                :: String
    , hrd_institutes         :: String
    , hrd_language_iso2      :: String
    , hrd_page               :: Int
    , hrd_publication_date   :: String
    , hrd_publication_day    :: Int
    , hrd_publication_hour   :: Int
    , hrd_publication_minute :: Int
    , hrd_publication_month  :: Int
    , hrd_publication_second :: Int
    , hrd_publication_year   :: Int
    , hrd_source             :: String
    , hrd_title              :: String
    , hrd_url                :: String
    , hrd_uniqId             :: String
    , hrd_uniqIdBdd          :: String )

type Hyperdata = Record Hyperdata_

64
type NodeContext_
65 66 67 68 69 70
  = ( nc_id         :: Maybe Int
    , nc_node_id    :: Int
    , nc_context_id :: Int
    , nc_score      :: Maybe Number
    , nc_category   :: Maybe Int
    )
71
type NodeContext = Record NodeContext_
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88

type NodeContextQuery
  = { contexts   :: Args
      { context_id :: Var "context_id" Int
      , node_id    :: Var "node_id" Int }
      { nc_id         :: Unit
      , nc_node_id    :: Unit
      , nc_context_id :: Unit
      , nc_score      :: Unit
      , nc_category   :: Unit
      }
    }
nodeContextQuery :: NodeContextQuery
nodeContextQuery
  = { contexts:
      { context_id: Var :: _ "context_id" Int
      , node_id: Var :: _ "node_id" Int } =>>
89
      GGQL.getFieldsStandard (Proxy :: _ NodeContext)
90 91
    }

92 93
type ContextsForNgramsQuery
  = { contexts_for_ngrams :: Args
94 95
      { corpus_id    :: Var "corpus_id" Int
      , ngrams_terms :: Var "ngrams_terms" NgramsTerms }
96
      { c_id                        :: Unit
97 98
      , c_score                     :: Unit
      , c_date                      :: Unit
99 100 101 102 103
      , c_name                      :: Unit
      , c_typename                  :: Unit
      , c_hash_id                   :: Unit
      , c_user_id                   :: Unit
      , c_parent_id                 :: Unit
104
      , c_category                  :: Unit
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
      , c_hyperdata                 ::
           { hrd_abstract           :: Unit
           , hrd_authors            :: Unit
           , hrd_bdd                :: Unit
           , hrd_doi                :: Unit
           , hrd_institutes         :: Unit
           , hrd_language_iso2      :: Unit
           , hrd_page               :: Unit
           , hrd_publication_date   :: Unit
           , hrd_publication_day    :: Unit
           , hrd_publication_hour   :: Unit
           , hrd_publication_minute :: Unit
           , hrd_publication_month  :: Unit
           , hrd_publication_second :: Unit
           , hrd_publication_year   :: Unit
           , hrd_source             :: Unit
           , hrd_title              :: Unit
           , hrd_url                :: Unit
           , hrd_uniqId             :: Unit
           , hrd_uniqIdBdd          :: Unit }
      }
    }
contextsForNgramsQuery :: ContextsForNgramsQuery
contextsForNgramsQuery
  = { contexts_for_ngrams:
130 131
      { corpus_id:    Var :: _ "corpus_id" Int
      , ngrams_terms: Var :: _ "ngrams_terms" NgramsTerms } =>>
132 133 134
      GGQL.getFieldsStandard (Proxy :: _ Context)
    }

135
------------------------------------------------------------------------
136 137 138 139 140 141

type NodeContextCategoryM
  = { context_id :: NotNull Int
    , node_id    :: NotNull Int
    , category   :: Int
    }
142 143 144 145 146 147 148 149 150


newtype NgramsTerms = NgramsTerms (Array String)

instance EncodeJson NgramsTerms where
  encodeJson (NgramsTerms ngramsTerms) = encodeJson ngramsTerms
instance ArgGql String NgramsTerms
instance VarTypeName NgramsTerms where
  varTypeName _ = "[String!]!"