{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedLists #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeFamilies #-}
module Data.RDF.Types
(
LValue (PlainL, PlainLL, TypedL),
Node (UNode, BNode, BNodeGen, LNode),
Subject,
Predicate,
Object,
Triple (Triple),
Triples,
View (view),
plainL,
plainLL,
typedL,
unode,
bnode,
bnodeUnsafe,
lnode,
triple,
unodeValidate,
uriValidate,
uriValidateString,
isUNode,
isLNode,
isBNode,
resolveQName,
isAbsoluteUri,
mkAbsoluteUrl,
escapeRDFSyntax,
unescapeUnicode,
fileSchemeToFilePath,
filePathToUri,
iriFragment,
uchar,
RDF,
Rdf (baseUrl, prefixMappings, addPrefixMappings, empty, mkRdf, addTriple, removeTriple, triplesOf, uniqTriplesOf, select, query, showGraph),
RdfParser (parseString, parseFile, parseURL),
RdfSerializer (hWriteRdf, writeRdf, hWriteH, writeH, hWriteTs, hWriteT, writeT, writeTs, hWriteN, writeN),
Namespace (PrefixedNS, PlainNS),
PrefixMappings (PrefixMappings),
PrefixMapping (PrefixMapping),
BaseUrl (..),
NodeSelector,
ParseFailure (ParseFailure),
)
where
#if MIN_VERSION_base(4,9,0)
#if !MIN_VERSION_base(4,11,0)
import Data.Semigroup
#else
#endif
#else
#endif
import Control.Applicative
import qualified Control.Applicative as A
import Control.DeepSeq (NFData, rnf)
import Control.Monad (guard, (<=<))
import Data.Binary
import Data.Char (chr, ord)
import Data.Either (isRight)
import Data.Hashable (Hashable)
import qualified Data.List as List
import Data.Map (Map)
import qualified Data.Map as Map
import Data.RDF.BlankNode
import Data.RDF.IRI
import Data.String (IsString (..))
import Data.Text (Text)
import qualified Data.Text as T
import GHC.Generics (Generic)
import Network.URI
import qualified Network.URI as Network (parseURI, uriPath)
import qualified System.FilePath as FP
import System.IO
import Text.Parsec (ParseError, parse)
import Text.Parser.Char
import Text.Parser.Combinators
import Text.Printf
import Prelude hiding (pred)
data LValue
=
PlainL !Text
|
PlainLL !Text !Text
|
TypedL !Text !Text
deriving ((forall x. LValue -> Rep LValue x)
-> (forall x. Rep LValue x -> LValue) -> Generic LValue
forall x. Rep LValue x -> LValue
forall x. LValue -> Rep LValue x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. LValue -> Rep LValue x
from :: forall x. LValue -> Rep LValue x
$cto :: forall x. Rep LValue x -> LValue
to :: forall x. Rep LValue x -> LValue
Generic, Int -> LValue -> ShowS
[LValue] -> ShowS
LValue -> [Char]
(Int -> LValue -> ShowS)
-> (LValue -> [Char]) -> ([LValue] -> ShowS) -> Show LValue
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> LValue -> ShowS
showsPrec :: Int -> LValue -> ShowS
$cshow :: LValue -> [Char]
show :: LValue -> [Char]
$cshowList :: [LValue] -> ShowS
showList :: [LValue] -> ShowS
Show)
instance Binary LValue
instance NFData LValue where
rnf :: LValue -> ()
rnf (PlainL Text
t) = Text -> ()
forall a. NFData a => a -> ()
rnf Text
t
rnf (PlainLL Text
t1 Text
t2) = Text -> ()
forall a. NFData a => a -> ()
rnf Text
t1 () -> () -> ()
forall a b. a -> b -> b
`seq` Text -> ()
forall a. NFData a => a -> ()
rnf Text
t2
rnf (TypedL Text
t1 Text
t2) = Text -> ()
forall a. NFData a => a -> ()
rnf Text
t1 () -> () -> ()
forall a b. a -> b -> b
`seq` Text -> ()
forall a. NFData a => a -> ()
rnf Text
t2
{-# INLINE plainL #-}
plainL :: Text -> LValue
plainL :: Text -> LValue
plainL = Text -> LValue
PlainL
{-# INLINE plainLL #-}
plainLL :: Text -> Text -> LValue
plainLL :: Text -> Text -> LValue
plainLL = Text -> Text -> LValue
PlainLL
{-# INLINE typedL #-}
typedL :: Text -> Text -> LValue
typedL :: Text -> Text -> LValue
typedL Text
val Text
dtype = Text -> Text -> LValue
TypedL (Text -> Text -> Text
canonicalize Text
dtype Text
val) Text
dtype
data Node
=
UNode !Text
|
BNode !Text
|
BNodeGen !Int
|
LNode !LValue
deriving ((forall x. Subject -> Rep Subject x)
-> (forall x. Rep Subject x -> Subject) -> Generic Subject
forall x. Rep Subject x -> Subject
forall x. Subject -> Rep Subject x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Subject -> Rep Subject x
from :: forall x. Subject -> Rep Subject x
$cto :: forall x. Rep Subject x -> Subject
to :: forall x. Rep Subject x -> Subject
Generic, Int -> Subject -> ShowS
[Subject] -> ShowS
Subject -> [Char]
(Int -> Subject -> ShowS)
-> (Subject -> [Char]) -> ([Subject] -> ShowS) -> Show Subject
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Subject -> ShowS
showsPrec :: Int -> Subject -> ShowS
$cshow :: Subject -> [Char]
show :: Subject -> [Char]
$cshowList :: [Subject] -> ShowS
showList :: [Subject] -> ShowS
Show)
instance Binary Node
instance NFData Node where
rnf :: Subject -> ()
rnf (UNode Text
t) = Text -> ()
forall a. NFData a => a -> ()
rnf Text
t
rnf (BNode Text
b) = Text -> ()
forall a. NFData a => a -> ()
rnf Text
b
rnf (BNodeGen Int
bgen) = Int -> ()
forall a. NFData a => a -> ()
rnf Int
bgen
rnf (LNode LValue
lvalue) = LValue -> ()
forall a. NFData a => a -> ()
rnf LValue
lvalue
type Subject = Node
type Predicate = Node
type Object = Node
{-# INLINE unode #-}
unode :: Text -> Node
unode :: Text -> Subject
unode = Text -> Subject
UNode
unodeValidate :: Text -> Maybe Node
unodeValidate :: Text -> Maybe Subject
unodeValidate Text
t = Text -> Subject
UNode (Text -> Subject) -> Maybe Text -> Maybe Subject
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> Maybe Text
uriValidate Text
t
uriValidate :: Text -> Maybe Text
uriValidate :: Text -> Maybe Text
uriValidate = (ParseError -> Maybe Text)
-> (Text -> Maybe Text) -> Either ParseError Text -> Maybe Text
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (Maybe Text -> ParseError -> Maybe Text
forall a b. a -> b -> a
const Maybe Text
forall a. Maybe a
Nothing) Text -> Maybe Text
forall a. a -> Maybe a
Just (Either ParseError Text -> Maybe Text)
-> (Text -> Either ParseError Text) -> Text -> Maybe Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Either ParseError Text
isRdfURI
uriValidateString :: String -> Maybe String
uriValidateString :: [Char] -> Maybe [Char]
uriValidateString = (Text -> [Char]) -> Maybe Text -> Maybe [Char]
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Text -> [Char]
T.unpack (Maybe Text -> Maybe [Char])
-> ([Char] -> Maybe Text) -> [Char] -> Maybe [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Maybe Text
uriValidate (Text -> Maybe Text) -> ([Char] -> Text) -> [Char] -> Maybe Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> Text
forall a. IsString a => [Char] -> a
fromString
isRdfURI :: Text -> Either ParseError Text
isRdfURI :: Text -> Either ParseError Text
isRdfURI Text
t = Parsec Text () Text -> [Char] -> Text -> Either ParseError Text
forall s t a.
Stream s Identity t =>
Parsec s () a -> [Char] -> s -> Either ParseError a
parse (Parsec Text () Text
forall (m :: * -> *). (CharParsing m, Monad m) => m Text
iriFragment Parsec Text () Text
-> ParsecT Text () Identity () -> Parsec Text () Text
forall a b.
ParsecT Text () Identity a
-> ParsecT Text () Identity b -> ParsecT Text () Identity a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text () Identity ()
forall (m :: * -> *). Parsing m => m ()
eof) ([Char]
"Invalid URI: " [Char] -> ShowS
forall a. Semigroup a => a -> a -> a
<> Text -> [Char]
T.unpack Text
t) Text
t
iriFragment :: (CharParsing m, Monad m) => m Text
iriFragment :: forall (m :: * -> *). (CharParsing m, Monad m) => m Text
iriFragment = [Char] -> Text
T.pack ([Char] -> Text) -> m [Char] -> m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Char -> m [Char]
forall a. m a -> m [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many m Char
validUriChar
where
validUriChar :: m Char
validUriChar = m Char -> m Char
forall a. m a -> m a
forall (m :: * -> *) a. Parsing m => m a -> m a
try ((Char -> Bool) -> m Char
forall (m :: * -> *). CharParsing m => (Char -> Bool) -> m Char
satisfy Char -> Bool
isValidUriChar) m Char -> m Char -> m Char
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> m Char
validUnicodeEscaped
validUnicodeEscaped :: m Char
validUnicodeEscaped = do
Char
c <- m Char
forall (m :: * -> *). (CharParsing m, Monad m) => m Char
uchar
Bool -> m ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Char -> Bool
isValidUriChar Char
c)
Char -> m Char
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return Char
c
isValidUriChar :: Char -> Bool
isValidUriChar Char
c =
Bool -> Bool
not (Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
>= Char
'\x00' Bool -> Bool -> Bool
&& Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= Char
'\x20')
Bool -> Bool -> Bool
&& Char
c Char -> [Char] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` ([Char]
"<>\"{}|^`\\" :: String)
uchar :: (CharParsing m, Monad m) => m Char
uchar :: forall (m :: * -> *). (CharParsing m, Monad m) => m Char
uchar = m Char -> m Char
forall a. m a -> m a
forall (m :: * -> *) a. Parsing m => m a -> m a
try m Char
shortUnicode m Char -> m Char -> m Char
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> m Char -> m Char
forall a. m a -> m a
forall (m :: * -> *) a. Parsing m => m a -> m a
try m Char
longUnicode
where
shortUnicode :: m Char
shortUnicode = [Char] -> m [Char]
forall (m :: * -> *). CharParsing m => [Char] -> m [Char]
string [Char]
"\\u" m [Char] -> m Char -> m Char
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Int -> m Char
forall (m :: * -> *). (CharParsing m, Monad m) => Int -> m Char
unescapeUnicodeParser Int
4
longUnicode :: m Char
longUnicode = [Char] -> m [Char]
forall (m :: * -> *). CharParsing m => [Char] -> m [Char]
string [Char]
"\\U" m [Char] -> m Char -> m Char
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Int -> m Char
forall (m :: * -> *). (CharParsing m, Monad m) => Int -> m Char
unescapeUnicodeParser Int
8
unescapeUnicodeParser :: (CharParsing m, Monad m) => Int -> m Char
unescapeUnicodeParser :: forall (m :: * -> *). (CharParsing m, Monad m) => Int -> m Char
unescapeUnicodeParser Int
n = do
Int
c <- Int -> Int -> m Int
forall {t} {f :: * -> *}.
(Eq t, Num t, Monad f, CharParsing f) =>
t -> Int -> f Int
go Int
n Int
0
Bool -> m ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Int
c Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
0x10FFFF)
Char -> m Char
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Char -> m Char) -> Char -> m Char
forall a b. (a -> b) -> a -> b
$ Int -> Char
chr Int
c
where
{-# INLINE go #-}
go :: t -> Int -> f Int
go t
0 Int
t = Int -> f Int
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
t
go t
k Int
t = do
Int
h <- f Char
forall (m :: * -> *). CharParsing m => m Char
anyChar f Char -> (Char -> f Int) -> f Int
forall a b. f a -> (a -> f b) -> f b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Char -> f Int
forall {f :: * -> *}. Alternative f => Char -> f Int
getHex
let t' :: Int
t' = Int
t Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
16 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
h
Int -> Int -> Int
forall a b. a -> b -> b
seq Int
t' (Int -> Int) -> f Int -> f Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> t -> Int -> f Int
go (t
k t -> t -> t
forall a. Num a => a -> a -> a
- t
1) Int
t'
{-# INLINE getHex #-}
getHex :: Char -> f Int
getHex Char
c
| Char
'0' Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= Char
c Bool -> Bool -> Bool
&& Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= Char
'9' = Int -> f Int
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Char -> Int
ord Char
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Char -> Int
ord Char
'0')
| Char
'A' Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= Char
c Bool -> Bool -> Bool
&& Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= Char
'F' = Int -> f Int
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Char -> Int
ord Char
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Char -> Int
ord Char
'A' Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
10)
| Char
'a' Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= Char
c Bool -> Bool -> Bool
&& Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= Char
'f' = Int -> f Int
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Char -> Int
ord Char
c Int -> Int -> Int
forall a. Num a => a -> a -> a
- Char -> Int
ord Char
'a' Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
10)
| Bool
otherwise = f Int
forall a. f a
forall (f :: * -> *) a. Alternative f => f a
A.empty
unescapeUnicode, escapeRDFSyntax :: Text -> Either ParseError Text
unescapeUnicode :: Text -> Either ParseError Text
unescapeUnicode Text
t = [Char] -> Text
T.pack ([Char] -> Text)
-> Either ParseError [Char] -> Either ParseError Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parsec Text () [Char] -> [Char] -> Text -> Either ParseError [Char]
forall s t a.
Stream s Identity t =>
Parsec s () a -> [Char] -> s -> Either ParseError a
parse (ParsecT Text () Identity Char -> Parsec Text () [Char]
forall a.
ParsecT Text () Identity a -> ParsecT Text () Identity [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many ParsecT Text () Identity Char
unicodeEsc) [Char]
"" Text
t
where
unicodeEsc :: ParsecT Text () Identity Char
unicodeEsc = ParsecT Text () Identity Char
forall (m :: * -> *). (CharParsing m, Monad m) => m Char
uchar ParsecT Text () Identity Char
-> ParsecT Text () Identity Char -> ParsecT Text () Identity Char
forall a.
ParsecT Text () Identity a
-> ParsecT Text () Identity a -> ParsecT Text () Identity a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ParsecT Text () Identity Char
forall (m :: * -> *). CharParsing m => m Char
anyChar
{-# DEPRECATED escapeRDFSyntax "Use unescapeUnicode instead" #-}
escapeRDFSyntax :: Text -> Either ParseError Text
escapeRDFSyntax = Text -> Either ParseError Text
unescapeUnicode
{-# INLINE bnode #-}
bnode :: Text -> Maybe Node
bnode :: Text -> Maybe Subject
bnode Text
t =
case Text -> Maybe [Char]
mkBNode Text
t of
Maybe [Char]
Nothing -> Maybe Subject
forall a. Maybe a
Nothing
Just [Char]
bString -> Subject -> Maybe Subject
forall a. a -> Maybe a
Just (Text -> Subject
BNode ([Char] -> Text
T.pack [Char]
bString))
{-# INLINE bnodeUnsafe #-}
bnodeUnsafe :: Text -> Node
bnodeUnsafe :: Text -> Subject
bnodeUnsafe = Text -> Subject
BNode
{-# INLINE lnode #-}
lnode :: LValue -> Node
lnode :: LValue -> Subject
lnode = LValue -> Subject
LNode
data Triple = Triple !Node !Node !Node
deriving ((forall x. Triple -> Rep Triple x)
-> (forall x. Rep Triple x -> Triple) -> Generic Triple
forall x. Rep Triple x -> Triple
forall x. Triple -> Rep Triple x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Triple -> Rep Triple x
from :: forall x. Triple -> Rep Triple x
$cto :: forall x. Rep Triple x -> Triple
to :: forall x. Rep Triple x -> Triple
Generic, Int -> Triple -> ShowS
[Triple] -> ShowS
Triple -> [Char]
(Int -> Triple -> ShowS)
-> (Triple -> [Char]) -> ([Triple] -> ShowS) -> Show Triple
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Triple -> ShowS
showsPrec :: Int -> Triple -> ShowS
$cshow :: Triple -> [Char]
show :: Triple -> [Char]
$cshowList :: [Triple] -> ShowS
showList :: [Triple] -> ShowS
Show)
instance Binary Triple
instance NFData Triple where
rnf :: Triple -> ()
rnf (Triple Subject
s Subject
p Subject
o) = Subject -> ()
forall a. NFData a => a -> ()
rnf Subject
s () -> () -> ()
forall a b. a -> b -> b
`seq` Subject -> ()
forall a. NFData a => a -> ()
rnf Subject
p () -> () -> ()
forall a b. a -> b -> b
`seq` Subject -> ()
forall a. NFData a => a -> ()
rnf Subject
o
type Triples = [Triple]
triple :: Subject -> Predicate -> Object -> Triple
triple :: Subject -> Subject -> Subject -> Triple
triple Subject
s Subject
p Subject
o
| Subject -> Bool
isLNode Subject
s = [Char] -> Triple
forall a. HasCallStack => [Char] -> a
error ([Char] -> Triple) -> [Char] -> Triple
forall a b. (a -> b) -> a -> b
$ [Char]
"subject must be UNode or BNode: " [Char] -> ShowS
forall a. Semigroup a => a -> a -> a
<> Subject -> [Char]
forall a. Show a => a -> [Char]
show Subject
s
| Subject -> Bool
isLNode Subject
p = [Char] -> Triple
forall a. HasCallStack => [Char] -> a
error ([Char] -> Triple) -> [Char] -> Triple
forall a b. (a -> b) -> a -> b
$ [Char]
"predicate must be UNode, not LNode: " [Char] -> ShowS
forall a. Semigroup a => a -> a -> a
<> Subject -> [Char]
forall a. Show a => a -> [Char]
show Subject
p
| Subject -> Bool
isBNode Subject
p = [Char] -> Triple
forall a. HasCallStack => [Char] -> a
error ([Char] -> Triple) -> [Char] -> Triple
forall a b. (a -> b) -> a -> b
$ [Char]
"predicate must be UNode, not BNode: " [Char] -> ShowS
forall a. Semigroup a => a -> a -> a
<> Subject -> [Char]
forall a. Show a => a -> [Char]
show Subject
p
| Bool
otherwise = Subject -> Subject -> Subject -> Triple
Triple Subject
s Subject
p Subject
o
{-# INLINE isUNode #-}
isUNode :: Node -> Bool
isUNode :: Subject -> Bool
isUNode (UNode Text
_) = Bool
True
isUNode Subject
_ = Bool
False
{-# INLINE isBNode #-}
isBNode :: Node -> Bool
isBNode :: Subject -> Bool
isBNode (BNode Text
_) = Bool
True
isBNode (BNodeGen Int
_) = Bool
True
isBNode Subject
_ = Bool
False
{-# INLINE isLNode #-}
isLNode :: Node -> Bool
isLNode :: Subject -> Bool
isLNode (LNode LValue
_) = Bool
True
isLNode Subject
_ = Bool
False
{-# INLINE isAbsoluteUri #-}
isAbsoluteUri :: Text -> Bool
isAbsoluteUri :: Text -> Bool
isAbsoluteUri = Either [Char] IRIRef -> Bool
forall a b. Either a b -> Bool
isRight (Either [Char] IRIRef -> Bool)
-> (Text -> Either [Char] IRIRef) -> Text -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Either [Char] IRIRef
parseIRI
class View a b where
view :: a -> b
data family RDF a
class (Generic rdfImpl, NFData rdfImpl) => Rdf rdfImpl where
baseUrl :: RDF rdfImpl -> Maybe BaseUrl
prefixMappings :: RDF rdfImpl -> PrefixMappings
addPrefixMappings :: RDF rdfImpl -> PrefixMappings -> Bool -> RDF rdfImpl
empty :: RDF rdfImpl
mkRdf :: Triples -> Maybe BaseUrl -> PrefixMappings -> RDF rdfImpl
addTriple :: RDF rdfImpl -> Triple -> RDF rdfImpl
removeTriple :: RDF rdfImpl -> Triple -> RDF rdfImpl
triplesOf :: RDF rdfImpl -> Triples
uniqTriplesOf :: RDF rdfImpl -> Triples
select :: RDF rdfImpl -> NodeSelector -> NodeSelector -> NodeSelector -> Triples
query :: RDF rdfImpl -> Maybe Node -> Maybe Node -> Maybe Node -> Triples
showGraph :: RDF rdfImpl -> String
instance (Rdf a) => Show (RDF a) where
show :: RDF a -> [Char]
show = RDF a -> [Char]
forall a. Rdf a => RDF a -> [Char]
showGraph
class RdfParser p where
parseString :: (Rdf a) => p -> Text -> Either ParseFailure (RDF a)
parseFile :: (Rdf a) => p -> String -> IO (Either ParseFailure (RDF a))
parseURL :: (Rdf a) => p -> String -> IO (Either ParseFailure (RDF a))
class RdfSerializer s where
hWriteRdf :: (Rdf a) => s -> Handle -> RDF a -> IO ()
writeRdf :: (Rdf a) => s -> RDF a -> IO ()
hWriteH :: (Rdf a) => s -> Handle -> RDF a -> IO ()
writeH :: (Rdf a) => s -> RDF a -> IO ()
hWriteTs :: s -> Handle -> Triples -> IO ()
writeTs :: s -> Triples -> IO ()
hWriteT :: s -> Handle -> Triple -> IO ()
writeT :: s -> Triple -> IO ()
hWriteN :: s -> Handle -> Node -> IO ()
writeN :: s -> Node -> IO ()
newtype BaseUrl = BaseUrl {BaseUrl -> Text
unBaseUrl :: Text}
deriving (BaseUrl -> BaseUrl -> Bool
(BaseUrl -> BaseUrl -> Bool)
-> (BaseUrl -> BaseUrl -> Bool) -> Eq BaseUrl
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: BaseUrl -> BaseUrl -> Bool
== :: BaseUrl -> BaseUrl -> Bool
$c/= :: BaseUrl -> BaseUrl -> Bool
/= :: BaseUrl -> BaseUrl -> Bool
Eq, Eq BaseUrl
Eq BaseUrl =>
(BaseUrl -> BaseUrl -> Ordering)
-> (BaseUrl -> BaseUrl -> Bool)
-> (BaseUrl -> BaseUrl -> Bool)
-> (BaseUrl -> BaseUrl -> Bool)
-> (BaseUrl -> BaseUrl -> Bool)
-> (BaseUrl -> BaseUrl -> BaseUrl)
-> (BaseUrl -> BaseUrl -> BaseUrl)
-> Ord BaseUrl
BaseUrl -> BaseUrl -> Bool
BaseUrl -> BaseUrl -> Ordering
BaseUrl -> BaseUrl -> BaseUrl
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: BaseUrl -> BaseUrl -> Ordering
compare :: BaseUrl -> BaseUrl -> Ordering
$c< :: BaseUrl -> BaseUrl -> Bool
< :: BaseUrl -> BaseUrl -> Bool
$c<= :: BaseUrl -> BaseUrl -> Bool
<= :: BaseUrl -> BaseUrl -> Bool
$c> :: BaseUrl -> BaseUrl -> Bool
> :: BaseUrl -> BaseUrl -> Bool
$c>= :: BaseUrl -> BaseUrl -> Bool
>= :: BaseUrl -> BaseUrl -> Bool
$cmax :: BaseUrl -> BaseUrl -> BaseUrl
max :: BaseUrl -> BaseUrl -> BaseUrl
$cmin :: BaseUrl -> BaseUrl -> BaseUrl
min :: BaseUrl -> BaseUrl -> BaseUrl
Ord, Int -> BaseUrl -> ShowS
[BaseUrl] -> ShowS
BaseUrl -> [Char]
(Int -> BaseUrl -> ShowS)
-> (BaseUrl -> [Char]) -> ([BaseUrl] -> ShowS) -> Show BaseUrl
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> BaseUrl -> ShowS
showsPrec :: Int -> BaseUrl -> ShowS
$cshow :: BaseUrl -> [Char]
show :: BaseUrl -> [Char]
$cshowList :: [BaseUrl] -> ShowS
showList :: [BaseUrl] -> ShowS
Show, BaseUrl -> ()
(BaseUrl -> ()) -> NFData BaseUrl
forall a. (a -> ()) -> NFData a
$crnf :: BaseUrl -> ()
rnf :: BaseUrl -> ()
NFData, NonEmpty BaseUrl -> BaseUrl
BaseUrl -> BaseUrl -> BaseUrl
(BaseUrl -> BaseUrl -> BaseUrl)
-> (NonEmpty BaseUrl -> BaseUrl)
-> (forall b. Integral b => b -> BaseUrl -> BaseUrl)
-> Semigroup BaseUrl
forall b. Integral b => b -> BaseUrl -> BaseUrl
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
$c<> :: BaseUrl -> BaseUrl -> BaseUrl
<> :: BaseUrl -> BaseUrl -> BaseUrl
$csconcat :: NonEmpty BaseUrl -> BaseUrl
sconcat :: NonEmpty BaseUrl -> BaseUrl
$cstimes :: forall b. Integral b => b -> BaseUrl -> BaseUrl
stimes :: forall b. Integral b => b -> BaseUrl -> BaseUrl
Semigroup, (forall x. BaseUrl -> Rep BaseUrl x)
-> (forall x. Rep BaseUrl x -> BaseUrl) -> Generic BaseUrl
forall x. Rep BaseUrl x -> BaseUrl
forall x. BaseUrl -> Rep BaseUrl x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. BaseUrl -> Rep BaseUrl x
from :: forall x. BaseUrl -> Rep BaseUrl x
$cto :: forall x. Rep BaseUrl x -> BaseUrl
to :: forall x. Rep BaseUrl x -> BaseUrl
Generic)
instance Binary BaseUrl
instance Monoid BaseUrl where
mempty :: BaseUrl
mempty = Text -> BaseUrl
BaseUrl Text
T.empty
type NodeSelector = Maybe (Node -> Bool)
newtype ParseFailure = ParseFailure String
deriving (ParseFailure -> ParseFailure -> Bool
(ParseFailure -> ParseFailure -> Bool)
-> (ParseFailure -> ParseFailure -> Bool) -> Eq ParseFailure
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ParseFailure -> ParseFailure -> Bool
== :: ParseFailure -> ParseFailure -> Bool
$c/= :: ParseFailure -> ParseFailure -> Bool
/= :: ParseFailure -> ParseFailure -> Bool
Eq, Int -> ParseFailure -> ShowS
[ParseFailure] -> ShowS
ParseFailure -> [Char]
(Int -> ParseFailure -> ShowS)
-> (ParseFailure -> [Char])
-> ([ParseFailure] -> ShowS)
-> Show ParseFailure
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ParseFailure -> ShowS
showsPrec :: Int -> ParseFailure -> ShowS
$cshow :: ParseFailure -> [Char]
show :: ParseFailure -> [Char]
$cshowList :: [ParseFailure] -> ShowS
showList :: [ParseFailure] -> ShowS
Show)
instance Eq Node where
(UNode Text
bs1) == :: Subject -> Subject -> Bool
== (UNode Text
bs2) = Text
bs1 Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
bs2
(BNode Text
bs1) == (BNode Text
bs2) = Text
bs1 Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
bs2
(BNodeGen Int
i1) == (BNodeGen Int
i2) = Int
i1 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
i2
(LNode LValue
l1) == (LNode LValue
l2) = LValue
l1 LValue -> LValue -> Bool
forall a. Eq a => a -> a -> Bool
== LValue
l2
Subject
_ == Subject
_ = Bool
False
instance Ord Node where
compare :: Subject -> Subject -> Ordering
compare (UNode Text
bs1) (UNode Text
bs2) = Text -> Text -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Text
bs1 Text
bs2
compare (UNode Text
_) Subject
_ = Ordering
LT
compare Subject
_ (UNode Text
_) = Ordering
GT
compare (BNode Text
bs1) (BNode Text
bs2) = Text -> Text -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Text
bs1 Text
bs2
compare (BNode Text
_) Subject
_ = Ordering
LT
compare Subject
_ (BNode Text
_) = Ordering
GT
compare (BNodeGen Int
i1) (BNodeGen Int
i2) = Int -> Int -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Int
i1 Int
i2
compare (BNodeGen Int
_) Subject
_ = Ordering
LT
compare Subject
_ (BNodeGen Int
_) = Ordering
GT
compare (LNode LValue
lv1) (LNode LValue
lv2) = LValue -> LValue -> Ordering
forall a. Ord a => a -> a -> Ordering
compare LValue
lv1 LValue
lv2
instance Hashable Node
instance Eq Triple where
(Triple Subject
s1 Subject
p1 Subject
o1) == :: Triple -> Triple -> Bool
== (Triple Subject
s2 Subject
p2 Subject
o2) = Subject
s1 Subject -> Subject -> Bool
forall a. Eq a => a -> a -> Bool
== Subject
s2 Bool -> Bool -> Bool
&& Subject
p1 Subject -> Subject -> Bool
forall a. Eq a => a -> a -> Bool
== Subject
p2 Bool -> Bool -> Bool
&& Subject
o1 Subject -> Subject -> Bool
forall a. Eq a => a -> a -> Bool
== Subject
o2
instance Ord Triple where
{-# INLINE compare #-}
(Triple Subject
s1 Subject
p1 Subject
o1) compare :: Triple -> Triple -> Ordering
`compare` (Triple Subject
s2 Subject
p2 Subject
o2) =
Subject -> Subject -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Subject
s1 Subject
s2 Ordering -> Ordering -> Ordering
forall a. Monoid a => a -> a -> a
`mappend` Subject -> Subject -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Subject
p1 Subject
p2 Ordering -> Ordering -> Ordering
forall a. Monoid a => a -> a -> a
`mappend` Subject -> Subject -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Subject
o1 Subject
o2
instance Eq LValue where
(PlainL Text
v1) == :: LValue -> LValue -> Bool
== (PlainL Text
v2) = Text
v1 Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
v2
(PlainLL Text
v1 Text
lt1) == (PlainLL Text
v2 Text
lt2) = Text -> Text
T.toLower Text
lt1 Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text -> Text
T.toLower Text
lt2 Bool -> Bool -> Bool
&& Text
v1 Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
v2
(TypedL Text
v1 Text
dt1) == (TypedL Text
v2 Text
dt2) = Text
v1 Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
v2 Bool -> Bool -> Bool
&& Text
dt1 Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
dt2
LValue
_ == LValue
_ = Bool
False
instance Ord LValue where
{-# INLINE compare #-}
compare :: LValue -> LValue -> Ordering
compare (PlainL Text
v1) (PlainL Text
v2) = Text -> Text -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Text
v1 Text
v2
compare (PlainL Text
_) LValue
_ = Ordering
LT
compare LValue
_ (PlainL Text
_) = Ordering
GT
compare (PlainLL Text
v1 Text
lt1) (PlainLL Text
v2 Text
lt2) = Text -> Text -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Text
lt1 Text
lt2 Ordering -> Ordering -> Ordering
forall a. Monoid a => a -> a -> a
`mappend` Text -> Text -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Text
v1 Text
v2
compare (PlainLL Text
_ Text
_) LValue
_ = Ordering
LT
compare LValue
_ (PlainLL Text
_ Text
_) = Ordering
GT
compare (TypedL Text
v1 Text
dt1) (TypedL Text
v2 Text
dt2) = Text -> Text -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Text
dt1 Text
dt2 Ordering -> Ordering -> Ordering
forall a. Monoid a => a -> a -> a
`mappend` Text -> Text -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Text
v1 Text
v2
instance Hashable LValue
data Namespace
= PrefixedNS Text Text
| PlainNS Text
instance Eq Namespace where
(PrefixedNS Text
_ Text
u1) == :: Namespace -> Namespace -> Bool
== (PrefixedNS Text
_ Text
u2) = Text
u1 Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
u2
(PlainNS Text
u1) == (PlainNS Text
u2) = Text
u1 Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
u2
(PrefixedNS Text
_ Text
u1) == (PlainNS Text
u2) = Text
u1 Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
u2
(PlainNS Text
u1) == (PrefixedNS Text
_ Text
u2) = Text
u1 Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
u2
instance Show Namespace where
show :: Namespace -> [Char]
show (PlainNS Text
uri) = Text -> [Char]
T.unpack Text
uri
show (PrefixedNS Text
prefix Text
uri) = [Char] -> [Char] -> ShowS
forall r. PrintfType r => [Char] -> r
printf [Char]
"(PrefixNS %s %s)" (Text -> [Char]
T.unpack Text
prefix) (Text -> [Char]
T.unpack Text
uri)
newtype PrefixMappings = PrefixMappings (Map Text Text)
deriving (PrefixMappings -> PrefixMappings -> Bool
(PrefixMappings -> PrefixMappings -> Bool)
-> (PrefixMappings -> PrefixMappings -> Bool) -> Eq PrefixMappings
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PrefixMappings -> PrefixMappings -> Bool
== :: PrefixMappings -> PrefixMappings -> Bool
$c/= :: PrefixMappings -> PrefixMappings -> Bool
/= :: PrefixMappings -> PrefixMappings -> Bool
Eq, Eq PrefixMappings
Eq PrefixMappings =>
(PrefixMappings -> PrefixMappings -> Ordering)
-> (PrefixMappings -> PrefixMappings -> Bool)
-> (PrefixMappings -> PrefixMappings -> Bool)
-> (PrefixMappings -> PrefixMappings -> Bool)
-> (PrefixMappings -> PrefixMappings -> Bool)
-> (PrefixMappings -> PrefixMappings -> PrefixMappings)
-> (PrefixMappings -> PrefixMappings -> PrefixMappings)
-> Ord PrefixMappings
PrefixMappings -> PrefixMappings -> Bool
PrefixMappings -> PrefixMappings -> Ordering
PrefixMappings -> PrefixMappings -> PrefixMappings
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: PrefixMappings -> PrefixMappings -> Ordering
compare :: PrefixMappings -> PrefixMappings -> Ordering
$c< :: PrefixMappings -> PrefixMappings -> Bool
< :: PrefixMappings -> PrefixMappings -> Bool
$c<= :: PrefixMappings -> PrefixMappings -> Bool
<= :: PrefixMappings -> PrefixMappings -> Bool
$c> :: PrefixMappings -> PrefixMappings -> Bool
> :: PrefixMappings -> PrefixMappings -> Bool
$c>= :: PrefixMappings -> PrefixMappings -> Bool
>= :: PrefixMappings -> PrefixMappings -> Bool
$cmax :: PrefixMappings -> PrefixMappings -> PrefixMappings
max :: PrefixMappings -> PrefixMappings -> PrefixMappings
$cmin :: PrefixMappings -> PrefixMappings -> PrefixMappings
min :: PrefixMappings -> PrefixMappings -> PrefixMappings
Ord, PrefixMappings -> ()
(PrefixMappings -> ()) -> NFData PrefixMappings
forall a. (a -> ()) -> NFData a
$crnf :: PrefixMappings -> ()
rnf :: PrefixMappings -> ()
NFData, NonEmpty PrefixMappings -> PrefixMappings
PrefixMappings -> PrefixMappings -> PrefixMappings
(PrefixMappings -> PrefixMappings -> PrefixMappings)
-> (NonEmpty PrefixMappings -> PrefixMappings)
-> (forall b. Integral b => b -> PrefixMappings -> PrefixMappings)
-> Semigroup PrefixMappings
forall b. Integral b => b -> PrefixMappings -> PrefixMappings
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
$c<> :: PrefixMappings -> PrefixMappings -> PrefixMappings
<> :: PrefixMappings -> PrefixMappings -> PrefixMappings
$csconcat :: NonEmpty PrefixMappings -> PrefixMappings
sconcat :: NonEmpty PrefixMappings -> PrefixMappings
$cstimes :: forall b. Integral b => b -> PrefixMappings -> PrefixMappings
stimes :: forall b. Integral b => b -> PrefixMappings -> PrefixMappings
Semigroup, Semigroup PrefixMappings
PrefixMappings
Semigroup PrefixMappings =>
PrefixMappings
-> (PrefixMappings -> PrefixMappings -> PrefixMappings)
-> ([PrefixMappings] -> PrefixMappings)
-> Monoid PrefixMappings
[PrefixMappings] -> PrefixMappings
PrefixMappings -> PrefixMappings -> PrefixMappings
forall a.
Semigroup a =>
a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
$cmempty :: PrefixMappings
mempty :: PrefixMappings
$cmappend :: PrefixMappings -> PrefixMappings -> PrefixMappings
mappend :: PrefixMappings -> PrefixMappings -> PrefixMappings
$cmconcat :: [PrefixMappings] -> PrefixMappings
mconcat :: [PrefixMappings] -> PrefixMappings
Monoid, (forall x. PrefixMappings -> Rep PrefixMappings x)
-> (forall x. Rep PrefixMappings x -> PrefixMappings)
-> Generic PrefixMappings
forall x. Rep PrefixMappings x -> PrefixMappings
forall x. PrefixMappings -> Rep PrefixMappings x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. PrefixMappings -> Rep PrefixMappings x
from :: forall x. PrefixMappings -> Rep PrefixMappings x
$cto :: forall x. Rep PrefixMappings x -> PrefixMappings
to :: forall x. Rep PrefixMappings x -> PrefixMappings
Generic)
instance Binary PrefixMappings
instance Show PrefixMappings where
show :: PrefixMappings -> [Char]
show (PrefixMappings Map Text Text
pmap) = [Char] -> ShowS
forall r. PrintfType r => [Char] -> r
printf [Char]
"PrefixMappings [%s]" [Char]
mappingsStr
where
showPM :: (Text, Text) -> [Char]
showPM = PrefixMapping -> [Char]
forall a. Show a => a -> [Char]
show (PrefixMapping -> [Char])
-> ((Text, Text) -> PrefixMapping) -> (Text, Text) -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text, Text) -> PrefixMapping
PrefixMapping
mappingsStr :: [Char]
mappingsStr = [Char] -> [[Char]] -> [Char]
forall a. [a] -> [[a]] -> [a]
List.intercalate [Char]
", " (((Text, Text) -> [Char]) -> [(Text, Text)] -> [[Char]]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Text, Text) -> [Char]
showPM (Map Text Text -> [(Text, Text)]
forall k a. Map k a -> [(k, a)]
Map.toList Map Text Text
pmap))
newtype PrefixMapping = PrefixMapping (Text, Text)
deriving (PrefixMapping -> PrefixMapping -> Bool
(PrefixMapping -> PrefixMapping -> Bool)
-> (PrefixMapping -> PrefixMapping -> Bool) -> Eq PrefixMapping
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PrefixMapping -> PrefixMapping -> Bool
== :: PrefixMapping -> PrefixMapping -> Bool
$c/= :: PrefixMapping -> PrefixMapping -> Bool
/= :: PrefixMapping -> PrefixMapping -> Bool
Eq, Eq PrefixMapping
Eq PrefixMapping =>
(PrefixMapping -> PrefixMapping -> Ordering)
-> (PrefixMapping -> PrefixMapping -> Bool)
-> (PrefixMapping -> PrefixMapping -> Bool)
-> (PrefixMapping -> PrefixMapping -> Bool)
-> (PrefixMapping -> PrefixMapping -> Bool)
-> (PrefixMapping -> PrefixMapping -> PrefixMapping)
-> (PrefixMapping -> PrefixMapping -> PrefixMapping)
-> Ord PrefixMapping
PrefixMapping -> PrefixMapping -> Bool
PrefixMapping -> PrefixMapping -> Ordering
PrefixMapping -> PrefixMapping -> PrefixMapping
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: PrefixMapping -> PrefixMapping -> Ordering
compare :: PrefixMapping -> PrefixMapping -> Ordering
$c< :: PrefixMapping -> PrefixMapping -> Bool
< :: PrefixMapping -> PrefixMapping -> Bool
$c<= :: PrefixMapping -> PrefixMapping -> Bool
<= :: PrefixMapping -> PrefixMapping -> Bool
$c> :: PrefixMapping -> PrefixMapping -> Bool
> :: PrefixMapping -> PrefixMapping -> Bool
$c>= :: PrefixMapping -> PrefixMapping -> Bool
>= :: PrefixMapping -> PrefixMapping -> Bool
$cmax :: PrefixMapping -> PrefixMapping -> PrefixMapping
max :: PrefixMapping -> PrefixMapping -> PrefixMapping
$cmin :: PrefixMapping -> PrefixMapping -> PrefixMapping
min :: PrefixMapping -> PrefixMapping -> PrefixMapping
Ord)
instance Show PrefixMapping where
show :: PrefixMapping -> [Char]
show (PrefixMapping (Text
prefix, Text
uri)) = [Char] -> [Char] -> ShowS
forall r. PrintfType r => [Char] -> r
printf [Char]
"PrefixMapping (%s, %s)" (Text -> [Char]
forall a. Show a => a -> [Char]
show Text
prefix) (Text -> [Char]
forall a. Show a => a -> [Char]
show Text
uri)
resolveQName :: Text -> PrefixMappings -> Maybe Text
resolveQName :: Text -> PrefixMappings -> Maybe Text
resolveQName Text
prefix (PrefixMappings Map Text Text
pms) = Text -> Map Text Text -> Maybe Text
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup Text
prefix Map Text Text
pms
{-# INLINE mkAbsoluteUrl #-}
{-# DEPRECATED mkAbsoluteUrl "Use resolveIRI instead, because mkAbsoluteUrl is a partial function" #-}
mkAbsoluteUrl :: Text -> Text -> Text
mkAbsoluteUrl :: Text -> Text -> Text
mkAbsoluteUrl Text
base Text
iri = ([Char] -> Text) -> (Text -> Text) -> Either [Char] Text -> Text
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either [Char] -> Text
forall a. HasCallStack => [Char] -> a
error Text -> Text
forall a. a -> a
id (Text -> Text -> Either [Char] Text
resolveIRI Text
base Text
iri)
{-# NOINLINE canonicalize #-}
canonicalize :: Text -> Text -> Text
canonicalize :: Text -> Text -> Text
canonicalize Text
typeTxt Text
litValue =
Text -> ((Text -> Text) -> Text) -> Maybe (Text -> Text) -> Text
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Text
litValue ((Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ Text
litValue) (Text -> Map Text (Text -> Text) -> Maybe (Text -> Text)
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup Text
typeTxt Map Text (Text -> Text)
canonicalizerTable)
{-# NOINLINE canonicalizerTable #-}
canonicalizerTable :: Map Text (Text -> Text)
canonicalizerTable :: Map Text (Text -> Text)
canonicalizerTable =
[(Text
integerUri, Text -> Text
_integerStr), (Text
doubleUri, Text -> Text
_doubleStr), (Text
decimalUri, Text -> Text
_decimalStr)]
where
integerUri :: Text
integerUri = Text
"http://www.w3.org/2001/XMLSchema#integer"
decimalUri :: Text
decimalUri = Text
"http://www.w3.org/2001/XMLSchema#decimal"
doubleUri :: Text
doubleUri = Text
"http://www.w3.org/2001/XMLSchema#double"
_integerStr, _decimalStr, _doubleStr :: Text -> Text
_integerStr :: Text -> Text
_integerStr Text
t
| Text -> Int
T.length Text
t Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
1 = Text
t
| HasCallStack => Text -> Char
Text -> Char
T.head Text
t Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'0' = Text -> Text
_integerStr (HasCallStack => Text -> Text
Text -> Text
T.tail Text
t)
| Bool
otherwise = Text
t
_doubleStr :: Text -> Text
_doubleStr Text
s = [Char] -> Text
T.pack ([Char] -> Text) -> [Char] -> Text
forall a b. (a -> b) -> a -> b
$ Double -> [Char]
forall a. Show a => a -> [Char]
show ([Char] -> Double
forall a. Read a => [Char] -> a
read ([Char] -> Double) -> [Char] -> Double
forall a b. (a -> b) -> a -> b
$ Text -> [Char]
T.unpack Text
s :: Double)
_decimalStr :: Text -> Text
_decimalStr Text
s =
case HasCallStack => Text -> Char
Text -> Char
T.last Text
s of
Char
'.' -> Text -> Text
f (Text
s Text -> Char -> Text
`T.snoc` Char
'0')
Char
_ -> Text -> Text
f Text
s
where
f :: Text -> Text
f Text
s' = [Char] -> Text
T.pack ([Char] -> Text) -> [Char] -> Text
forall a b. (a -> b) -> a -> b
$ Double -> [Char]
forall a. Show a => a -> [Char]
show ([Char] -> Double
forall a. Read a => [Char] -> a
read ([Char] -> Double) -> [Char] -> Double
forall a b. (a -> b) -> a -> b
$ Text -> [Char]
T.unpack Text
s' :: Double)
fileSchemeToFilePath :: (IsString s) => Node -> Maybe s
fileSchemeToFilePath :: forall s. IsString s => Subject -> Maybe s
fileSchemeToFilePath (UNode Text
fileScheme)
| Text
"file://" Text -> Text -> Bool
`T.isPrefixOf` Text
fileScheme = Text -> Maybe s
textToFilePath Text
fileScheme
| Bool
otherwise = Maybe s
forall a. Maybe a
Nothing
where
textToFilePath :: Text -> Maybe s
textToFilePath = s -> Maybe s
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (s -> Maybe s) -> ([Char] -> s) -> [Char] -> Maybe s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> s
forall a. IsString a => [Char] -> a
fromString ([Char] -> Maybe s) -> (Text -> Maybe [Char]) -> Text -> Maybe s
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< [Char] -> Maybe [Char]
stringToFilePath ([Char] -> Maybe [Char])
-> (Text -> [Char]) -> Text -> Maybe [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> [Char]
T.unpack
stringToFilePath :: [Char] -> Maybe [Char]
stringToFilePath = [Char] -> Maybe [Char]
fixPrefix ([Char] -> Maybe [Char])
-> ([Char] -> Maybe [Char]) -> [Char] -> Maybe [Char]
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< [Char] -> Maybe [Char]
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([Char] -> Maybe [Char]) -> (URI -> [Char]) -> URI -> Maybe [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
unEscapeString ShowS -> (URI -> [Char]) -> URI -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. URI -> [Char]
Network.uriPath (URI -> Maybe [Char])
-> ([Char] -> Maybe URI) -> [Char] -> Maybe [Char]
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< [Char] -> Maybe URI
Network.parseURI
fixPrefix :: [Char] -> Maybe [Char]
fixPrefix [Char]
"" = Maybe [Char]
forall a. Maybe a
Nothing
fixPrefix p :: [Char]
p@(Char
p' : [Char]
p'')
| Char
p' Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
FP.pathSeparator = [Char] -> Maybe [Char]
forall a. a -> Maybe a
Just (ShowS
FP.normalise [Char]
p)
| Char
p' Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'/' = [Char] -> Maybe [Char]
forall a. a -> Maybe a
Just (ShowS
FP.normalise [Char]
p'')
| Bool
otherwise = [Char] -> Maybe [Char]
forall a. a -> Maybe a
Just ([Char]
"\\\\" [Char] -> ShowS
forall a. Semigroup a => a -> a -> a
<> ShowS
FP.normalise [Char]
p)
fileSchemeToFilePath Subject
_ = Maybe s
forall a. Maybe a
Nothing
filePathToUri :: (IsString s) => FilePath -> Maybe s
filePathToUri :: forall s. IsString s => [Char] -> Maybe s
filePathToUri [Char]
p
| [Char] -> Bool
FP.isRelative [Char]
p = Maybe s
forall a. Maybe a
Nothing
| Bool
otherwise = s -> Maybe s
forall a. a -> Maybe a
Just (s -> Maybe s) -> ([Char] -> s) -> [Char] -> Maybe s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> s
forall a. IsString a => [Char] -> a
fromString ([Char] -> s) -> ShowS -> [Char] -> s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
as_uri ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
FP.normalise ([Char] -> Maybe s) -> [Char] -> Maybe s
forall a b. (a -> b) -> a -> b
$ [Char]
p
where
as_uri :: ShowS
as_uri = ([Char]
"file://" [Char] -> ShowS
forall a. Semigroup a => a -> a -> a
<>) ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Bool) -> ShowS
escapeURIString Char -> Bool
isAllowedInURI ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
as_posix ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
fix_prefix
fix_prefix :: ShowS
fix_prefix [Char]
p' = case (ShowS
FP.takeDrive [Char]
p') of
[Char]
"/" -> [Char]
p'
Char
'\\' : Char
'\\' : [Char]
_ -> Int -> ShowS
forall a. Int -> [a] -> [a]
drop Int
2 [Char]
p'
[Char]
_ -> Char
'/' Char -> ShowS
forall a. a -> [a] -> [a]
: [Char]
p'
as_posix :: ShowS
as_posix = (Char -> Char) -> ShowS
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Char -> Char
repl
repl :: Char -> Char
repl Char
'\\' = Char
'/'
repl Char
c = Char
c