{-# LANGUAGE OverloadedStrings #-}
module Data.RDF.Encoder.NQuads (
encodeRDFGraph
, encodeRDFGraphs
, encodeTriple
, encodeQuad
) where
import qualified Data.ByteString.Builder as B
import Data.RDF.Types
import Data.RDF.Encoder.Common
encodeTriple :: Triple -> B.Builder
encodeTriple :: Triple -> Builder
encodeTriple (Triple Subject
s Predicate
p Object
o) = Subject -> Builder
encodeSubject Subject
s
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
B.byteString ByteString
" "
forall a. Semigroup a => a -> a -> a
<> Predicate -> Builder
encodePredicate Predicate
p
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
B.byteString ByteString
" "
forall a. Semigroup a => a -> a -> a
<> Object -> Builder
encodeObject Object
o
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
B.byteString ByteString
" .\n"
encodeQuad :: Quad -> B.Builder
encodeQuad :: Quad -> Builder
encodeQuad (Quad Triple
t Maybe IRI
Nothing) = Triple -> Builder
encodeTriple Triple
t
encodeQuad (Quad (Triple Subject
s Predicate
p Object
o) (Just IRI
g)) = Subject -> Builder
encodeSubject Subject
s
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
B.byteString ByteString
" "
forall a. Semigroup a => a -> a -> a
<> Predicate -> Builder
encodePredicate Predicate
p
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
B.byteString ByteString
" "
forall a. Semigroup a => a -> a -> a
<> Object -> Builder
encodeObject Object
o
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
B.byteString ByteString
" "
forall a. Semigroup a => a -> a -> a
<> IRI -> Builder
encodeEscapedIRI IRI
g
forall a. Semigroup a => a -> a -> a
<> ByteString -> Builder
B.byteString ByteString
" .\n"
encodeRDFGraph :: RDFGraph -> B.Builder
encodeRDFGraph :: RDFGraph -> Builder
encodeRDFGraph (RDFGraph Maybe IRI
Nothing [Triple]
ts) = forall a. Monoid a => [a] -> a
mconcat forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map Triple -> Builder
encodeTriple [Triple]
ts
encodeRDFGraph (RDFGraph (Just IRI
g) [Triple]
ts) = let qs :: [Quad]
qs = forall a b. (a -> b) -> [a] -> [b]
map (\Triple
t -> Triple -> Maybe IRI -> Quad
Quad Triple
t (forall a. a -> Maybe a
Just IRI
g)) [Triple]
ts
in forall a. Monoid a => [a] -> a
mconcat forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map Quad -> Builder
encodeQuad [Quad]
qs
encodeRDFGraphs :: Foldable f => f RDFGraph -> B.Builder
encodeRDFGraphs :: forall (f :: * -> *). Foldable f => f RDFGraph -> Builder
encodeRDFGraphs = forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap RDFGraph -> Builder
encodeRDFGraph