Commit b50e7bde authored by Alexandre Delanoë's avatar Alexandre Delanoë

[API] Connection to Isidore.

parent 7d6d74c4
...@@ -29,8 +29,8 @@ Portability : POSIX ...@@ -29,8 +29,8 @@ Portability : POSIX
module Gargantext.Database.Flow -- (flowDatabase, ngrams2list) module Gargantext.Database.Flow -- (flowDatabase, ngrams2list)
where where
import Prelude (String)
--import Debug.Trace (trace) import Debug.Trace (trace)
import Control.Lens ((^.), view, Lens', _Just) import Control.Lens ((^.), view, Lens', _Just)
import Control.Monad (mapM_) import Control.Monad (mapM_)
import Control.Monad.IO.Class (liftIO) import Control.Monad.IO.Class (liftIO)
...@@ -63,6 +63,7 @@ import Gargantext.Prelude ...@@ -63,6 +63,7 @@ import Gargantext.Prelude
import Gargantext.Text.Terms.Eleve (buildTries, toToken) import Gargantext.Text.Terms.Eleve (buildTries, toToken)
import Gargantext.Text.List (buildNgramsLists,StopSize(..)) import Gargantext.Text.List (buildNgramsLists,StopSize(..))
import Gargantext.Text.Parsers (parseFile, FileFormat) import Gargantext.Text.Parsers (parseFile, FileFormat)
import qualified Gargantext.Text.Parsers.IsidoreApi as Isidore
import Gargantext.Text.Terms (TermType(..), tt_lang, extractTerms, uniText) import Gargantext.Text.Terms (TermType(..), tt_lang, extractTerms, uniText)
import Gargantext.Text.Terms.Mono.Stem.En (stemIt) import Gargantext.Text.Terms.Mono.Stem.En (stemIt)
import Servant (ServantErr) import Servant (ServantErr)
...@@ -89,6 +90,30 @@ type FlowCorpus a = ( AddUniqId a ...@@ -89,6 +90,30 @@ type FlowCorpus a = ( AddUniqId a
------------------------------------------------------------------------ ------------------------------------------------------------------------
data ApiQuery = ApiIsidoreQuery Text | ApiIsidoreAuth Text
-- | APIs
-- TODO instances
getDataApi :: Lang
-> Maybe Limit
-> ApiQuery
-> IO [HyperdataDocument]
getDataApi lang limit (ApiIsidoreQuery q) = Isidore.get lang limit (Just q) Nothing
getDataApi lang limit (ApiIsidoreAuth q) = Isidore.get lang limit Nothing (Just q)
flowCorpusApi :: ( FlowCmdM env ServantErr m)
=> Username -> CorpusName
-> TermType Lang
-> Maybe Limit
-> ApiQuery
-> m CorpusId
flowCorpusApi u n tt l q = do
docs <- liftIO $ splitEvery 500 <$> getDataApi (_tt_lang tt) l q
flowCorpus u n tt docs
------------------------------------------------------------------------
flowAnnuaire :: FlowCmdM env ServantErr m flowAnnuaire :: FlowCmdM env ServantErr m
=> Username -> CorpusName -> (TermType Lang) -> FilePath -> m AnnuaireId => Username -> CorpusName -> (TermType Lang) -> FilePath -> m AnnuaireId
flowAnnuaire u n l filePath = do flowAnnuaire u n l filePath = do
...@@ -108,7 +133,6 @@ flowCorpusDebat u n l fp = do ...@@ -108,7 +133,6 @@ flowCorpusDebat u n l fp = do
) )
flowCorpus u n (Multi FR) (map (map toHyperdataDocument) docs) flowCorpus u n (Multi FR) (map (map toHyperdataDocument) docs)
flowCorpusFile :: FlowCmdM env ServantErr m flowCorpusFile :: FlowCmdM env ServantErr m
=> Username -> CorpusName => Username -> CorpusName
-> Limit -- Limit the number of docs (for dev purpose) -> Limit -- Limit the number of docs (for dev purpose)
...@@ -193,7 +217,7 @@ insertMasterDocs c lang hs = do ...@@ -193,7 +217,7 @@ insertMasterDocs c lang hs = do
fixLang (Unsupervised l n s m) = Unsupervised l n s m' fixLang (Unsupervised l n s m) = Unsupervised l n s m'
where where
m' = case m of m' = case m of
Nothing -> Just $ buildTries n (fmap toToken $ uniText $ Text.intercalate " " $ List.concat $ map hasText documentsWithId) Nothing -> trace ("buildTries here" :: String) $ Just $ buildTries n (fmap toToken $ uniText $ Text.intercalate " " $ List.concat $ map hasText documentsWithId)
m'' -> m'' m'' -> m''
fixLang l = l fixLang l = l
......
...@@ -9,7 +9,6 @@ Portability : POSIX ...@@ -9,7 +9,6 @@ Portability : POSIX
-} -}
{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
......
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