[hyperdata] some Arxiv/Pubmed refactoring

parent 3fe6eba0
Pipeline #5694 passed with stages
in 106 minutes and 3 seconds
...@@ -19,13 +19,13 @@ module Gargantext.Core.Text.Corpus.API.Arxiv ...@@ -19,13 +19,13 @@ module Gargantext.Core.Text.Corpus.API.Arxiv
) where ) where
import Arxiv qualified as Arxiv import Arxiv qualified as Arxiv
import Conduit import Conduit ( ConduitT, (.|), mapC, takeC )
import Data.Text (unpack) import Data.Text (unpack)
import Data.Text qualified as Text import Data.Text qualified as Text
import Gargantext.Core (Lang(..)) import Gargantext.Core (Lang(..))
import Gargantext.Core.Text.Corpus.Query as Corpus import Gargantext.Core.Text.Corpus.Query as Corpus
import Gargantext.Core.Types (Term(..)) import Gargantext.Core.Types (Term(..))
import Gargantext.Database.Admin.Types.Hyperdata (HyperdataDocument(..)) import Gargantext.Database.Admin.Types.Hyperdata.Document ( HyperdataDocument(..) )
import Gargantext.Prelude hiding (get) import Gargantext.Prelude hiding (get)
import Network.Api.Arxiv qualified as Ax import Network.Api.Arxiv qualified as Ax
...@@ -46,7 +46,7 @@ convertQuery q = mkQuery (interpretQuery q transformAST) ...@@ -46,7 +46,7 @@ convertQuery q = mkQuery (interpretQuery q transformAST)
transformAST ast = case ast of transformAST ast = case ast of
BAnd sub (BConst (Negative term)) BAnd sub (BConst (Negative term))
-- The second term become positive, so that it can be translated. -- The second term become positive, so that it can be translated.
-> Ax.AndNot <$> (transformAST sub) <*> transformAST (BConst (Positive term)) -> Ax.AndNot <$> transformAST sub <*> transformAST (BConst (Positive term))
BAnd term1 (BNot term2) BAnd term1 (BNot term2)
-> Ax.AndNot <$> transformAST term1 <*> transformAST term2 -> Ax.AndNot <$> transformAST term1 <*> transformAST term2
BAnd sub1 sub2 BAnd sub1 sub2
...@@ -88,7 +88,7 @@ toDoc l (Arxiv.Result { abstract ...@@ -88,7 +88,7 @@ toDoc l (Arxiv.Result { abstract
, authors = aus , authors = aus
--, categories --, categories
, doi , doi
, id -- , id
, journal , journal
--, primaryCategory --, primaryCategory
, publication_date , publication_date
......
...@@ -20,13 +20,13 @@ module Gargantext.Core.Text.Corpus.API.Pubmed ...@@ -20,13 +20,13 @@ module Gargantext.Core.Text.Corpus.API.Pubmed
) )
where where
import Conduit import Conduit ( ConduitT, (.|), mapC, takeC )
import Data.Text qualified as Text import Data.Text qualified as Text
import Data.Text.Encoding qualified as TE import Data.Text.Encoding qualified as TE
import Gargantext.Core (Lang(..)) import Gargantext.Core (Lang(..))
import Gargantext.Core.Text.Corpus.Query as Corpus import Gargantext.Core.Text.Corpus.Query as Corpus
import Gargantext.Core.Types (Term(..)) import Gargantext.Core.Types (Term(..))
import Gargantext.Database.Admin.Types.Hyperdata (HyperdataDocument(..)) import Gargantext.Database.Admin.Types.Hyperdata.Document ( HyperdataDocument(..) )
import Gargantext.Prelude hiding (get) import Gargantext.Prelude hiding (get)
import Network.HTTP.Types.URI (EscapeItem(..), renderQueryPartialEscape) import Network.HTTP.Types.URI (EscapeItem(..), renderQueryPartialEscape)
import PUBMED qualified as PubMed import PUBMED qualified as PubMed
...@@ -64,7 +64,7 @@ convertQuery q = ESearch (interpretQuery q transformAST) ...@@ -64,7 +64,7 @@ convertQuery q = ESearch (interpretQuery q transformAST)
transformAST ast = case ast of transformAST ast = case ast of
BAnd sub (BConst (Negative term)) BAnd sub (BConst (Negative term))
-- The second term become positive, so that it can be translated. -- The second term become positive, so that it can be translated.
-> (transformAST sub) <> [QN "+AND+NOT+"] <> transformAST (BConst (Positive term)) -> transformAST sub <> [QN "+AND+NOT+"] <> transformAST (BConst (Positive term))
BAnd term1 (BNot term2) BAnd term1 (BNot term2)
-> transformAST term1 <> [QN "+AND+NOT+"] <> transformAST term2 -> transformAST term1 <> [QN "+AND+NOT+"] <> transformAST term2
BAnd sub1 sub2 BAnd sub1 sub2
...@@ -108,8 +108,7 @@ get apiKey q l = do ...@@ -108,8 +108,7 @@ get apiKey q l = do
-- <$> PubMed.getMetadataWithC q l -- <$> PubMed.getMetadataWithC q l
toDoc :: Lang -> PubMedDoc.PubMed -> HyperdataDocument toDoc :: Lang -> PubMedDoc.PubMed -> HyperdataDocument
toDoc l (PubMedDoc.PubMed { pubmed_id toDoc l (PubMedDoc.PubMed { pubmed_article = PubMedDoc.PubMedArticle t j as aus
, pubmed_article = PubMedDoc.PubMedArticle t j as aus
, pubmed_date = PubMedDoc.PubMedDate a y m d } , pubmed_date = PubMedDoc.PubMedDate a y m d }
) = HyperdataDocument { _hd_bdd = Just "PubMed" ) = HyperdataDocument { _hd_bdd = Just "PubMed"
, _hd_doi = Nothing , _hd_doi = Nothing
...@@ -133,16 +132,14 @@ toDoc l (PubMedDoc.PubMed { pubmed_id ...@@ -133,16 +132,14 @@ toDoc l (PubMedDoc.PubMed { pubmed_id
where where
authors :: [PubMedDoc.Author] -> Maybe Text authors :: [PubMedDoc.Author] -> Maybe Text
authors [] = Nothing authors [] = Nothing
authors au = Just $ (Text.intercalate ", ") authors au = Just $ Text.intercalate ", "
$ catMaybes $ mapMaybe (\n -> PubMedDoc.foreName n <> Just " " <> PubMedDoc.lastName n) au
$ map (\n -> PubMedDoc.foreName n <> Just " " <> PubMedDoc.lastName n) au
institutes :: [PubMedDoc.Author] -> Maybe Text institutes :: [PubMedDoc.Author] -> Maybe Text
institutes [] = Nothing institutes [] = Nothing
institutes au = Just $ (Text.intercalate ", ") institutes au = Just $ Text.intercalate ", "
$ (map (Text.replace ", " " - ")) $ map (Text.replace ", " " - ")
$ catMaybes $ mapMaybe PubMedDoc.affiliation au
$ map PubMedDoc.affiliation au
abstract :: [Text] -> Maybe Text abstract :: [Text] -> Maybe Text
......
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