Context.purs 4.87 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
  , contextNgramsQuery
12
  , NgramsTerms(..)
13 14
  ) where

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


25 26 27 28
type Context_
  = ( c_id        :: Int
    , c_name      :: String
    , c_typename  :: Int
29 30
    , c_date      :: String
    , c_hash_id   :: Maybe String
31
    , c_user_id   :: Int
32 33 34
    , c_parent_id :: Maybe Int
    , c_category  :: Maybe Int
    , c_score     :: Maybe Int  -- TODO: Maybe Double
35 36 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
    , 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_

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

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 } =>>
87
      GGQL.getFieldsStandard (Proxy :: _ NodeContext)
88 89
    }

90 91
type ContextsForNgramsQuery
  = { contexts_for_ngrams :: Args
92 93
      { corpus_id    :: Var "corpus_id" Int
      , ngrams_terms :: Var "ngrams_terms" NgramsTerms }
94
      { c_id                        :: Unit
95 96
      , c_score                     :: Unit
      , c_date                      :: Unit
97 98 99 100 101
      , c_name                      :: Unit
      , c_typename                  :: Unit
      , c_hash_id                   :: Unit
      , c_user_id                   :: Unit
      , c_parent_id                 :: Unit
102
      , c_category                  :: Unit
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
      , 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:
128 129
      { corpus_id:    Var :: _ "corpus_id" Int
      , ngrams_terms: Var :: _ "ngrams_terms" NgramsTerms } =>>
130 131 132
      GGQL.getFieldsStandard (Proxy :: _ Context)
    }

133 134 135 136 137 138 139 140 141 142 143 144
type ContextNgramsQuery
  = { context_ngrams :: Args
    { context_id :: Var "context_id" Int
    , list_id    :: Var "list_id" Int }
    Unit }

contextNgramsQuery :: ContextNgramsQuery
contextNgramsQuery
  = { context_ngrams:
      { context_id: Var :: _ "context_id" Int
      , list_id:    Var :: _ "list_id" Int } =>> unit }

145
------------------------------------------------------------------------
146 147 148 149 150 151

type NodeContextCategoryM
  = { context_id :: NotNull Int
    , node_id    :: NotNull Int
    , category   :: Int
    }
152 153 154 155 156 157 158 159 160


newtype NgramsTerms = NgramsTerms (Array String)

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