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)
20 route = "https://isidore.science/sparql/"
22 selectQueryRaw' :: String -> String -> IO (Response ByteString)
23 selectQueryRaw' uri q = getWith opts uri
25 opts = defaults & header "Accept" .~ ["application/sparql-results+xml"]
26 & header "User-Agent" .~ ["gargantext-hsparql-client"]
27 & param "query" .~ [Data.Text.pack q]
29 isidoreGet :: Text -> IO ByteString
31 let s = createSelectQuery $ simpleSelect q
33 r <- selectQueryRaw' route s
34 putStrLn $ show $ r ^. responseStatus
35 pure $ r ^. responseBody
36 -- res <- selectQuery route $ simpleSelect q
39 simpleSelect :: Text -> Query SelectQuery
41 -- See Predefined Namespace Prefixes:
42 -- https://isidore.science/sparql?nsdecl
43 isidore <- prefix "isidore" (iriRef "http://www.rechercheisidore.fr/class/")
44 rdf <- prefix "rdf" (iriRef "http://www.w3.org/1999/02/22-rdf-syntax-ns#")
45 dcterms <- prefix "dcterms" (iriRef "http://purl.org/dc/terms/")
46 dc <- prefix "dc" (iriRef "http://purl.org/dc/elements/1.1/")
47 ore <- prefix "ore" (iriRef "http://www.openarchives.org/ore/terms/")
48 bif <- prefix "bif" (iriRef "bif:")
62 triple_ link (rdf .:. "type") (isidore .:. "BibliographicalResource")
63 triple_ link (dcterms .:. "title") title
64 triple_ link (dcterms .:. "date") date
65 triple_ link (dcterms .:. "creator") authors
66 triple_ link (dcterms .:. "language") lang
67 triple_ link (dcterms .:. "source") source
69 triple_ link (ore .:. "isAggregatedBy") agg
70 --triple_ agg (dcterms .:. "title") title
73 optional $ triple_ link (dcterms .:. "publisher") publisher
74 optional $ triple_ link (dc .:. "description") abstract
76 --filterExpr $ (.||.) (contains title q) (contains abstract q)
78 --triple_ indexT (bif .:. "contains") title
80 --filterExpr_ (contains indexT q) -- (contains abstract q)
84 selectVars [link, date, authors, source, title, lang, publisher, abstract]