]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Text/Parsers/Isidore.hs
[TEXT][Parsers][Isidore] working query.
[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 :: EndPoint
20 route = "https://isidore.science/sparql/"
21
22 selectQueryRaw' :: String -> String -> IO (Response ByteString)
23 selectQueryRaw' uri q = getWith opts uri
24 where
25 opts = defaults & header "Accept" .~ ["application/sparql-results+xml"]
26 & header "User-Agent" .~ ["gargantext-hsparql-client"]
27 & param "query" .~ [Data.Text.pack q]
28
29 isidoreGet :: Text -> IO ByteString
30 isidoreGet q = do
31 let s = createSelectQuery $ simpleSelect q
32 putStrLn s
33 r <- selectQueryRaw' route s
34 putStrLn $ show $ r ^. responseStatus
35 pure $ r ^. responseBody
36 -- res <- selectQuery route $ simpleSelect q
37 -- pure res
38
39 simpleSelect :: Text -> Query SelectQuery
40 simpleSelect q = do
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:")
49
50 link <- var
51 title <- var
52 date <- var
53 abstract <- var
54 authors <- var
55 source <- var
56 lang <- var
57 publisher <- var
58 agg <- var
59
60 indexT <- var
61
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
68
69 triple_ link (ore .:. "isAggregatedBy") agg
70 --triple_ agg (dcterms .:. "title") title
71
72
73 optional $ triple_ link (dcterms .:. "publisher") publisher
74 optional $ triple_ link (dc .:. "description") abstract
75
76 --filterExpr $ (.||.) (contains title q) (contains abstract q)
77
78 --triple_ indexT (bif .:. "contains") title
79
80 --filterExpr_ (contains indexT q) -- (contains abstract q)
81 orderNextDesc date
82 limit_ 10
83 distinct_
84 selectVars [link, date, authors, source, title, lang, publisher, abstract]