summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordefanor <defanor@uberspace.net>2018-02-22 00:54:45 +0300
committerdefanor <defanor@uberspace.net>2018-02-22 13:18:18 +0300
commit664defb9d6733452f465275562708c00228d64f9 (patch)
tree7274558f4cffb1ab6e91fe1144baba9b8b4b487e
parent9939aa23bb11b22be9e570c972be6a898b9df8eb (diff)
downloadpancake-664defb9d6733452f465275562708c00228d64f9.zip
pancake-664defb9d6733452f465275562708c00228d64f9.tar.gz
pancake-664defb9d6733452f465275562708c00228d64f9.tar.bz2
RDF: avoid an unnecessary query
-rw-r--r--Text/Pandoc/Readers/RDF.hs40
1 files changed, 18 insertions, 22 deletions
diff --git a/Text/Pandoc/Readers/RDF.hs b/Text/Pandoc/Readers/RDF.hs
index 081b71e..bf58695 100644
--- a/Text/Pandoc/Readers/RDF.hs
+++ b/Text/Pandoc/Readers/RDF.hs
@@ -46,10 +46,7 @@ import Text.Pandoc.Error (PandocError(..))
import Control.Exception
import System.Directory
-import Foreign
-import Redland.MidLevel
-import Redland.LowLevel
-import Redland.Util
+import Redland
detectAlternateVersion :: T.Text -> IO (Maybe URI)
@@ -89,32 +86,31 @@ readRDF bu rf t = do
parseDoc = Right . Pandoc mempty . pure . LineBlock <$> do
withWSMU "memory" [] "temporary" "" (uriToString id bu "") $
\world _ model uri -> do
- tryParseStringIntoModel world ["turtle", "rdfxml", "n-triples"]
- model uri (T.unpack t)
- withQuery world model "sparql" "SELECT ?s ?p ?o WHERE { ?s ?p ?o }"
- (Just uri) $ \results -> do
- cacheDir <- getXdgDirectory XdgCache "pancake"
- createDirectoryIfMissing True cacheDir
- withWSMU "hashes" [("hash-type", "bdb"), ("dir", cacheDir)]
- "rdf-cache" "" (uriToString id bu "") $ \world' _ model' uri' ->
- mapM (printTriple (world', model', uri')) results
- -- todo: should probably use statements instead, need to complete
- -- that part of the bindings.
+ guessingParseStringIntoModel world model uri (T.unpack t)
+ withStatements world model (Triple Nothing Nothing Nothing) $
+ \triples -> do
+ cacheDir <- getXdgDirectory XdgCache "pancake"
+ createDirectoryIfMissing True cacheDir
+ withWSMU "hashes" [("hash-type", "bdb"), ("dir", cacheDir)]
+ "rdf-cache" "" (uriToString id bu "") $ \world' _ model' uri' ->
+ mapM (printTriple (world', model', uri')) triples
printTriple :: ( ForeignPtr RedlandWorld
, ForeignPtr RedlandModel
, ForeignPtr RedlandURI)
- -> [(String, Node)]
+ -> Triple
-> IO [Inline]
- printTriple wmu l =
- concat . intersperse [Space] <$> mapM (printNode wmu . snd) l
+ printTriple wmu triple =
+ concat . intersperse [Space] <$>
+ mapM (printNode wmu) [subject triple, predicate triple, object triple]
printNode :: ( ForeignPtr RedlandWorld
, ForeignPtr RedlandModel
, ForeignPtr RedlandURI)
- -> Node
+ -> Maybe Node
-> IO [Inline]
- printNode _ (BlankNode s) = pure [Str s]
- printNode _ (LiteralNode s) = pure [Str s]
- printNode (w, m, u) (ResourceNode s) =
+ printNode _ Nothing = pure [Str "-"]
+ printNode _ (Just (BlankNode s)) = pure [Str s]
+ printNode _ (Just (LiteralNode s)) = pure [Str s]
+ printNode (w, m, u) (Just (ResourceNode s)) =
let su = showURI s
q = "SELECT ?label WHERE { <" ++ s ++
"> <http://www.w3.org/2000/01/rdf-schema#label> ?label }"