Commit 6651d0d6 authored by Alexandre Delanoë's avatar Alexandre Delanoë

[API][NGRAMS] to discuss

parent 30aae72b
...@@ -97,10 +97,6 @@ data NgramsTable = NgramsTable { _ngramsTable :: [Tree NgramsElement] } ...@@ -97,10 +97,6 @@ data NgramsTable = NgramsTable { _ngramsTable :: [Tree NgramsElement] }
$(deriveJSON (unPrefix "_") ''NgramsTable) $(deriveJSON (unPrefix "_") ''NgramsTable)
-- TODO
instance FromJSON (Tree NgramsElement)
instance ToJSON (Tree NgramsElement)
------------------------------------------------------------------------ ------------------------------------------------------------------------
-- On the Client side: -- On the Client side:
--data Action = InGroup NgramsId NgramsId --data Action = InGroup NgramsId NgramsId
...@@ -145,7 +141,6 @@ instance ToSchema NgramsIdPatchs ...@@ -145,7 +141,6 @@ instance ToSchema NgramsIdPatchs
instance Arbitrary NgramsIdPatchs where instance Arbitrary NgramsIdPatchs where
arbitrary = NgramsIdPatchs <$> arbitrary arbitrary = NgramsIdPatchs <$> arbitrary
------------------------------------------------------------------------ ------------------------------------------------------------------------
------------------------------------------------------------------------ ------------------------------------------------------------------------
type Version = Int type Version = Int
...@@ -178,11 +173,16 @@ ngramsIdPatch = fromList $ catMaybes $ reverse [ replace (1::NgramsId) (Just $ n ...@@ -178,11 +173,16 @@ ngramsIdPatch = fromList $ catMaybes $ reverse [ replace (1::NgramsId) (Just $ n
------------------------------------------------------------------------ ------------------------------------------------------------------------
------------------------------------------------------------------------ ------------------------------------------------------------------------
type CorpusId = Int type CorpusId = Int
type TableNgramsApi = Summary " Table Ngrams API" type TableNgramsApi = Summary " Table Ngrams API Change"
:> QueryParam "list" ListId :> QueryParam "list" ListId
:> ReqBody '[JSON] NgramsIdPatchs :> ReqBody '[JSON] NgramsIdPatchs
:> Put '[JSON] NgramsIdPatchsBack :> Put '[JSON] NgramsIdPatchsBack
type TableNgramsApiGet = Summary " Table Ngrams API Get"
:> QueryParam "ngramsType" TabType
:> QueryParam "list" ListId
:> Get '[JSON] NgramsIdPatchsBack
type NgramsIdPatchsFeed = NgramsIdPatchs type NgramsIdPatchsFeed = NgramsIdPatchs
type NgramsIdPatchsBack = NgramsIdPatchs type NgramsIdPatchsBack = NgramsIdPatchs
...@@ -219,3 +219,5 @@ tableNgramsPatch conn corpusId maybeList patchs = do ...@@ -219,3 +219,5 @@ tableNgramsPatch conn corpusId maybeList patchs = do
_ <- updateNodeNgrams conn (toLists listId patchs) _ <- updateNodeNgrams conn (toLists listId patchs)
pure (NgramsIdPatchs []) pure (NgramsIdPatchs [])
getTableNgramsPatch :: Connection -> CorpusId -> Maybe TabType -> Maybe ListId -> IO NgramsTable
getTableNgramsPatch = undefined
...@@ -48,7 +48,7 @@ import Database.PostgreSQL.Simple (Connection) ...@@ -48,7 +48,7 @@ import Database.PostgreSQL.Simple (Connection)
import GHC.Generics (Generic) import GHC.Generics (Generic)
import Servant import Servant
import Gargantext.API.Ngrams (TabType(..), TableNgramsApi, tableNgramsPatch, NgramsIdPatchsFeed, NgramsIdPatchsBack) import Gargantext.API.Ngrams (TabType(..), TableNgramsApi, TableNgramsApiGet,tableNgramsPatch, getTableNgramsPatch, NgramsIdPatchsFeed, NgramsIdPatchsBack)
import Gargantext.Prelude import Gargantext.Prelude
import Gargantext.Database.Types.Node import Gargantext.Database.Types.Node
import Gargantext.Database.Node ( runCmd import Gargantext.Database.Node ( runCmd
...@@ -110,6 +110,7 @@ type NodeAPI a = Get '[JSON] (Node a) ...@@ -110,6 +110,7 @@ type NodeAPI a = Get '[JSON] (Node a)
-- TODO gather it -- TODO gather it
:<|> "table" :> TableApi :<|> "table" :> TableApi
:<|> "list" :> TableNgramsApi :<|> "list" :> TableNgramsApi
:<|> "listGet" :> TableNgramsApiGet
:<|> "chart" :> ChartApi :<|> "chart" :> ChartApi
:<|> "favorites" :> FavApi :<|> "favorites" :> FavApi
...@@ -142,6 +143,7 @@ nodeAPI conn p id ...@@ -142,6 +143,7 @@ nodeAPI conn p id
-- TODO gather it -- TODO gather it
:<|> getTable conn id :<|> getTable conn id
:<|> tableNgramsPatch' conn id :<|> tableNgramsPatch' conn id
:<|> getTableNgramsPatch' conn id
:<|> getChart conn id :<|> getChart conn id
:<|> favApi conn id :<|> favApi conn id
...@@ -233,7 +235,6 @@ type ChartApi = Summary " Chart API" ...@@ -233,7 +235,6 @@ type ChartApi = Summary " Chart API"
-- To launch a query and update the corpus -- To launch a query and update the corpus
-- :<|> "query" :> Capture "string" Text :> Get '[JSON] Text -- :<|> "query" :> Capture "string" Text :> Get '[JSON] Text
------------------------------------------------------------------------ ------------------------------------------------------------------------
type GraphAPI = Get '[JSON] Graph type GraphAPI = Get '[JSON] Graph
graphAPI :: Connection -> NodeId -> Server GraphAPI graphAPI :: Connection -> NodeId -> Server GraphAPI
...@@ -288,6 +289,9 @@ getNodesWith' conn id p nodeType offset limit = liftIO (getNodesWith conn id p ...@@ -288,6 +289,9 @@ getNodesWith' conn id p nodeType offset limit = liftIO (getNodesWith conn id p
tableNgramsPatch' :: Connection -> CorpusId -> Maybe ListId -> NgramsIdPatchsFeed -> Handler NgramsIdPatchsBack tableNgramsPatch' :: Connection -> CorpusId -> Maybe ListId -> NgramsIdPatchsFeed -> Handler NgramsIdPatchsBack
tableNgramsPatch' c cId mL ns = liftIO $ tableNgramsPatch c cId mL ns tableNgramsPatch' c cId mL ns = liftIO $ tableNgramsPatch c cId mL ns
getTableNgramsPatch' :: Connection -> CorpusId -> Maybe TabType -> Maybe ListId -> Handler NgramsIdPatchsBack
getTableNgramsPatch' c cId nType mL = liftIO $ getTableNgramsPatch c cId nType mL
query :: Text -> Handler Text query :: Text -> Handler Text
query s = pure s query s = pure s
......
...@@ -135,7 +135,7 @@ type Offset = Int ...@@ -135,7 +135,7 @@ type Offset = Int
data Tree a = TreeN a [Tree a] data Tree a = TreeN a [Tree a]
deriving (Show, Read, Eq, Generic, Ord) deriving (Show, Read, Eq, Generic, Ord)
instance ToJSON (Tree NodeTree) where instance ToJSON a => ToJSON (Tree a) where
toJSON (TreeN node nodes) = toJSON (TreeN node nodes) =
object ["node" A..= toJSON node, "children" A..= toJSON nodes] object ["node" A..= toJSON node, "children" A..= toJSON nodes]
......
...@@ -32,7 +32,7 @@ import Data.Tuple.Extra (both, second) ...@@ -32,7 +32,7 @@ import Data.Tuple.Extra (both, second)
import qualified Data.Map as DM import qualified Data.Map as DM
import Gargantext.Core.Types (NodePoly(..), ListType(..), listId) import Gargantext.Core.Types (NodePoly(..), ListType(..), listId)
import Gargantext.Database.Bashql (runCmd', del) import Gargantext.Database.Bashql (runCmd')--, del)
import Gargantext.Database.Ngrams (insertNgrams, Ngrams(..), NgramsT(..), NgramsIndexed(..), indexNgramsT, ngramsTypeId, NgramsType(..), text2ngrams) import Gargantext.Database.Ngrams (insertNgrams, Ngrams(..), NgramsT(..), NgramsIndexed(..), indexNgramsT, ngramsTypeId, NgramsType(..), text2ngrams)
import Gargantext.Database.Node (getRoot, mkRoot, mkCorpus, Cmd(..), mkList) import Gargantext.Database.Node (getRoot, mkRoot, mkCorpus, Cmd(..), mkList)
import Gargantext.Database.Node.Document.Add (add) import Gargantext.Database.Node.Document.Add (add)
...@@ -68,8 +68,8 @@ flow fp cName = do ...@@ -68,8 +68,8 @@ flow fp cName = do
_ <- runCmd' $ insertToNodeNgrams indexedNgrams _ <- runCmd' $ insertToNodeNgrams indexedNgrams
-- List Flow -- List Flow
listId <- runCmd' $ listFlow masterUserId corpusId indexedNgrams listId2 <- runCmd' $ listFlow masterUserId corpusId indexedNgrams
printDebug "list id:" listId printDebug "list id:" listId2
printDebug "Docs IDs : " (length idsRepeat) printDebug "Docs IDs : " (length idsRepeat)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment