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 (Maybe [[BindingValue]])
31 let s = createSelectQuery $ isidoreSelect q
33 r <- selectQueryRaw' route s
34 putStrLn $ show $ r ^. responseStatus
35 pure $ structureContent $ r ^. responseBody
36 -- res <- selectQuery route $ simpleSelect q
39 isidoreSelect :: 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 --iso <- prefix "fra" (iriRef "http://lexvo.org/id/iso639-3/")
48 --ore <- prefix "ore" (iriRef "http://www.openarchives.org/ore/terms/")
49 --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") langDoc
67 triple_ link (dc .:. "description") abstract
68 --triple_ link (ore .:. "isAggregatedBy") agg
69 --triple_ agg (dcterms .:. "title") title
71 optional_ $ triple_ link (dcterms .:. "source") source
72 optional_ $ triple_ link (dcterms .:. "publisher") publisher
74 -- TODO FIX BUG with (.||.) operator
75 --filterExpr $ (.||.) (contains title q) (contains title q)
76 filterExpr_ (containsWith title q) -- (contains abstract q)
77 --filterExpr (containsWith abstract q) -- (contains abstract q)
79 -- TODO FIX filter with lang
80 --filterExpr $ langMatches title (str ("fra" :: Text))
81 --filterExpr $ (.==.) lang (str ("http://lexvo.org/id/iso639-3/fra" :: Text))
86 selectVars [link, date, langDoc, authors, source, publisher, title, abstract]