]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Text/Parsers/Isidore.hs
Isidore: make the sparql request using Wreq because httpS is required
[gargantext.git] / src / Gargantext / Text / Parsers / Isidore.hs
1 {-# LANGUAGE NoImplicitPrelude #-}
2 {-# LANGUAGE ScopedTypeVariables #-}
3 {-# LANGUAGE OverloadedStrings #-}
4
5 module Gargantext.Text.Parsers.Isidore where
6
7 import Gargantext.Prelude
8 import Database.HSparql.Connection
9 import Database.HSparql.QueryGenerator
10
11 -- import Data.RDF hiding (triple)
12 import Data.Text hiding (groupBy)
13
14 import Control.Lens hiding (contains)
15 import Data.ByteString.Lazy (ByteString)
16 import Prelude (String)
17 import Network.Wreq
18
19 route = "https://isidore.science/sparql/"
20
21 selectQueryRaw' :: String -> String -> IO (Response ByteString)
22 selectQueryRaw' uri q = getWith opts uri
23 where
24 opts = defaults & header "Accept" .~ ["application/sparql-results+xml"]
25 & header "User-Agent" .~ ["gargantext-hsparql-client"]
26 & param "query" .~ [Data.Text.pack q]
27
28 --selectExample :: IO (Maybe [Text])
29 isidore q = do
30 let s = createSelectQuery $ simpleSelect q
31 putStrLn s
32 r <- selectQueryRaw' route s
33 putStrLn $ show $ r ^. responseStatus
34 pure $ r ^. responseBody
35 -- res <- selectQuery route $ simpleSelect q
36 -- pure res
37
38 simpleSelect :: Text -> Query SelectQuery
39 simpleSelect q = do
40 isidore <- prefix "isidore" (iriRef "http://www.rechercheisidore.fr/class")
41 rdf <- prefix "rdf" (iriRef "http://www.w3.org/1999/02/22-rdf-syntax-ns#")
42 dcterms <- prefix "dcterms" (iriRef "http://purl.org/dc/terms")
43 dc <- prefix "dc" (iriRef "http://purl.org/dc")
44
45 doc <- var
46 title <- var
47 date <- var
48 abstract <- var
49 source <- var
50
51 triple doc (rdf .:. "type") (isidore .:. "BibliographicalResource")
52 triple doc (dcterms .:. "title") title
53 triple doc (dcterms .:. "date") date
54 triple doc (dcterms .:. "source") source
55 triple doc (dc .:. "description") abstract
56
57 filterExpr $ (.||.) (contains title q) (contains abstract q)
58 groupBy title
59 groupBy source
60
61 selectVars [title, date, source, abstract]