Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
haskell-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Christian Merten
haskell-gargantext
Commits
9173f8b3
Commit
9173f8b3
authored
May 29, 2023
by
Alfredo Di Napoli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement conversion from Query to Arxiv
parent
b45714a8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
5 deletions
+42
-5
Arxiv.hs
src/Gargantext/Core/Text/Corpus/API/Arxiv.hs
+34
-2
Query.hs
src/Gargantext/Core/Text/Corpus/Query.hs
+8
-3
No files found.
src/Gargantext/Core/Text/Corpus/API/Arxiv.hs
View file @
9173f8b3
...
...
@@ -17,13 +17,14 @@ module Gargantext.Core.Text.Corpus.API.Arxiv
import
Conduit
import
Data.Maybe
import
Data.Text
(
Text
)
import
Data.Text
(
Text
,
unpack
)
import
qualified
Data.Text
as
Text
import
Gargantext.Prelude
import
Gargantext.Core
(
Lang
(
..
))
import
Gargantext.Database.Admin.Types.Hyperdata
(
HyperdataDocument
(
..
))
import
Gargantext.Core.Text.Corpus.Query
as
Corpus
import
Gargantext.Core.Types
(
Term
(
..
))
import
qualified
Arxiv
as
Arxiv
import
qualified
Network.Api.Arxiv
as
Ax
...
...
@@ -31,7 +32,38 @@ import qualified Network.Api.Arxiv as Ax
-- | Converts a Gargantext's generic boolean query into an Arxiv Query.
convertQuery
::
Corpus
.
Query
->
Ax
.
Query
convertQuery
_q
=
undefined
convertQuery
q
=
mkQuery
(
interpretQuery
q
transformAST
)
where
transformAST
::
BoolExpr
Term
->
Maybe
Ax
.
Expression
transformAST
ast
=
case
ast
of
BAnd
sub
(
BConst
(
Negative
term
))
-- The second term become positive, so that it can be translated.
->
Ax
.
AndNot
<$>
(
transformAST
sub
)
<*>
transformAST
(
BConst
(
Positive
term
))
BAnd
term1
(
BNot
term2
)
->
Ax
.
AndNot
<$>
transformAST
term1
<*>
transformAST
term2
BAnd
sub1
sub2
->
Ax
.
And
<$>
transformAST
sub1
<*>
transformAST
sub2
BOr
sub1
sub2
->
Ax
.
Or
<$>
transformAST
sub1
<*>
transformAST
sub2
BNot
(
BConst
(
Negative
term
))
->
transformAST
(
BConst
(
Positive
term
))
-- double negation
BNot
_
->
Nothing
BTrue
->
Nothing
BFalse
->
Nothing
BConst
(
Positive
(
Term
term
))
->
Just
$
Ax
.
Exp
$
Ax
.
Abs
[
unpack
term
]
-- Do not handle negative terms, because we don't have a way to represent them in Arxiv.
BConst
(
Negative
_
)
->
Nothing
mkQuery
::
Maybe
Ax
.
Expression
->
Ax
.
Query
mkQuery
mb_exp
=
Ax
.
Query
{
Ax
.
qExp
=
mb_exp
,
Ax
.
qIds
=
[]
,
Ax
.
qStart
=
0
,
Ax
.
qItems
=
Arxiv
.
batchSize
}
-- | TODO put default pubmed query in gargantext.ini
-- by default: 10K docs
...
...
src/Gargantext/Core/Text/Corpus/Query.hs
View file @
9173f8b3
...
...
@@ -7,7 +7,9 @@ module Gargantext.Core.Text.Corpus.Query (
,
getQuery
,
parseQuery
,
renderQuery
,
interpretQuery
,
ExternalAPIs
(
..
)
,
module
BoolExpr
-- * Useful for testing
,
unsafeMkQuery
...
...
@@ -20,9 +22,9 @@ import Gargantext.Core.Types
import
Prelude
import
Text.ParserCombinators.Parsec
import
qualified
Data.Aeson
as
Aeson
import
qualified
Data.BoolExpr
as
BoolExpr
import
qualified
Data.BoolExpr.Parser
as
BoolExpr
import
qualified
Data.BoolExpr.Printer
as
BoolExpr
import
Data.BoolExpr
as
BoolExpr
import
Data.BoolExpr.Parser
as
BoolExpr
import
Data.BoolExpr.Printer
as
BoolExpr
import
qualified
Data.Swagger
as
Swagger
import
qualified
Data.Text
as
T
import
qualified
Servant.API
as
Servant
...
...
@@ -48,6 +50,9 @@ newtype Limit = Limit { getLimit :: Int }
newtype
Query
=
Query
{
getQuery
::
(
BoolExpr
.
CNF
Term
)
}
deriving
Show
interpretQuery
::
Query
->
(
BoolExpr
.
BoolExpr
Term
->
ast
)
->
ast
interpretQuery
(
Query
q
)
transform
=
transform
(
BoolExpr
.
fromCNF
q
)
unsafeMkQuery
::
BoolExpr
.
BoolExpr
Term
->
Query
unsafeMkQuery
=
Query
.
BoolExpr
.
boolTreeToCNF
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment