1 {-# LANGUAGE NoImplicitPrelude #-}
2 {-# LANGUAGE ScopedTypeVariables #-}
3 {-# LANGUAGE OverloadedStrings #-}
5 module Gargantext.Text.Parsers.Isidore where
7 import Gargantext.Prelude
8 import Database.HSparql.Connection
9 import Database.HSparql.QueryGenerator
11 -- import Data.RDF hiding (triple)
12 import Data.Text hiding (groupBy)
14 import Control.Lens hiding (contains)
15 import Data.ByteString.Lazy (ByteString)
16 import Prelude (String)
19 route = "https://isidore.science/sparql/"
21 selectQueryRaw' :: String -> String -> IO (Response ByteString)
22 selectQueryRaw' uri q = getWith opts uri
24 opts = defaults & header "Accept" .~ ["application/sparql-results+xml"]
25 & header "User-Agent" .~ ["gargantext-hsparql-client"]
26 & param "query" .~ [Data.Text.pack q]
28 --selectExample :: IO (Maybe [Text])
30 let s = createSelectQuery $ simpleSelect q
32 r <- selectQueryRaw' route s
33 putStrLn $ show $ r ^. responseStatus
34 pure $ r ^. responseBody
35 -- res <- selectQuery route $ simpleSelect q
38 simpleSelect :: Text -> Query SelectQuery
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")
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
57 filterExpr $ (.||.) (contains title q) (contains abstract q)
61 selectVars [title, date, source, abstract]