Commit 902126ad authored by Alexandre Delanoë's avatar Alexandre Delanoë

[FIX] V3 Ngrams List post/update with CSV format

parent ba645886
...@@ -22,14 +22,14 @@ import Data.HashMap.Strict (HashMap) ...@@ -22,14 +22,14 @@ import Data.HashMap.Strict (HashMap)
import Data.Map (Map, toList) import Data.Map (Map, toList)
import Data.Maybe (catMaybes) import Data.Maybe (catMaybes)
import Data.Set (Set) import Data.Set (Set)
import Data.Text (Text, concat, pack) import Data.Text (Text, concat, pack, splitOn)
import Data.Vector (Vector) import Data.Vector (Vector)
import Gargantext.API.Admin.Orchestrator.Types import Gargantext.API.Admin.Orchestrator.Types
import Gargantext.API.Ngrams (setListNgrams) import Gargantext.API.Ngrams (setListNgrams)
import Gargantext.API.Ngrams.List.Types
import Gargantext.API.Ngrams.Prelude (getNgramsList)
import Gargantext.API.Ngrams.Tools (getTermsWith) import Gargantext.API.Ngrams.Tools (getTermsWith)
import Gargantext.API.Ngrams.Types import Gargantext.API.Ngrams.Types
import Gargantext.API.Ngrams.Prelude (getNgramsList)
import Gargantext.API.Ngrams.List.Types
import Gargantext.API.Prelude (GargServer) import Gargantext.API.Prelude (GargServer)
import Gargantext.Core.NodeStory import Gargantext.Core.NodeStory
import Gargantext.Core.Text.Terms (ExtractedNgrams(..)) import Gargantext.Core.Text.Terms (ExtractedNgrams(..))
...@@ -41,8 +41,8 @@ import Gargantext.Database.Action.Metrics.NgramsByContext (getOccByNgramsOnlyFas ...@@ -41,8 +41,8 @@ import Gargantext.Database.Action.Metrics.NgramsByContext (getOccByNgramsOnlyFas
import Gargantext.Database.Admin.Types.Hyperdata.Document import Gargantext.Database.Admin.Types.Hyperdata.Document
import Gargantext.Database.Admin.Types.Node import Gargantext.Database.Admin.Types.Node
import Gargantext.Database.Query.Table.NodeContext (selectDocNodes) import Gargantext.Database.Query.Table.NodeContext (selectDocNodes)
import Gargantext.Database.Schema.Ngrams
import Gargantext.Database.Schema.Context import Gargantext.Database.Schema.Context
import Gargantext.Database.Schema.Ngrams
import Gargantext.Database.Types (Indexed(..)) import Gargantext.Database.Types (Indexed(..))
import Gargantext.Prelude import Gargantext.Prelude
import Network.HTTP.Media ((//), (/:)) import Network.HTTP.Media ((//), (/:))
...@@ -58,17 +58,6 @@ import qualified Data.Vector as Vec ...@@ -58,17 +58,6 @@ import qualified Data.Vector as Vec
import qualified Prelude as Prelude import qualified Prelude as Prelude
import qualified Protolude as P import qualified Protolude as P
------------------------------------------------------------------------ ------------------------------------------------------------------------
-- | TODO refactor
{-
type API = Get '[JSON, HTML] (Headers '[Header "Content-Disposition" Text] NgramsList)
-- :<|> ReqBody '[JSON] NgramsList :> Post '[JSON] Bool
:<|> PostAPI
:<|> CSVPostAPI
api :: ListId -> GargServer API
api l = get l :<|> postAsync l :<|> csvPostAsync l
-}
----------------------
type GETAPI = Summary "Get List" type GETAPI = Summary "Get List"
:> "lists" :> "lists"
:> Capture "listId" ListId :> Capture "listId" ListId
...@@ -122,11 +111,11 @@ get lId = do ...@@ -122,11 +111,11 @@ get lId = do
------------------------------------------------------------------------ ------------------------------------------------------------------------
-- TODO : purge list -- TODO : purge list
-- TODO talk -- TODO talk
post :: FlowCmdM env err m setList :: FlowCmdM env err m
=> ListId => ListId
-> NgramsList -> NgramsList
-> m Bool -> m Bool
post l m = do setList l m = do
-- TODO check with Version for optim -- TODO check with Version for optim
printDebug "New list as file" l printDebug "New list as file" l
_ <- mapM (\(nt, Versioned _v ns) -> setListNgrams l nt ns) $ toList m _ <- mapM (\(nt, Versioned _v ns) -> setListNgrams l nt ns) $ toList m
...@@ -227,7 +216,7 @@ postAsync' l (WithFile _ m _) logStatus = do ...@@ -227,7 +216,7 @@ postAsync' l (WithFile _ m _) logStatus = do
, _scst_events = Just [] , _scst_events = Just []
} }
printDebug "New list as file" l printDebug "New list as file" l
_ <- post l m _ <- setList l m
-- printDebug "Done" r -- printDebug "Done" r
pure JobLog { _scst_succeeded = Just 1 pure JobLog { _scst_succeeded = Just 1
...@@ -236,7 +225,6 @@ postAsync' l (WithFile _ m _) logStatus = do ...@@ -236,7 +225,6 @@ postAsync' l (WithFile _ m _) logStatus = do
, _scst_events = Just [] , _scst_events = Just []
} }
------------------------------------------------------------------------ ------------------------------------------------------------------------
type CSVPostAPI = Summary "Update List (legacy v3 CSV)" type CSVPostAPI = Summary "Update List (legacy v3 CSV)"
:> "csv" :> "csv"
:> "add" :> "add"
...@@ -257,12 +245,22 @@ readCsvText t = case eDec of ...@@ -257,12 +245,22 @@ readCsvText t = case eDec of
parseCsvData :: [(Text, Text, Text)] -> Map NgramsTerm NgramsRepoElement parseCsvData :: [(Text, Text, Text)] -> Map NgramsTerm NgramsRepoElement
parseCsvData lst = Map.fromList $ conv <$> lst parseCsvData lst = Map.fromList $ conv <$> lst
where where
conv (_status, label, _forms) = conv (status, label, forms) =
(NgramsTerm label, NgramsRepoElement { _nre_size = 1 (NgramsTerm label, NgramsRepoElement { _nre_size = 1
, _nre_list = CandidateTerm , _nre_list = case status == "map" of
True -> MapTerm
False -> case status == "main" of
True -> CandidateTerm
False -> StopTerm
, _nre_root = Nothing , _nre_root = Nothing
, _nre_parent = Nothing , _nre_parent = Nothing
, _nre_children = MSet Map.empty }) , _nre_children = MSet
$ Map.fromList
$ map (\form -> (NgramsTerm form, ()))
$ filter (/= "")
$ splitOn "|&|" forms
}
)
csvPost :: FlowCmdM env err m csvPost :: FlowCmdM env err m
=> ListId => ListId
...@@ -278,10 +276,8 @@ csvPost l m = do ...@@ -278,10 +276,8 @@ csvPost l m = do
printDebug "[csvPost] p" p printDebug "[csvPost] p" p
_ <- setListNgrams l NgramsTerms p _ <- setListNgrams l NgramsTerms p
pure True pure True
------------------------------------------------------------------------
------------------------------------------------------------------------
csvPostAsync :: GargServer CSVAPI csvPostAsync :: GargServer CSVAPI
csvPostAsync lId = csvPostAsync lId =
serveJobsAPI $ serveJobsAPI $
......
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