{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
module Swish.RDF.Graph
(
RDFLabel(..), ToRDFLabel(..), FromRDFLabel(..)
, isLiteral, isUntypedLiteral, isTypedLiteral, isXMLLiteral
, isDatatyped, isMemberProp, isUri, isBlank, isQueryVar
, getLiteralText, getScopedName, makeBlank
, quote
, quoteT
, RDFArcSet
, RDFTriple
, toRDFTriple, fromRDFTriple
, NSGraph(..)
, RDFGraph
, toRDFGraph, emptyRDFGraph
, NamespaceMap
, emptyNamespaceMap
, LookupFormula(..), Formula, FormulaMap, emptyFormulaMap
, addArc, merge
, allLabels, allNodes, remapLabels, remapLabelList
, newNode, newNodes
, setNamespaces, getNamespaces
, setFormulae, getFormulae, setFormula, getFormula
, fmapNSGraph
, traverseNSGraph
, LDGraph(..), Label (..), Arc(..)
, arc, Selector
, resRdfRDF
, resRdfDescription
, resRdfID
, resRdfAbout
, resRdfParseType
, resRdfResource
, resRdfLi
, resRdfNodeID
, resRdfDatatype
, resRdf1, resRdf2, resRdfn
, resRdfsResource
, resRdfsClass
, resRdfsLiteral
, resRdfsDatatype
, resRdfXMLLiteral
, resRdfProperty
, resRdfsRange
, resRdfsDomain
, resRdfType
, resRdfsSubClassOf
, resRdfsSubPropertyOf
, resRdfsLabel
, resRdfsComment
, resRdfsContainer
, resRdfBag
, resRdfSeq
, resRdfAlt
, resRdfsContainerMembershipProperty
, resRdfsMember
, resRdfList
, resRdfFirst
, resRdfRest
, resRdfNil
, resRdfStatement
, resRdfSubject
, resRdfPredicate
, resRdfObject
, resRdfsSeeAlso
, resRdfsIsDefinedBy
, resRdfValue
, resOwlSameAs
, resRdfdGeneralRestriction
, resRdfdOnProperties, resRdfdConstraint, resRdfdMaxCardinality
, resLogImplies
, grMatchMap, grEq
, mapnode, maplist
)
where
import Swish.Namespace
( getNamespaceTuple
, getScopedNameURI
, ScopedName
, getScopeLocal, getScopeNamespace
, getQName
, makeQNameScopedName
, makeURIScopedName
, nullScopedName
)
import Swish.RDF.Vocabulary (LanguageTag)
import Swish.RDF.Vocabulary (fromLangTag, xsdBoolean, xsdDate, xsdDateTime, xsdDecimal, xsdDouble, xsdFloat, xsdInteger
, rdfType, rdfList, rdfFirst, rdfRest, rdfNil
, rdfsMember, rdfdGeneralRestriction, rdfdOnProperties, rdfdConstraint, rdfdMaxCardinality
, rdfsSeeAlso, rdfValue, rdfsLabel, rdfsComment, rdfProperty
, rdfsSubPropertyOf, rdfsSubClassOf, rdfsClass, rdfsLiteral
, rdfsDatatype, rdfXMLLiteral, rdfsRange, rdfsDomain, rdfsContainer
, rdfBag, rdfSeq, rdfAlt
, rdfsContainerMembershipProperty, rdfsIsDefinedBy
, rdfsResource, rdfStatement, rdfSubject, rdfPredicate, rdfObject
, rdfRDF, rdfDescription, rdfID, rdfAbout, rdfParseType
, rdfResource, rdfLi, rdfNodeID, rdfDatatype, rdfXMLLiteral
, rdf1, rdf2, rdfn
, owlSameAs, logImplies, namespaceRDF
)
import Swish.GraphClass (LDGraph(..), Label (..), Arc(..), ArcSet, Selector)
import Swish.GraphClass (arc, arcLabels, getComponents)
import Swish.GraphMatch (LabelMap, ScopedLabel(..))
import Swish.GraphMatch (graphMatch)
import Swish.QName (QName, getLName)
#if (!defined(__GLASGOW_HASKELL__)) || (__GLASGOW_HASKELL__ < 710)
import Control.Applicative (Applicative(pure), (<$>), (<*>))
import Data.Monoid (Monoid(..))
#endif
import Control.Arrow ((***))
import Network.URI (URI)
import Data.Maybe (mapMaybe)
import Data.Char (ord, isDigit)
import Data.Hashable (hashWithSalt)
import Data.List (intersect, union, foldl')
import Data.Word (Word32)
import Data.String (IsString(..))
#if MIN_VERSION_time(1,5,0)
import Data.Time (UTCTime, Day, ParseTime, parseTimeM, formatTime, defaultTimeLocale)
#else
import Data.Time (UTCTime, Day, ParseTime, parseTime, formatTime)
import System.Locale (defaultTimeLocale)
#endif
#if !(MIN_VERSION_base(4, 11, 0))
import Data.Semigroup
#endif
import Text.Printf
import qualified Data.Map as M
import qualified Data.Set as S
import qualified Data.Text as T
import qualified Data.Text.Read as T
import qualified Data.Traversable as Traversable
data RDFLabel =
Res ScopedName
| Lit T.Text
| LangLit T.Text LanguageTag
| TypedLit T.Text ScopedName
| Blank String
| Var String
| NoNode
instance Eq RDFLabel where
Res ScopedName
q1 == :: RDFLabel -> RDFLabel -> Bool
== Res ScopedName
q2 = ScopedName
q1 forall a. Eq a => a -> a -> Bool
== ScopedName
q2
Blank [Char]
b1 == Blank [Char]
b2 = [Char]
b1 forall a. Eq a => a -> a -> Bool
== [Char]
b2
Var [Char]
v1 == Var [Char]
v2 = [Char]
v1 forall a. Eq a => a -> a -> Bool
== [Char]
v2
Lit Text
s1 == Lit Text
s2 = Text
s1 forall a. Eq a => a -> a -> Bool
== Text
s2
LangLit Text
s1 LanguageTag
l1 == LangLit Text
s2 LanguageTag
l2 = Text
s1 forall a. Eq a => a -> a -> Bool
== Text
s2 Bool -> Bool -> Bool
&& LanguageTag
l1 forall a. Eq a => a -> a -> Bool
== LanguageTag
l2
TypedLit Text
s1 ScopedName
t1 == TypedLit Text
s2 ScopedName
t2 = Text
s1 forall a. Eq a => a -> a -> Bool
== Text
s2 Bool -> Bool -> Bool
&& ScopedName
t1 forall a. Eq a => a -> a -> Bool
== ScopedName
t2
RDFLabel
_ == RDFLabel
_ = Bool
False
instance Show RDFLabel where
show :: RDFLabel -> [Char]
show (Res ScopedName
sn) = forall a. Show a => a -> [Char]
show ScopedName
sn
show (Lit Text
st) = Text -> [Char]
quote1Str Text
st
show (LangLit Text
st LanguageTag
lang) = Text -> [Char]
quote1Str Text
st forall a. [a] -> [a] -> [a]
++ [Char]
"@" forall a. [a] -> [a] -> [a]
++ Text -> [Char]
T.unpack (LanguageTag -> Text
fromLangTag LanguageTag
lang)
show (TypedLit Text
st ScopedName
dtype)
| ScopedName
dtype forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [ScopedName
xsdBoolean, ScopedName
xsdDouble, ScopedName
xsdDecimal, ScopedName
xsdInteger] = Text -> [Char]
T.unpack Text
st
| Bool
otherwise = Text -> [Char]
quote1Str Text
st forall a. [a] -> [a] -> [a]
++ [Char]
"^^" forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> [Char]
show ScopedName
dtype
show (Blank [Char]
ln) = [Char]
"_:" forall a. [a] -> [a] -> [a]
++ [Char]
ln
show (Var [Char]
ln) = Char
'?' forall a. a -> [a] -> [a]
: [Char]
ln
show RDFLabel
NoNode = [Char]
"<NoNode>"
instance Ord RDFLabel where
compare :: RDFLabel -> RDFLabel -> Ordering
compare (Res ScopedName
sn1) (Res ScopedName
sn2) = forall a. Ord a => a -> a -> Ordering
compare ScopedName
sn1 ScopedName
sn2
compare (Res ScopedName
_) RDFLabel
_ = Ordering
LT
compare RDFLabel
_ (Res ScopedName
_) = Ordering
GT
compare (Lit Text
s1) (Lit Text
s2) = forall a. Ord a => a -> a -> Ordering
compare Text
s1 Text
s2
compare (Lit Text
_) RDFLabel
_ = Ordering
LT
compare RDFLabel
_ (Lit Text
_) = Ordering
GT
compare (LangLit Text
s1 LanguageTag
l1) (LangLit Text
s2 LanguageTag
l2) = forall a. Ord a => a -> a -> Ordering
compare (Text
s1,LanguageTag
l1) (Text
s2,LanguageTag
l2)
compare (LangLit Text
_ LanguageTag
_) RDFLabel
_ = Ordering
LT
compare RDFLabel
_ (LangLit Text
_ LanguageTag
_) = Ordering
GT
compare (TypedLit Text
s1 ScopedName
t1) (TypedLit Text
s2 ScopedName
t2) = forall a. Ord a => a -> a -> Ordering
compare (Text
s1,ScopedName
t1) (Text
s2,ScopedName
t2)
compare (TypedLit Text
_ ScopedName
_) RDFLabel
_ = Ordering
LT
compare RDFLabel
_ (TypedLit Text
_ ScopedName
_) = Ordering
GT
compare (Blank [Char]
ln1) (Blank [Char]
ln2) = forall a. Ord a => a -> a -> Ordering
compare [Char]
ln1 [Char]
ln2
compare (Blank [Char]
_) RDFLabel
_ = Ordering
LT
compare RDFLabel
_ (Blank [Char]
_) = Ordering
GT
compare (Var [Char]
ln1) (Var [Char]
ln2) = forall a. Ord a => a -> a -> Ordering
compare [Char]
ln1 [Char]
ln2
compare (Var [Char]
_) RDFLabel
NoNode = Ordering
LT
compare RDFLabel
_ (Var [Char]
_) = Ordering
GT
compare RDFLabel
NoNode RDFLabel
NoNode = Ordering
EQ
instance Label RDFLabel where
labelIsVar :: RDFLabel -> Bool
labelIsVar (Blank [Char]
_) = Bool
True
labelIsVar (Var [Char]
_) = Bool
True
labelIsVar RDFLabel
_ = Bool
False
getLocal :: RDFLabel -> [Char]
getLocal (Blank [Char]
loc) = [Char]
loc
getLocal (Var [Char]
loc) = Char
'?'forall a. a -> [a] -> [a]
:[Char]
loc
getLocal (Res ScopedName
sn) = [Char]
"Res_" forall a. [a] -> [a] -> [a]
++ (Text -> [Char]
T.unpack forall b c a. (b -> c) -> (a -> b) -> a -> c
. LName -> Text
getLName forall b c a. (b -> c) -> (a -> b) -> a -> c
. ScopedName -> LName
getScopeLocal) ScopedName
sn
getLocal RDFLabel
NoNode = [Char]
"None"
getLocal RDFLabel
_ = [Char]
"Lit_"
makeLabel :: [Char] -> RDFLabel
makeLabel (Char
'?':[Char]
loc) = [Char] -> RDFLabel
Var [Char]
loc
makeLabel [Char]
loc = [Char] -> RDFLabel
Blank [Char]
loc
labelHash :: Int -> RDFLabel -> Int
labelHash Int
seed RDFLabel
lb = forall a. Hashable a => Int -> a -> Int
hashWithSalt Int
seed (RDFLabel -> [Char]
showCanon RDFLabel
lb)
instance IsString RDFLabel where
fromString :: [Char] -> RDFLabel
fromString = Text -> RDFLabel
Lit forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> Text
T.pack
class ToRDFLabel a where
toRDFLabel :: a -> RDFLabel
class FromRDFLabel a where
fromRDFLabel :: RDFLabel -> Maybe a
instance ToRDFLabel RDFLabel where
toRDFLabel :: RDFLabel -> RDFLabel
toRDFLabel = forall a. a -> a
id
instance FromRDFLabel RDFLabel where
fromRDFLabel :: RDFLabel -> Maybe RDFLabel
fromRDFLabel = forall a. a -> Maybe a
Just
maybeReadStr :: (Read a) => T.Text -> Maybe a
maybeReadStr :: forall a. Read a => Text -> Maybe a
maybeReadStr Text
txt = case forall a. Read a => ReadS a
reads (Text -> [Char]
T.unpack Text
txt) of
[(a
val, [Char]
"")] -> forall a. a -> Maybe a
Just a
val
[(a, [Char])]
_ -> forall a. Maybe a
Nothing
maybeRead :: T.Reader a -> T.Text -> Maybe a
maybeRead :: forall a. Reader a -> Text -> Maybe a
maybeRead Reader a
rdr Text
inTxt =
case Reader a
rdr Text
inTxt of
Right (a
val, Text
"") -> forall a. a -> Maybe a
Just a
val
Either [Char] (a, Text)
_ -> forall a. Maybe a
Nothing
fLabel :: (T.Text -> Maybe a) -> ScopedName -> RDFLabel -> Maybe a
fLabel :: forall a. (Text -> Maybe a) -> ScopedName -> RDFLabel -> Maybe a
fLabel Text -> Maybe a
conv ScopedName
dtype (TypedLit Text
xs ScopedName
dt) | ScopedName
dt forall a. Eq a => a -> a -> Bool
== ScopedName
dtype = Text -> Maybe a
conv Text
xs
| Bool
otherwise = forall a. Maybe a
Nothing
fLabel Text -> Maybe a
_ ScopedName
_ RDFLabel
_ = forall a. Maybe a
Nothing
tLabel :: (Show a) => ScopedName -> (String -> T.Text) -> a -> RDFLabel
tLabel :: forall a. Show a => ScopedName -> ([Char] -> Text) -> a -> RDFLabel
tLabel ScopedName
dtype [Char] -> Text
conv = forall a b c. (a -> b -> c) -> b -> a -> c
flip Text -> ScopedName -> RDFLabel
TypedLit ScopedName
dtype forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> Text
conv forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> [Char]
show
instance ToRDFLabel Char where
toRDFLabel :: Char -> RDFLabel
toRDFLabel = Text -> RDFLabel
Lit forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Text
T.singleton
instance FromRDFLabel Char where
fromRDFLabel :: RDFLabel -> Maybe Char
fromRDFLabel (Lit Text
cs) | Text -> Int -> Ordering
T.compareLength Text
cs Int
1 forall a. Eq a => a -> a -> Bool
== Ordering
EQ = forall a. a -> Maybe a
Just (Text -> Char
T.head Text
cs)
| Bool
otherwise = forall a. Maybe a
Nothing
fromRDFLabel RDFLabel
_ = forall a. Maybe a
Nothing
instance ToRDFLabel String where
toRDFLabel :: [Char] -> RDFLabel
toRDFLabel = Text -> RDFLabel
Lit forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> Text
T.pack
instance FromRDFLabel String where
fromRDFLabel :: RDFLabel -> Maybe [Char]
fromRDFLabel (Lit Text
xs) = forall a. a -> Maybe a
Just (Text -> [Char]
T.unpack Text
xs)
fromRDFLabel RDFLabel
_ = forall a. Maybe a
Nothing
textToBool :: T.Text -> Maybe Bool
textToBool :: Text -> Maybe Bool
textToBool Text
s | Text
s forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Text
"1", Text
"true"] = forall a. a -> Maybe a
Just Bool
True
| Text
s forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Text
"0", Text
"false"] = forall a. a -> Maybe a
Just Bool
False
| Bool
otherwise = forall a. Maybe a
Nothing
instance ToRDFLabel Bool where
toRDFLabel :: Bool -> RDFLabel
toRDFLabel Bool
b = Text -> ScopedName -> RDFLabel
TypedLit (if Bool
b then Text
"true" else Text
"false") ScopedName
xsdBoolean
instance FromRDFLabel Bool where
fromRDFLabel :: RDFLabel -> Maybe Bool
fromRDFLabel = forall a. (Text -> Maybe a) -> ScopedName -> RDFLabel -> Maybe a
fLabel Text -> Maybe Bool
textToBool ScopedName
xsdBoolean
fromRealFloat :: (RealFloat a, PrintfArg a) => ScopedName -> a -> RDFLabel
fromRealFloat :: forall a. (RealFloat a, PrintfArg a) => ScopedName -> a -> RDFLabel
fromRealFloat ScopedName
dtype a
f | forall a. RealFloat a => a -> Bool
isNaN a
f = Text -> RDFLabel
toL Text
"NaN"
| forall a. RealFloat a => a -> Bool
isInfinite a
f = Text -> RDFLabel
toL forall a b. (a -> b) -> a -> b
$ if a
f forall a. Ord a => a -> a -> Bool
> a
0.0 then Text
"INF" else Text
"-INF"
| Bool
otherwise = Text -> RDFLabel
toL forall a b. (a -> b) -> a -> b
$ [Char] -> Text
T.pack forall a b. (a -> b) -> a -> b
$ forall r. PrintfType r => [Char] -> r
printf [Char]
"%E" a
f
where
toL :: Text -> RDFLabel
toL = forall a b c. (a -> b -> c) -> b -> a -> c
flip Text -> ScopedName -> RDFLabel
TypedLit ScopedName
dtype
textToRealFloat :: (RealFloat a, Read a) => (a -> Maybe a) -> T.Text -> Maybe a
textToRealFloat :: forall a.
(RealFloat a, Read a) =>
(a -> Maybe a) -> Text -> Maybe a
textToRealFloat a -> Maybe a
conv = Text -> Maybe a
rconv
where
rconv :: Text -> Maybe a
rconv Text
"NaN" = forall a. a -> Maybe a
Just (a
0.0 forall a. Fractional a => a -> a -> a
/ a
0.0)
rconv Text
"INF" = forall a. a -> Maybe a
Just (a
1.0 forall a. Fractional a => a -> a -> a
/ a
0.0)
rconv Text
"-INF" = forall a. a -> Maybe a
Just ((-a
1.0) forall a. Fractional a => a -> a -> a
/ a
0.0)
rconv Text
ival
| Text -> Bool
T.null Text
ival = forall a. Maybe a
Nothing
| Bool
otherwise = case forall a. Read a => Text -> Maybe a
maybeReadStr Text
ival of
Just a
val -> a -> Maybe a
conv a
val
Maybe a
_ -> if Text -> Char
T.last Text
ival forall a. Eq a => a -> a -> Bool
== Char
'.'
then forall a. Read a => Text -> Maybe a
maybeReadStr (Text -> Char -> Text
T.snoc Text
ival Char
'0') forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= a -> Maybe a
conv
else forall a. Maybe a
Nothing
textToFloat :: T.Text -> Maybe Float
textToFloat :: Text -> Maybe Float
textToFloat =
let
conv :: a -> Maybe a
conv a
f | forall a. RealFloat a => a -> Bool
isNaN a
f Bool -> Bool -> Bool
|| forall a. RealFloat a => a -> Bool
isInfinite a
f = forall a. Maybe a
Nothing
| Bool
otherwise = forall a. a -> Maybe a
Just a
f
in forall a.
(RealFloat a, Read a) =>
(a -> Maybe a) -> Text -> Maybe a
textToRealFloat forall {a}. RealFloat a => a -> Maybe a
conv
textToDouble :: T.Text -> Maybe Double
textToDouble :: Text -> Maybe Double
textToDouble = forall a.
(RealFloat a, Read a) =>
(a -> Maybe a) -> Text -> Maybe a
textToRealFloat forall a. a -> Maybe a
Just
instance ToRDFLabel Float where
toRDFLabel :: Float -> RDFLabel
toRDFLabel = forall a. (RealFloat a, PrintfArg a) => ScopedName -> a -> RDFLabel
fromRealFloat ScopedName
xsdFloat
instance FromRDFLabel Float where
fromRDFLabel :: RDFLabel -> Maybe Float
fromRDFLabel = forall a. (Text -> Maybe a) -> ScopedName -> RDFLabel -> Maybe a
fLabel Text -> Maybe Float
textToFloat ScopedName
xsdFloat
instance ToRDFLabel Double where
toRDFLabel :: Double -> RDFLabel
toRDFLabel = forall a. (RealFloat a, PrintfArg a) => ScopedName -> a -> RDFLabel
fromRealFloat ScopedName
xsdDouble
instance FromRDFLabel Double where
fromRDFLabel :: RDFLabel -> Maybe Double
fromRDFLabel = forall a. (Text -> Maybe a) -> ScopedName -> RDFLabel -> Maybe a
fLabel Text -> Maybe Double
textToDouble ScopedName
xsdDouble
instance ToRDFLabel Int where
toRDFLabel :: Int -> RDFLabel
toRDFLabel = forall a. Show a => ScopedName -> ([Char] -> Text) -> a -> RDFLabel
tLabel ScopedName
xsdInteger [Char] -> Text
T.pack
textToInt :: T.Text -> Maybe Int
textToInt :: Text -> Maybe Int
textToInt Text
s =
let conv :: Integer -> Maybe Int
conv :: Integer -> Maybe Int
conv Integer
i =
let lb :: Integer
lb = forall a b. (Integral a, Num b) => a -> b
fromIntegral (forall a. Bounded a => a
minBound :: Int)
ub :: Integer
ub = forall a b. (Integral a, Num b) => a -> b
fromIntegral (forall a. Bounded a => a
maxBound :: Int)
in if (Integer
i forall a. Ord a => a -> a -> Bool
>= Integer
lb) Bool -> Bool -> Bool
&& (Integer
i forall a. Ord a => a -> a -> Bool
<= Integer
ub) then forall a. a -> Maybe a
Just (forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
i) else forall a. Maybe a
Nothing
in forall a. Reader a -> Text -> Maybe a
maybeRead (forall a. Num a => Reader a -> Reader a
T.signed forall a. Integral a => Reader a
T.decimal) Text
s forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Integer -> Maybe Int
conv
instance FromRDFLabel Int where
fromRDFLabel :: RDFLabel -> Maybe Int
fromRDFLabel = forall a. (Text -> Maybe a) -> ScopedName -> RDFLabel -> Maybe a
fLabel Text -> Maybe Int
textToInt ScopedName
xsdInteger
instance ToRDFLabel Integer where
toRDFLabel :: Integer -> RDFLabel
toRDFLabel = forall a. Show a => ScopedName -> ([Char] -> Text) -> a -> RDFLabel
tLabel ScopedName
xsdInteger [Char] -> Text
T.pack
instance FromRDFLabel Integer where
fromRDFLabel :: RDFLabel -> Maybe Integer
fromRDFLabel = forall a. (Text -> Maybe a) -> ScopedName -> RDFLabel -> Maybe a
fLabel (forall a. Reader a -> Text -> Maybe a
maybeRead (forall a. Num a => Reader a -> Reader a
T.signed forall a. Integral a => Reader a
T.decimal)) ScopedName
xsdInteger
fromUTCFormat :: UTCTime -> String
fromUTCFormat :: UTCTime -> [Char]
fromUTCFormat = forall t. FormatTime t => TimeLocale -> [Char] -> t -> [Char]
formatTime TimeLocale
defaultTimeLocale [Char]
"%FT%T%QZ"
fromDayFormat :: Day -> String
fromDayFormat :: Day -> [Char]
fromDayFormat = forall t. FormatTime t => TimeLocale -> [Char] -> t -> [Char]
formatTime TimeLocale
defaultTimeLocale [Char]
"%FZ"
toTimeFormat :: (ParseTime a) => String -> String -> Maybe a
toTimeFormat :: forall a. ParseTime a => [Char] -> [Char] -> Maybe a
toTimeFormat [Char]
fmt [Char]
inVal =
let fmtHHMM :: [Char]
fmtHHMM = [Char]
fmt forall a. [a] -> [a] -> [a]
++ [Char]
"%z"
fmtZ :: [Char]
fmtZ = [Char]
fmt forall a. [a] -> [a] -> [a]
++ [Char]
"Z"
#if MIN_VERSION_time(1,5,0)
pt :: [Char] -> m t
pt [Char]
f = forall (m :: * -> *) t.
(MonadFail m, ParseTime t) =>
Bool -> TimeLocale -> [Char] -> [Char] -> m t
parseTimeM Bool
True TimeLocale
defaultTimeLocale [Char]
f [Char]
inVal
#else
pt f = parseTime defaultTimeLocale f inVal
#endif
in case forall {m :: * -> *} {t}.
(MonadFail m, ParseTime t) =>
[Char] -> m t
pt [Char]
fmtHHMM of
o :: Maybe a
o@(Just a
_) -> Maybe a
o
Maybe a
_ -> case forall {m :: * -> *} {t}.
(MonadFail m, ParseTime t) =>
[Char] -> m t
pt [Char]
fmtZ of
o :: Maybe a
o@(Just a
_) -> Maybe a
o
Maybe a
_ -> forall {m :: * -> *} {t}.
(MonadFail m, ParseTime t) =>
[Char] -> m t
pt [Char]
fmt
toUTCFormat :: T.Text -> Maybe UTCTime
toUTCFormat :: Text -> Maybe UTCTime
toUTCFormat = forall a. ParseTime a => [Char] -> [Char] -> Maybe a
toTimeFormat [Char]
"%FT%T%Q" forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> [Char]
T.unpack
toDayFormat :: T.Text -> Maybe Day
toDayFormat :: Text -> Maybe Day
toDayFormat = forall a. ParseTime a => [Char] -> [Char] -> Maybe a
toTimeFormat [Char]
"%F" forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> [Char]
T.unpack
instance ToRDFLabel UTCTime where
toRDFLabel :: UTCTime -> RDFLabel
toRDFLabel = forall a b c. (a -> b -> c) -> b -> a -> c
flip Text -> ScopedName -> RDFLabel
TypedLit ScopedName
xsdDateTime forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> Text
T.pack forall b c a. (b -> c) -> (a -> b) -> a -> c
. UTCTime -> [Char]
fromUTCFormat
instance FromRDFLabel UTCTime where
fromRDFLabel :: RDFLabel -> Maybe UTCTime
fromRDFLabel = forall a. (Text -> Maybe a) -> ScopedName -> RDFLabel -> Maybe a
fLabel Text -> Maybe UTCTime
toUTCFormat ScopedName
xsdDateTime
instance ToRDFLabel Day where
toRDFLabel :: Day -> RDFLabel
toRDFLabel = forall a b c. (a -> b -> c) -> b -> a -> c
flip Text -> ScopedName -> RDFLabel
TypedLit ScopedName
xsdDate forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> Text
T.pack forall b c a. (b -> c) -> (a -> b) -> a -> c
. Day -> [Char]
fromDayFormat
instance FromRDFLabel Day where
fromRDFLabel :: RDFLabel -> Maybe Day
fromRDFLabel = forall a. (Text -> Maybe a) -> ScopedName -> RDFLabel -> Maybe a
fLabel Text -> Maybe Day
toDayFormat ScopedName
xsdDate
instance ToRDFLabel ScopedName where
toRDFLabel :: ScopedName -> RDFLabel
toRDFLabel = ScopedName -> RDFLabel
Res
instance FromRDFLabel ScopedName where
fromRDFLabel :: RDFLabel -> Maybe ScopedName
fromRDFLabel (Res ScopedName
sn) = forall a. a -> Maybe a
Just ScopedName
sn
fromRDFLabel RDFLabel
_ = forall a. Maybe a
Nothing
instance ToRDFLabel QName where
toRDFLabel :: QName -> RDFLabel
toRDFLabel = ScopedName -> RDFLabel
Res forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe Text -> QName -> ScopedName
makeQNameScopedName forall a. Maybe a
Nothing
instance FromRDFLabel QName where
fromRDFLabel :: RDFLabel -> Maybe QName
fromRDFLabel (Res ScopedName
sn) = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ ScopedName -> QName
getQName ScopedName
sn
fromRDFLabel RDFLabel
_ = forall a. Maybe a
Nothing
instance ToRDFLabel URI where
toRDFLabel :: URI -> RDFLabel
toRDFLabel = ScopedName -> RDFLabel
Res forall b c a. (b -> c) -> (a -> b) -> a -> c
. URI -> ScopedName
makeURIScopedName
instance FromRDFLabel URI where
fromRDFLabel :: RDFLabel -> Maybe URI
fromRDFLabel (Res ScopedName
sn) = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ ScopedName -> URI
getScopedNameURI ScopedName
sn
fromRDFLabel RDFLabel
_ = forall a. Maybe a
Nothing
showCanon :: RDFLabel -> String
showCanon :: RDFLabel -> [Char]
showCanon (Res ScopedName
sn) = [Char]
"<" forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> [Char]
show (ScopedName -> URI
getScopedNameURI ScopedName
sn) forall a. [a] -> [a] -> [a]
++ [Char]
">"
showCanon (Lit Text
st) = forall a. Show a => a -> [Char]
show Text
st
showCanon (LangLit Text
st LanguageTag
lang) = Text -> [Char]
quote1Str Text
st forall a. [a] -> [a] -> [a]
++ [Char]
"@" forall a. [a] -> [a] -> [a]
++ Text -> [Char]
T.unpack (LanguageTag -> Text
fromLangTag LanguageTag
lang)
showCanon (TypedLit Text
st ScopedName
dt) = Text -> [Char]
quote1Str Text
st forall a. [a] -> [a] -> [a]
++ [Char]
"^^" forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> [Char]
show (ScopedName -> URI
getScopedNameURI ScopedName
dt)
showCanon RDFLabel
s = forall a. Show a => a -> [Char]
show RDFLabel
s
processChar ::
Char
-> (T.Text, Bool)
processChar :: Char -> (Text, Bool)
processChar Char
'"' = (Text
"\\\"", Bool
True)
processChar Char
'\\' = (Text
"\\\\", Bool
True)
processChar Char
'\n' = (Text
"\\n", Bool
True)
processChar Char
'\r' = (Text
"\\r", Bool
True)
processChar Char
'\t' = (Text
"\\t", Bool
True)
processChar Char
'\b' = (Text
"\\b", Bool
True)
processChar Char
'\f' = (Text
"\\u000C", Bool
True)
processChar Char
c =
let nc :: Int
nc = Char -> Int
ord Char
c
four :: Text
four = Text -> Text -> Text
T.append Text
"\\u" forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> Text
T.pack forall a b. (a -> b) -> a -> b
$ forall r. PrintfType r => [Char] -> r
printf [Char]
"%04X" Int
nc
eight :: Text
eight = Text -> Text -> Text
T.append Text
"\\U" forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> Text
T.pack forall a b. (a -> b) -> a -> b
$ forall r. PrintfType r => [Char] -> r
printf [Char]
"%08X" Int
nc
in if Int
nc forall a. Ord a => a -> a -> Bool
< Int
0x20
then (Text
four, Bool
True)
else if Int
nc forall a. Ord a => a -> a -> Bool
< Int
0x7f
then (Char -> Text
T.singleton Char
c, Bool
False)
else if Int
nc forall a. Ord a => a -> a -> Bool
< Int
0x10000
then (Text
four, Bool
True)
else (Text
eight, Bool
True)
convertChar :: Char -> T.Text
convertChar :: Char -> Text
convertChar = forall a b. (a, b) -> a
fst forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> (Text, Bool)
processChar
quoteT :: Bool -> T.Text -> T.Text
quoteT :: Bool -> Text -> Text
quoteT Bool
True Text
txt =
let go :: (Text -> t) -> Text -> t
go Text -> t
dl Text
x =
case Text -> Maybe (Char, Text)
T.uncons Text
x of
Just (Char
c, Text
xs) -> (Text -> t) -> Text -> t
go (Text -> t
dl forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text -> Text
T.append (Char -> Text
convertChar Char
c)) Text
xs
Maybe (Char, Text)
_ -> Text -> t
dl Text
T.empty
in forall {t}. (Text -> t) -> Text -> t
go (Text -> Text -> Text
T.append Text
T.empty) Text
txt
quoteT Bool
_ Text
txt =
let go :: (Text -> t) -> Text -> t
go Text -> t
dl Text
x =
case Text -> Maybe (Char, Text)
T.uncons Text
x of
Just (Char
'"', Text
xs) -> (Text -> t) -> Text -> t
go1 Text -> t
dl Text
xs
Just (Char
'\n', Text
xs) -> (Text -> t) -> Text -> t
go (Text -> t
dl forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Text -> Text
T.cons Char
'\n') Text
xs
Just (Char
c, Text
xs) -> (Text -> t) -> Text -> t
go (Text -> t
dl forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text -> Text
T.append (Char -> Text
convertChar Char
c)) Text
xs
Maybe (Char, Text)
_ -> Text -> t
dl Text
T.empty
go1 :: (Text -> t) -> Text -> t
go1 Text -> t
dl Text
x =
case Text -> Maybe (Char, Text)
T.uncons Text
x of
Just (Char
'"', Text
xs) -> (Text -> t) -> Text -> t
go2 Text -> t
dl Text
xs
Just (Char
'\n', Text
xs) -> (Text -> t) -> Text -> t
go (Text -> t
dl forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text -> Text
T.append Text
"\"\n") Text
xs
Just (Char
'\\', Text
xs) -> (Text -> t) -> Text -> t
go (Text -> t
dl forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text -> Text
T.append Text
"\\\"\\\\") Text
xs
Just (Char
c, Text
xs) ->
let (Text
t, Bool
f) = Char -> (Text, Bool)
processChar Char
c
dl' :: Text -> Text
dl' = if Bool
f then Text -> Text -> Text
T.append Text
"\\\"" else Char -> Text -> Text
T.cons Char
'"'
in (Text -> t) -> Text -> t
go (Text -> t
dl forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
dl' forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text -> Text
T.append Text
t) Text
xs
Maybe (Char, Text)
_ -> Text -> t
dl Text
"\\\""
go2 :: (Text -> t) -> Text -> t
go2 Text -> t
dl Text
x =
case Text -> Maybe (Char, Text)
T.uncons Text
x of
Just (Char
'"', Text
xs) -> (Text -> t) -> Text -> t
go (Text -> t
dl forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text -> Text
T.append Text
"\\\"\\\"\\\"") Text
xs
Just (Char
'\n', Text
xs) -> (Text -> t) -> Text -> t
go (Text -> t
dl forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text -> Text
T.append Text
"\"\"\n") Text
xs
Just (Char
'\\', Text
xs) -> (Text -> t) -> Text -> t
go (Text -> t
dl forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text -> Text
T.append Text
"\\\"\\\"\\\\") Text
xs
Just (Char
c, Text
xs) ->
let (Text
t, Bool
f) = Char -> (Text, Bool)
processChar Char
c
dl' :: Text -> Text
dl' = Text -> Text -> Text
T.append (if Bool
f then Text
"\\\"\\\"" else Text
"\"\"")
in (Text -> t) -> Text -> t
go (Text -> t
dl forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
dl' forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text -> Text
T.append Text
t) Text
xs
Maybe (Char, Text)
_ -> Text -> t
dl Text
"\\\"\\\""
go0 :: (Text -> t) -> Text -> t
go0 Text -> t
dl Text
x =
case Text -> Maybe (Char, Text)
T.uncons Text
x of
Just (Char
'"', Text
xs) -> (Text -> t) -> Text -> t
go0 (Text -> t
dl forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text -> Text
T.append Text
"\\\"") Text
xs
Just (Char
'\n', Text
xs) -> forall {t}. (Text -> t) -> Text -> t
go (Text -> t
dl forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Text -> Text
T.cons Char
'\n') Text
xs
Just (Char
c, Text
xs) -> forall {t}. (Text -> t) -> Text -> t
go (Text -> t
dl forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text -> Text
T.append (Char -> Text
convertChar Char
c)) Text
xs
Maybe (Char, Text)
_ -> Text -> t
dl Text
T.empty
in forall {t}. (Text -> t) -> Text -> t
go0 (Text -> Text -> Text
T.append Text
T.empty) Text
txt
quote ::
Bool
-> String
-> String
quote :: Bool -> ShowS
quote Bool
f = Text -> [Char]
T.unpack forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> Text -> Text
quoteT Bool
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> Text
T.pack
quote1Str :: T.Text -> String
quote1Str :: Text -> [Char]
quote1Str Text
t = Char
'"' forall a. a -> [a] -> [a]
: Text -> [Char]
T.unpack (Bool -> Text -> Text
quoteT Bool
True Text
t) forall a. [a] -> [a] -> [a]
++ [Char]
"\""
resRdfType :: RDFLabel
resRdfType :: RDFLabel
resRdfType = ScopedName -> RDFLabel
Res ScopedName
rdfType
resRdfList :: RDFLabel
resRdfList :: RDFLabel
resRdfList = ScopedName -> RDFLabel
Res ScopedName
rdfList
resRdfFirst :: RDFLabel
resRdfFirst :: RDFLabel
resRdfFirst = ScopedName -> RDFLabel
Res ScopedName
rdfFirst
resRdfRest :: RDFLabel
resRdfRest :: RDFLabel
resRdfRest = ScopedName -> RDFLabel
Res ScopedName
rdfRest
resRdfNil :: RDFLabel
resRdfNil :: RDFLabel
resRdfNil = ScopedName -> RDFLabel
Res ScopedName
rdfNil
resRdfsMember :: RDFLabel
resRdfsMember :: RDFLabel
resRdfsMember = ScopedName -> RDFLabel
Res ScopedName
rdfsMember
resRdfdGeneralRestriction :: RDFLabel
resRdfdGeneralRestriction :: RDFLabel
resRdfdGeneralRestriction = ScopedName -> RDFLabel
Res ScopedName
rdfdGeneralRestriction
resRdfdOnProperties :: RDFLabel
resRdfdOnProperties :: RDFLabel
resRdfdOnProperties = ScopedName -> RDFLabel
Res ScopedName
rdfdOnProperties
resRdfdConstraint :: RDFLabel
resRdfdConstraint :: RDFLabel
resRdfdConstraint = ScopedName -> RDFLabel
Res ScopedName
rdfdConstraint
resRdfdMaxCardinality :: RDFLabel
resRdfdMaxCardinality :: RDFLabel
resRdfdMaxCardinality = ScopedName -> RDFLabel
Res ScopedName
rdfdMaxCardinality
resRdfsSeeAlso :: RDFLabel
resRdfsSeeAlso :: RDFLabel
resRdfsSeeAlso = ScopedName -> RDFLabel
Res ScopedName
rdfsSeeAlso
resRdfValue :: RDFLabel
resRdfValue :: RDFLabel
resRdfValue = ScopedName -> RDFLabel
Res ScopedName
rdfValue
resOwlSameAs :: RDFLabel
resOwlSameAs :: RDFLabel
resOwlSameAs = ScopedName -> RDFLabel
Res ScopedName
owlSameAs
resLogImplies :: RDFLabel
resLogImplies :: RDFLabel
resLogImplies = ScopedName -> RDFLabel
Res ScopedName
logImplies
resRdfsLabel :: RDFLabel
resRdfsLabel :: RDFLabel
resRdfsLabel = ScopedName -> RDFLabel
Res ScopedName
rdfsLabel
resRdfsComment :: RDFLabel
= ScopedName -> RDFLabel
Res ScopedName
rdfsComment
resRdfProperty :: RDFLabel
resRdfProperty :: RDFLabel
resRdfProperty = ScopedName -> RDFLabel
Res ScopedName
rdfProperty
resRdfsSubPropertyOf :: RDFLabel
resRdfsSubPropertyOf :: RDFLabel
resRdfsSubPropertyOf = ScopedName -> RDFLabel
Res ScopedName
rdfsSubPropertyOf
resRdfsSubClassOf :: RDFLabel
resRdfsSubClassOf :: RDFLabel
resRdfsSubClassOf = ScopedName -> RDFLabel
Res ScopedName
rdfsSubClassOf
resRdfsClass :: RDFLabel
resRdfsClass :: RDFLabel
resRdfsClass = ScopedName -> RDFLabel
Res ScopedName
rdfsClass
resRdfsLiteral :: RDFLabel
resRdfsLiteral :: RDFLabel
resRdfsLiteral = ScopedName -> RDFLabel
Res ScopedName
rdfsLiteral
resRdfsDatatype :: RDFLabel
resRdfsDatatype :: RDFLabel
resRdfsDatatype = ScopedName -> RDFLabel
Res ScopedName
rdfsDatatype
resRdfXMLLiteral :: RDFLabel
resRdfXMLLiteral :: RDFLabel
resRdfXMLLiteral = ScopedName -> RDFLabel
Res ScopedName
rdfXMLLiteral
resRdfsRange :: RDFLabel
resRdfsRange :: RDFLabel
resRdfsRange = ScopedName -> RDFLabel
Res ScopedName
rdfsRange
resRdfsDomain :: RDFLabel
resRdfsDomain :: RDFLabel
resRdfsDomain = ScopedName -> RDFLabel
Res ScopedName
rdfsDomain
resRdfsContainer :: RDFLabel
resRdfsContainer :: RDFLabel
resRdfsContainer = ScopedName -> RDFLabel
Res ScopedName
rdfsContainer
resRdfBag :: RDFLabel
resRdfBag :: RDFLabel
resRdfBag = ScopedName -> RDFLabel
Res ScopedName
rdfBag
resRdfSeq :: RDFLabel
resRdfSeq :: RDFLabel
resRdfSeq = ScopedName -> RDFLabel
Res ScopedName
rdfSeq
resRdfAlt :: RDFLabel
resRdfAlt :: RDFLabel
resRdfAlt = ScopedName -> RDFLabel
Res ScopedName
rdfAlt
resRdfsContainerMembershipProperty :: RDFLabel
resRdfsContainerMembershipProperty :: RDFLabel
resRdfsContainerMembershipProperty = ScopedName -> RDFLabel
Res ScopedName
rdfsContainerMembershipProperty
resRdfsIsDefinedBy :: RDFLabel
resRdfsIsDefinedBy :: RDFLabel
resRdfsIsDefinedBy = ScopedName -> RDFLabel
Res ScopedName
rdfsIsDefinedBy
resRdfsResource :: RDFLabel
resRdfsResource :: RDFLabel
resRdfsResource = ScopedName -> RDFLabel
Res ScopedName
rdfsResource
resRdfStatement :: RDFLabel
resRdfStatement :: RDFLabel
resRdfStatement = ScopedName -> RDFLabel
Res ScopedName
rdfStatement
resRdfSubject :: RDFLabel
resRdfSubject :: RDFLabel
resRdfSubject = ScopedName -> RDFLabel
Res ScopedName
rdfSubject
resRdfPredicate :: RDFLabel
resRdfPredicate :: RDFLabel
resRdfPredicate = ScopedName -> RDFLabel
Res ScopedName
rdfPredicate
resRdfObject :: RDFLabel
resRdfObject :: RDFLabel
resRdfObject = ScopedName -> RDFLabel
Res ScopedName
rdfObject
resRdfRDF :: RDFLabel
resRdfRDF :: RDFLabel
resRdfRDF = ScopedName -> RDFLabel
Res ScopedName
rdfRDF
resRdfDescription :: RDFLabel
resRdfDescription :: RDFLabel
resRdfDescription = ScopedName -> RDFLabel
Res ScopedName
rdfDescription
resRdfID :: RDFLabel
resRdfID :: RDFLabel
resRdfID = ScopedName -> RDFLabel
Res ScopedName
rdfID
resRdfAbout :: RDFLabel
resRdfAbout :: RDFLabel
resRdfAbout = ScopedName -> RDFLabel
Res ScopedName
rdfAbout
resRdfParseType :: RDFLabel
resRdfParseType :: RDFLabel
resRdfParseType = ScopedName -> RDFLabel
Res ScopedName
rdfParseType
resRdfResource :: RDFLabel
resRdfResource :: RDFLabel
resRdfResource = ScopedName -> RDFLabel
Res ScopedName
rdfResource
resRdfLi :: RDFLabel
resRdfLi :: RDFLabel
resRdfLi = ScopedName -> RDFLabel
Res ScopedName
rdfLi
resRdfNodeID :: RDFLabel
resRdfNodeID :: RDFLabel
resRdfNodeID = ScopedName -> RDFLabel
Res ScopedName
rdfNodeID
resRdfDatatype :: RDFLabel
resRdfDatatype :: RDFLabel
resRdfDatatype = ScopedName -> RDFLabel
Res ScopedName
rdfDatatype
resRdf1 :: RDFLabel
resRdf1 :: RDFLabel
resRdf1 = ScopedName -> RDFLabel
Res ScopedName
rdf1
resRdf2 :: RDFLabel
resRdf2 :: RDFLabel
resRdf2 = ScopedName -> RDFLabel
Res ScopedName
rdf2
resRdfn :: Word32 -> RDFLabel
resRdfn :: Word32 -> RDFLabel
resRdfn = ScopedName -> RDFLabel
Res forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word32 -> ScopedName
rdfn
isUri :: RDFLabel -> Bool
isUri :: RDFLabel -> Bool
isUri (Res ScopedName
_) = Bool
True
isUri RDFLabel
_ = Bool
False
isLiteral :: RDFLabel -> Bool
isLiteral :: RDFLabel -> Bool
isLiteral (Lit Text
_) = Bool
True
isLiteral (LangLit Text
_ LanguageTag
_) = Bool
True
isLiteral (TypedLit Text
_ ScopedName
_) = Bool
True
isLiteral RDFLabel
_ = Bool
False
isUntypedLiteral :: RDFLabel -> Bool
isUntypedLiteral :: RDFLabel -> Bool
isUntypedLiteral (Lit Text
_) = Bool
True
isUntypedLiteral (LangLit Text
_ LanguageTag
_) = Bool
True
isUntypedLiteral RDFLabel
_ = Bool
False
isTypedLiteral :: RDFLabel -> Bool
isTypedLiteral :: RDFLabel -> Bool
isTypedLiteral (TypedLit Text
_ ScopedName
_) = Bool
True
isTypedLiteral RDFLabel
_ = Bool
False
isXMLLiteral :: RDFLabel -> Bool
isXMLLiteral :: RDFLabel -> Bool
isXMLLiteral = ScopedName -> RDFLabel -> Bool
isDatatyped ScopedName
rdfXMLLiteral
isDatatyped :: ScopedName -> RDFLabel -> Bool
isDatatyped :: ScopedName -> RDFLabel -> Bool
isDatatyped ScopedName
d (TypedLit Text
_ ScopedName
dt) = ScopedName
d forall a. Eq a => a -> a -> Bool
== ScopedName
dt
isDatatyped ScopedName
_ RDFLabel
_ = Bool
False
isMemberProp :: RDFLabel -> Bool
isMemberProp :: RDFLabel -> Bool
isMemberProp (Res ScopedName
sn) =
ScopedName -> Namespace
getScopeNamespace ScopedName
sn forall a. Eq a => a -> a -> Bool
== Namespace
namespaceRDF Bool -> Bool -> Bool
&&
case Text -> Maybe (Char, Text)
T.uncons (LName -> Text
getLName (ScopedName -> LName
getScopeLocal ScopedName
sn)) of
Just (Char
'_', Text
t) -> (Char -> Bool) -> Text -> Bool
T.all Char -> Bool
isDigit Text
t
Maybe (Char, Text)
_ -> Bool
False
isMemberProp RDFLabel
_ = Bool
False
isBlank :: RDFLabel -> Bool
isBlank :: RDFLabel -> Bool
isBlank (Blank [Char]
_) = Bool
True
isBlank RDFLabel
_ = Bool
False
isQueryVar :: RDFLabel -> Bool
isQueryVar :: RDFLabel -> Bool
isQueryVar (Var [Char]
_) = Bool
True
isQueryVar RDFLabel
_ = Bool
False
getLiteralText :: RDFLabel -> T.Text
getLiteralText :: RDFLabel -> Text
getLiteralText (Lit Text
s) = Text
s
getLiteralText (LangLit Text
s LanguageTag
_) = Text
s
getLiteralText (TypedLit Text
s ScopedName
_) = Text
s
getLiteralText RDFLabel
_ = Text
""
getScopedName :: RDFLabel -> ScopedName
getScopedName :: RDFLabel -> ScopedName
getScopedName (Res ScopedName
sn) = ScopedName
sn
getScopedName RDFLabel
_ = ScopedName
nullScopedName
makeBlank :: RDFLabel -> RDFLabel
makeBlank :: RDFLabel -> RDFLabel
makeBlank (Var [Char]
loc) = [Char] -> RDFLabel
Blank [Char]
loc
makeBlank RDFLabel
lb = RDFLabel
lb
type RDFTriple = Arc RDFLabel
type RDFArcSet = ArcSet RDFLabel
toRDFTriple ::
(ToRDFLabel s, ToRDFLabel p, ToRDFLabel o)
=> s
-> p
-> o
-> RDFTriple
toRDFTriple :: forall s p o.
(ToRDFLabel s, ToRDFLabel p, ToRDFLabel o) =>
s -> p -> o -> RDFTriple
toRDFTriple s
s p
p o
o =
forall lb. lb -> lb -> lb -> Arc lb
Arc (forall a. ToRDFLabel a => a -> RDFLabel
toRDFLabel s
s) (forall a. ToRDFLabel a => a -> RDFLabel
toRDFLabel p
p) (forall a. ToRDFLabel a => a -> RDFLabel
toRDFLabel o
o)
fromRDFTriple ::
(FromRDFLabel s, FromRDFLabel p, FromRDFLabel o)
=> RDFTriple
-> Maybe (s, p, o)
fromRDFTriple :: forall s p o.
(FromRDFLabel s, FromRDFLabel p, FromRDFLabel o) =>
RDFTriple -> Maybe (s, p, o)
fromRDFTriple (Arc RDFLabel
s RDFLabel
p RDFLabel
o) =
(,,) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. FromRDFLabel a => RDFLabel -> Maybe a
fromRDFLabel RDFLabel
s forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. FromRDFLabel a => RDFLabel -> Maybe a
fromRDFLabel RDFLabel
p forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. FromRDFLabel a => RDFLabel -> Maybe a
fromRDFLabel RDFLabel
o
type NamespaceMap = M.Map (Maybe T.Text) URI
emptyNamespaceMap :: NamespaceMap
emptyNamespaceMap :: NamespaceMap
emptyNamespaceMap = forall k a. Map k a
M.empty
data LookupFormula lb gr = Formula
{ forall lb gr. LookupFormula lb gr -> lb
formLabel :: lb
, forall lb gr. LookupFormula lb gr -> gr
formGraph :: gr
}
instance (Eq lb, Eq gr) => Eq (LookupFormula lb gr) where
LookupFormula lb gr
f1 == :: LookupFormula lb gr -> LookupFormula lb gr -> Bool
== LookupFormula lb gr
f2 = forall lb gr. LookupFormula lb gr -> lb
formLabel LookupFormula lb gr
f1 forall a. Eq a => a -> a -> Bool
== forall lb gr. LookupFormula lb gr -> lb
formLabel LookupFormula lb gr
f2 Bool -> Bool -> Bool
&&
forall lb gr. LookupFormula lb gr -> gr
formGraph LookupFormula lb gr
f1 forall a. Eq a => a -> a -> Bool
== forall lb gr. LookupFormula lb gr -> gr
formGraph LookupFormula lb gr
f2
instance (Ord lb, Ord gr) => Ord (LookupFormula lb gr) where
(Formula lb
a1 gr
b1) compare :: LookupFormula lb gr -> LookupFormula lb gr -> Ordering
`compare` (Formula lb
a2 gr
b2) =
(lb
a1,gr
b1) forall a. Ord a => a -> a -> Ordering
`compare` (lb
a2,gr
b2)
type Formula lb = LookupFormula lb (NSGraph lb)
instance (Label lb) => Show (Formula lb)
where
show :: Formula lb -> [Char]
show (Formula lb
l NSGraph lb
g) = forall a. Show a => a -> [Char]
show lb
l forall a. [a] -> [a] -> [a]
++ [Char]
" :- { " forall a. [a] -> [a] -> [a]
++ forall lb. Label lb => [Char] -> NSGraph lb -> [Char]
showArcs [Char]
" " NSGraph lb
g forall a. [a] -> [a] -> [a]
++ [Char]
" }"
type FormulaMap lb = M.Map lb (NSGraph lb)
emptyFormulaMap :: FormulaMap RDFLabel
emptyFormulaMap :: FormulaMap RDFLabel
emptyFormulaMap = forall k a. Map k a
M.empty
fmapFormulaMap :: (Ord a) => (a -> a) -> FormulaMap a -> FormulaMap a
fmapFormulaMap :: forall a. Ord a => (a -> a) -> FormulaMap a -> FormulaMap a
fmapFormulaMap a -> a
f FormulaMap a
m = forall k a. Ord k => [(k, a)] -> Map k a
M.fromList forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map (a -> a
f forall (a :: * -> * -> *) b c b' c'.
Arrow a =>
a b c -> a b' c' -> a (b, b') (c, c')
*** forall lb. Ord lb => (lb -> lb) -> NSGraph lb -> NSGraph lb
fmapNSGraph a -> a
f) forall a b. (a -> b) -> a -> b
$ forall k a. Map k a -> [(k, a)]
M.assocs FormulaMap a
m
traverseFormulaMap ::
(Applicative f, Ord a)
=> (a -> f a) -> FormulaMap a -> f (FormulaMap a)
traverseFormulaMap :: forall (f :: * -> *) a.
(Applicative f, Ord a) =>
(a -> f a) -> FormulaMap a -> f (FormulaMap a)
traverseFormulaMap a -> f a
f = forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
Traversable.traverse (forall (f :: * -> *) a.
(Applicative f, Ord a) =>
(a -> f a) -> NSGraph a -> f (NSGraph a)
traverseFormula a -> f a
f)
traverseFormula ::
(Applicative f, Ord a)
=> (a -> f a) -> NSGraph a -> f (NSGraph a)
traverseFormula :: forall (f :: * -> *) a.
(Applicative f, Ord a) =>
(a -> f a) -> NSGraph a -> f (NSGraph a)
traverseFormula = forall (f :: * -> *) a.
(Applicative f, Ord a) =>
(a -> f a) -> NSGraph a -> f (NSGraph a)
traverseNSGraph
data NSGraph lb = NSGraph
{ forall lb. NSGraph lb -> NamespaceMap
namespaces :: NamespaceMap
, forall lb. NSGraph lb -> FormulaMap lb
formulae :: FormulaMap lb
, forall lb. NSGraph lb -> ArcSet lb
statements :: ArcSet lb
}
instance LDGraph NSGraph lb where
emptyGraph :: NSGraph lb
emptyGraph = forall lb. NamespaceMap -> FormulaMap lb -> ArcSet lb -> NSGraph lb
NSGraph NamespaceMap
emptyNamespaceMap forall k a. Map k a
M.empty forall a. Set a
S.empty
getArcs :: NSGraph lb -> ArcSet lb
getArcs = forall lb. NSGraph lb -> ArcSet lb
statements
setArcs :: NSGraph lb -> ArcSet lb -> NSGraph lb
setArcs NSGraph lb
g ArcSet lb
as = NSGraph lb
g { statements :: ArcSet lb
statements=ArcSet lb
as }
instance (Label lb) => Semigroup (NSGraph lb) where
<> :: NSGraph lb -> NSGraph lb -> NSGraph lb
(<>) = forall lb. Label lb => NSGraph lb -> NSGraph lb -> NSGraph lb
merge
instance (Label lb) => Monoid (NSGraph lb) where
mempty :: NSGraph lb
mempty = forall (lg :: * -> *) lb. LDGraph lg lb => lg lb
emptyGraph
#if !(MIN_VERSION_base(4, 11, 0))
mappend = (<>)
#endif
fmapNSGraph :: (Ord lb) => (lb -> lb) -> NSGraph lb -> NSGraph lb
fmapNSGraph :: forall lb. Ord lb => (lb -> lb) -> NSGraph lb -> NSGraph lb
fmapNSGraph lb -> lb
f (NSGraph NamespaceMap
ns FormulaMap lb
fml ArcSet lb
stmts) =
forall lb. NamespaceMap -> FormulaMap lb -> ArcSet lb -> NSGraph lb
NSGraph NamespaceMap
ns (forall a. Ord a => (a -> a) -> FormulaMap a -> FormulaMap a
fmapFormulaMap lb -> lb
f FormulaMap lb
fml) ((forall b a. Ord b => (a -> b) -> Set a -> Set b
S.map forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap lb -> lb
f) ArcSet lb
stmts)
traverseNSGraph ::
(Applicative f, Ord a)
=> (a -> f a) -> NSGraph a -> f (NSGraph a)
traverseNSGraph :: forall (f :: * -> *) a.
(Applicative f, Ord a) =>
(a -> f a) -> NSGraph a -> f (NSGraph a)
traverseNSGraph a -> f a
f (NSGraph NamespaceMap
ns FormulaMap a
fml ArcSet a
stmts) =
forall lb. NamespaceMap -> FormulaMap lb -> ArcSet lb -> NSGraph lb
NSGraph NamespaceMap
ns forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (f :: * -> *) a.
(Applicative f, Ord a) =>
(a -> f a) -> FormulaMap a -> f (FormulaMap a)
traverseFormulaMap a -> f a
f FormulaMap a
fml forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (forall (f :: * -> *) b a.
(Applicative f, Ord b) =>
(a -> f b) -> Set a -> f (Set b)
traverseSet forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
Traversable.traverse a -> f a
f) ArcSet a
stmts
traverseSet ::
(Applicative f, Ord b)
=> (a -> f b) -> S.Set a -> f (S.Set b)
traverseSet :: forall (f :: * -> *) b a.
(Applicative f, Ord b) =>
(a -> f b) -> Set a -> f (Set b)
traverseSet a -> f b
f = forall a b. (a -> b -> b) -> b -> Set a -> b
S.foldr a -> f (Set b) -> f (Set b)
cons (forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a. Set a
S.empty)
where
cons :: a -> f (Set b) -> f (Set b)
cons a
x f (Set b)
s = forall a. Ord a => a -> Set a -> Set a
S.insert forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
x forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> f (Set b)
s
instance (Label lb) => Eq (NSGraph lb) where
== :: NSGraph lb -> NSGraph lb -> Bool
(==) = forall lb. Label lb => NSGraph lb -> NSGraph lb -> Bool
grEq
instance (Label lb) => Ord (NSGraph lb) where
(NSGraph NamespaceMap
_ FormulaMap lb
fml1 ArcSet lb
stmts1) compare :: NSGraph lb -> NSGraph lb -> Ordering
`compare` (NSGraph NamespaceMap
_ FormulaMap lb
fml2 ArcSet lb
stmts2) =
(FormulaMap lb
fml1,ArcSet lb
stmts1) forall a. Ord a => a -> a -> Ordering
`compare` (FormulaMap lb
fml2,ArcSet lb
stmts2)
instance (Label lb) => Show (NSGraph lb) where
show :: NSGraph lb -> [Char]
show = forall lb. Label lb => [Char] -> NSGraph lb -> [Char]
grShow [Char]
""
showList :: [NSGraph lb] -> ShowS
showList = forall lb. Label lb => [Char] -> [NSGraph lb] -> ShowS
grShowList [Char]
""
getNamespaces :: NSGraph lb -> NamespaceMap
getNamespaces :: forall lb. NSGraph lb -> NamespaceMap
getNamespaces = forall lb. NSGraph lb -> NamespaceMap
namespaces
setNamespaces :: NamespaceMap -> NSGraph lb -> NSGraph lb
setNamespaces :: forall lb. NamespaceMap -> NSGraph lb -> NSGraph lb
setNamespaces NamespaceMap
ns NSGraph lb
g = NSGraph lb
g { namespaces :: NamespaceMap
namespaces=NamespaceMap
ns }
getFormulae :: NSGraph lb -> FormulaMap lb
getFormulae :: forall lb. NSGraph lb -> FormulaMap lb
getFormulae = forall lb. NSGraph lb -> FormulaMap lb
formulae
setFormulae :: FormulaMap lb -> NSGraph lb -> NSGraph lb
setFormulae :: forall lb. FormulaMap lb -> NSGraph lb -> NSGraph lb
setFormulae FormulaMap lb
fs NSGraph lb
g = NSGraph lb
g { formulae :: FormulaMap lb
formulae=FormulaMap lb
fs }
getFormula :: (Label lb) => NSGraph lb -> lb -> Maybe (NSGraph lb)
getFormula :: forall lb. Label lb => NSGraph lb -> lb -> Maybe (NSGraph lb)
getFormula NSGraph lb
g lb
l = forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup lb
l (forall lb. NSGraph lb -> FormulaMap lb
formulae NSGraph lb
g)
setFormula :: (Label lb) => Formula lb -> NSGraph lb -> NSGraph lb
setFormula :: forall lb. Label lb => Formula lb -> NSGraph lb -> NSGraph lb
setFormula (Formula lb
fn NSGraph lb
fg) NSGraph lb
g = NSGraph lb
g { formulae :: FormulaMap lb
formulae = forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert lb
fn NSGraph lb
fg (forall lb. NSGraph lb -> FormulaMap lb
formulae NSGraph lb
g) }
addArc :: (Label lb) => Arc lb -> NSGraph lb -> NSGraph lb
addArc :: forall lb. Label lb => Arc lb -> NSGraph lb -> NSGraph lb
addArc Arc lb
ar = forall (lg :: * -> *) lb.
LDGraph lg lb =>
(ArcSet lb -> ArcSet lb) -> lg lb -> lg lb
update (forall a. Ord a => a -> Set a -> Set a
S.insert Arc lb
ar)
grShowList :: (Label lb) => String -> [NSGraph lb] -> String -> String
grShowList :: forall lb. Label lb => [Char] -> [NSGraph lb] -> ShowS
grShowList [Char]
_ [] = [Char] -> ShowS
showString [Char]
"[no graphs]"
grShowList [Char]
p (NSGraph lb
g:[NSGraph lb]
gs) = Char -> ShowS
showChar Char
'[' forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> ShowS
showString (forall lb. Label lb => [Char] -> NSGraph lb -> [Char]
grShow [Char]
pp NSGraph lb
g) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall lb. Label lb => [NSGraph lb] -> ShowS
showl [NSGraph lb]
gs
where
showl :: [NSGraph lb] -> ShowS
showl [] = Char -> ShowS
showChar Char
']'
showl (NSGraph lb
h:[NSGraph lb]
hs) = [Char] -> ShowS
showString ([Char]
",\n " forall a. [a] -> [a] -> [a]
++ [Char]
p forall a. [a] -> [a] -> [a]
++ forall lb. Label lb => [Char] -> NSGraph lb -> [Char]
grShow [Char]
pp NSGraph lb
h) forall b c a. (b -> c) -> (a -> b) -> a -> c
. [NSGraph lb] -> ShowS
showl [NSGraph lb]
hs
pp :: [Char]
pp = Char
' 'forall a. a -> [a] -> [a]
:[Char]
p
grShow :: (Label lb) => String -> NSGraph lb -> String
grShow :: forall lb. Label lb => [Char] -> NSGraph lb -> [Char]
grShow [Char]
p NSGraph lb
g =
[Char]
"Graph, formulae: " forall a. [a] -> [a] -> [a]
++ [Char]
showForm forall a. [a] -> [a] -> [a]
++ [Char]
"\n" forall a. [a] -> [a] -> [a]
++
[Char]
p forall a. [a] -> [a] -> [a]
++ [Char]
"arcs: " forall a. [a] -> [a] -> [a]
++ forall lb. Label lb => [Char] -> NSGraph lb -> [Char]
showArcs [Char]
p NSGraph lb
g
where
showForm :: [Char]
showForm = forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (([Char]
pp forall a. [a] -> [a] -> [a]
++) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> [Char]
show) [LookupFormula lb (NSGraph lb)]
fml
fml :: [LookupFormula lb (NSGraph lb)]
fml = forall a b. (a -> b) -> [a] -> [b]
map (forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry forall lb gr. lb -> gr -> LookupFormula lb gr
Formula) forall a b. (a -> b) -> a -> b
$ forall k a. Map k a -> [(k, a)]
M.assocs (forall lb. NSGraph lb -> FormulaMap lb
getFormulae NSGraph lb
g)
pp :: [Char]
pp = [Char]
"\n " forall a. [a] -> [a] -> [a]
++ [Char]
p
showArcs :: (Label lb) => String -> NSGraph lb -> String
showArcs :: forall lb. Label lb => [Char] -> NSGraph lb -> [Char]
showArcs [Char]
p NSGraph lb
g = forall a b. (a -> b -> b) -> b -> Set a -> b
S.foldr (forall a. [a] -> [a] -> [a]
(++) forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Char]
pp forall a. [a] -> [a] -> [a]
++) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> [Char]
show) [Char]
"" (forall (lg :: * -> *) lb. LDGraph lg lb => lg lb -> ArcSet lb
getArcs NSGraph lb
g)
where
pp :: [Char]
pp = [Char]
"\n " forall a. [a] -> [a] -> [a]
++ [Char]
p
grEq :: (Label lb) => NSGraph lb -> NSGraph lb -> Bool
grEq :: forall lb. Label lb => NSGraph lb -> NSGraph lb -> Bool
grEq NSGraph lb
g1 = forall a b. (a, b) -> a
fst forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall lb.
Label lb =>
NSGraph lb -> NSGraph lb -> (Bool, LabelMap (ScopedLabel lb))
grMatchMap NSGraph lb
g1
grMatchMap :: (Label lb) =>
NSGraph lb -> NSGraph lb -> (Bool, LabelMap (ScopedLabel lb))
grMatchMap :: forall lb.
Label lb =>
NSGraph lb -> NSGraph lb -> (Bool, LabelMap (ScopedLabel lb))
grMatchMap NSGraph lb
g1 NSGraph lb
g2 =
forall lb.
Label lb =>
(lb -> lb -> Bool)
-> ArcSet lb -> ArcSet lb -> (Bool, LabelMap (ScopedLabel lb))
graphMatch lb -> lb -> Bool
matchable (forall (lg :: * -> *) lb. LDGraph lg lb => lg lb -> ArcSet lb
getArcs NSGraph lb
g1) (forall (lg :: * -> *) lb. LDGraph lg lb => lg lb -> ArcSet lb
getArcs NSGraph lb
g2)
where
matchable :: lb -> lb -> Bool
matchable lb
l1 lb
l2 = forall {k}. Ord k => NSGraph k -> k -> Maybe (NSGraph k)
mapFormula NSGraph lb
g1 lb
l1 forall a. Eq a => a -> a -> Bool
== forall {k}. Ord k => NSGraph k -> k -> Maybe (NSGraph k)
mapFormula NSGraph lb
g2 lb
l2
mapFormula :: NSGraph k -> k -> Maybe (NSGraph k)
mapFormula NSGraph k
g k
l = forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup k
l (forall lb. NSGraph lb -> FormulaMap lb
getFormulae NSGraph k
g)
merge :: (Label lb) => NSGraph lb -> NSGraph lb -> NSGraph lb
merge :: forall lb. Label lb => NSGraph lb -> NSGraph lb -> NSGraph lb
merge NSGraph lb
gr1 NSGraph lb
gr2 =
let bn1 :: [lb]
bn1 = forall a. Set a -> [a]
S.toList forall a b. (a -> b) -> a -> b
$ forall lb. Label lb => (lb -> Bool) -> NSGraph lb -> Set lb
allLabels forall lb. Label lb => lb -> Bool
labelIsVar NSGraph lb
gr1
bn2 :: [lb]
bn2 = forall a. Set a -> [a]
S.toList forall a b. (a -> b) -> a -> b
$ forall lb. Label lb => (lb -> Bool) -> NSGraph lb -> Set lb
allLabels forall lb. Label lb => lb -> Bool
labelIsVar NSGraph lb
gr2
dupbn :: [lb]
dupbn = forall a. Eq a => [a] -> [a] -> [a]
intersect [lb]
bn1 [lb]
bn2
allbn :: [lb]
allbn = forall a. Eq a => [a] -> [a] -> [a]
union [lb]
bn1 [lb]
bn2
in forall (lg :: * -> *) lb.
(LDGraph lg lb, Ord lb) =>
lg lb -> lg lb -> lg lb
addGraphs NSGraph lb
gr1 (forall lb.
Label lb =>
[lb] -> [lb] -> (lb -> lb) -> NSGraph lb -> NSGraph lb
remapLabels [lb]
dupbn [lb]
allbn forall a. a -> a
id NSGraph lb
gr2)
allLabels :: (Label lb) => (lb -> Bool) -> NSGraph lb -> S.Set lb
allLabels :: forall lb. Label lb => (lb -> Bool) -> NSGraph lb -> Set lb
allLabels lb -> Bool
p NSGraph lb
gr = forall a. (a -> Bool) -> Set a -> Set a
S.filter lb -> Bool
p (forall lb. Label lb => (lb -> Bool) -> Set lb -> Set lb -> Set lb
unionNodes lb -> Bool
p (forall lb. Label lb => (lb -> Bool) -> NSGraph lb -> Set lb
formulaNodes lb -> Bool
p NSGraph lb
gr) (forall (lg :: * -> *) lb.
(LDGraph lg lb, Ord lb) =>
lg lb -> Set lb
labels NSGraph lb
gr) )
allNodes :: (Label lb) => (lb -> Bool) -> NSGraph lb -> S.Set lb
allNodes :: forall lb. Label lb => (lb -> Bool) -> NSGraph lb -> Set lb
allNodes lb -> Bool
p = forall lb. Label lb => (lb -> Bool) -> Set lb -> Set lb -> Set lb
unionNodes lb -> Bool
p forall a. Set a
S.empty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (lg :: * -> *) lb.
(LDGraph lg lb, Ord lb) =>
lg lb -> Set lb
nodes
formulaNodes :: (Label lb) => (lb -> Bool) -> NSGraph lb -> S.Set lb
formulaNodes :: forall lb. Label lb => (lb -> Bool) -> NSGraph lb -> Set lb
formulaNodes lb -> Bool
p NSGraph lb
gr = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' (forall lb. Label lb => (lb -> Bool) -> Set lb -> Set lb -> Set lb
unionNodes lb -> Bool
p) Set lb
fkeys (forall a b. (a -> b) -> [a] -> [b]
map (forall lb. Label lb => (lb -> Bool) -> NSGraph lb -> Set lb
allLabels lb -> Bool
p) [NSGraph lb]
fvals)
where
fm :: FormulaMap lb
fm = forall lb. NSGraph lb -> FormulaMap lb
formulae NSGraph lb
gr
fvals :: [NSGraph lb]
fvals = forall k a. Map k a -> [a]
M.elems FormulaMap lb
fm
fkeys :: Set lb
fkeys = forall a. (a -> Bool) -> Set a -> Set a
S.filter lb -> Bool
p forall a b. (a -> b) -> a -> b
$ forall a. Ord a => [a] -> Set a
S.fromList forall a b. (a -> b) -> a -> b
$ forall k a. Map k a -> [k]
M.keys FormulaMap lb
fm
unionNodes :: (Label lb) => (lb -> Bool) -> S.Set lb -> S.Set lb -> S.Set lb
unionNodes :: forall lb. Label lb => (lb -> Bool) -> Set lb -> Set lb -> Set lb
unionNodes lb -> Bool
p Set lb
ls1 Set lb
ls2 = Set lb
ls1 forall a. Ord a => Set a -> Set a -> Set a
`S.union` forall a. (a -> Bool) -> Set a -> Set a
S.filter lb -> Bool
p Set lb
ls2
remapLabels ::
(Label lb)
=> [lb]
-> [lb]
-> (lb -> lb)
-> NSGraph lb
-> NSGraph lb
remapLabels :: forall lb.
Label lb =>
[lb] -> [lb] -> (lb -> lb) -> NSGraph lb -> NSGraph lb
remapLabels [lb]
dupbn [lb]
allbn lb -> lb
cnvbn =
forall lb. Ord lb => (lb -> lb) -> NSGraph lb -> NSGraph lb
fmapNSGraph (forall lb. Label lb => [lb] -> [lb] -> (lb -> lb) -> lb -> lb
mapnode [lb]
dupbn [lb]
allbn lb -> lb
cnvbn)
remapLabelList ::
(Label lb)
=> [lb]
-> [lb]
-> [(lb,lb)]
remapLabelList :: forall lb. Label lb => [lb] -> [lb] -> [(lb, lb)]
remapLabelList [lb]
remap [lb]
avoid = forall lb.
Label lb =>
[lb] -> [lb] -> (lb -> lb) -> [(lb, lb)] -> [(lb, lb)]
maplist [lb]
remap [lb]
avoid forall a. a -> a
id []
mapnode ::
(Label lb) => [lb] -> [lb] -> (lb -> lb) -> lb -> lb
mapnode :: forall lb. Label lb => [lb] -> [lb] -> (lb -> lb) -> lb -> lb
mapnode [lb]
dupbn [lb]
allbn lb -> lb
cnvbn lb
nv =
forall k a. Ord k => a -> k -> Map k a -> a
M.findWithDefault lb
nv lb
nv forall a b. (a -> b) -> a -> b
$ forall k a. Ord k => [(k, a)] -> Map k a
M.fromList forall a b. (a -> b) -> a -> b
$ forall lb.
Label lb =>
[lb] -> [lb] -> (lb -> lb) -> [(lb, lb)] -> [(lb, lb)]
maplist [lb]
dupbn [lb]
allbn lb -> lb
cnvbn []
maplist ::
(Label lb)
=> [lb]
-> [lb]
-> (lb -> lb)
-> [(lb,lb)]
-> [(lb,lb)]
maplist :: forall lb.
Label lb =>
[lb] -> [lb] -> (lb -> lb) -> [(lb, lb)] -> [(lb, lb)]
maplist [] [lb]
_ lb -> lb
_ [(lb, lb)]
mapbn = [(lb, lb)]
mapbn
maplist (lb
dn:[lb]
dupbn) [lb]
allbn lb -> lb
cnvbn [(lb, lb)]
mapbn = forall lb.
Label lb =>
[lb] -> [lb] -> (lb -> lb) -> [(lb, lb)] -> [(lb, lb)]
maplist [lb]
dupbn [lb]
allbn' lb -> lb
cnvbn [(lb, lb)]
mapbn'
where
dnmap :: lb
dnmap = forall lb. Label lb => lb -> [lb] -> lb
newNode (lb -> lb
cnvbn lb
dn) [lb]
allbn
mapbn' :: [(lb, lb)]
mapbn' = (lb
dn,lb
dnmap)forall a. a -> [a] -> [a]
:[(lb, lb)]
mapbn
allbn' :: [lb]
allbn' = lb
dnmapforall a. a -> [a] -> [a]
:[lb]
allbn
newNode :: (Label lb) => lb -> [lb] -> lb
newNode :: forall lb. Label lb => lb -> [lb] -> lb
newNode lb
dn [lb]
existnodes =
forall a. [a] -> a
head forall a b. (a -> b) -> a -> b
$ forall lb. Label lb => lb -> [lb] -> [lb]
newNodes lb
dn [lb]
existnodes
newNodes :: (Label lb) => lb -> [lb] -> [lb]
newNodes :: forall lb. Label lb => lb -> [lb] -> [lb]
newNodes lb
dn [lb]
existnodes =
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [lb]
existnodes)) forall a b. (a -> b) -> a -> b
$ forall lb. Label lb => ([Char], Word32) -> [lb]
trynodes (forall lb. Label lb => lb -> ([Char], Word32)
noderootindex lb
dn)
noderootindex :: (Label lb) => lb -> (String, Word32)
noderootindex :: forall lb. Label lb => lb -> ([Char], Word32)
noderootindex lb
dn = ([Char]
nh,Word32
nx) where
([Char]
nh,[Char]
nt) = [Char] -> ([Char], [Char])
splitnodeid forall a b. (a -> b) -> a -> b
$ forall lb. Label lb => lb -> [Char]
getLocal lb
dn
nx :: Word32
nx = if forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Char]
nt then Word32
0 else forall a. Read a => [Char] -> a
read [Char]
nt
splitnodeid :: String -> (String,String)
splitnodeid :: [Char] -> ([Char], [Char])
splitnodeid = forall a. (a -> Bool) -> [a] -> ([a], [a])
break Char -> Bool
isDigit
trynodes :: (Label lb) => (String, Word32) -> [lb]
trynodes :: forall lb. Label lb => ([Char], Word32) -> [lb]
trynodes ([Char]
nr,Word32
nx) = [ forall lb. Label lb => [Char] -> lb
makeLabel ([Char]
nr forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> [Char]
show Word32
n) | Word32
n <- forall a. (a -> a) -> a -> [a]
iterate (forall a. Num a => a -> a -> a
+ Word32
1) Word32
nx ]
type RDFGraph = NSGraph RDFLabel
toRDFGraph ::
RDFArcSet
-> RDFGraph
toRDFGraph :: RDFArcSet -> RDFGraph
toRDFGraph RDFArcSet
arcs =
let lbls :: Set RDFLabel
lbls = forall b a. Ord b => (a -> [b]) -> Set a -> Set b
getComponents forall lb. Arc lb -> [lb]
arcLabels RDFArcSet
arcs
getNS :: RDFLabel -> Maybe ScopedName
getNS (Res ScopedName
s) = forall a. a -> Maybe a
Just ScopedName
s
getNS (TypedLit Text
_ ScopedName
dt) = forall a. a -> Maybe a
Just ScopedName
dt
getNS RDFLabel
_ = forall a. Maybe a
Nothing
ns :: [Namespace]
ns = forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ScopedName -> Namespace
getScopeNamespace forall b c a. (b -> c) -> (a -> b) -> a -> c
. RDFLabel -> Maybe ScopedName
getNS) forall a b. (a -> b) -> a -> b
$ forall a. Set a -> [a]
S.toList Set RDFLabel
lbls
nsmap :: NamespaceMap
nsmap = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl'
(\NamespaceMap
m Namespace
ins -> let (Maybe Text
p,URI
u) = Namespace -> (Maybe Text, URI)
getNamespaceTuple Namespace
ins
in forall k a. Ord k => (a -> a -> a) -> k -> a -> Map k a -> Map k a
M.insertWith (forall a b. a -> b -> a
const forall a. a -> a
id) Maybe Text
p URI
u NamespaceMap
m)
NamespaceMap
emptyNamespaceMap [Namespace]
ns
in forall a. Monoid a => a
mempty { namespaces :: NamespaceMap
namespaces = NamespaceMap
nsmap, statements :: RDFArcSet
statements = RDFArcSet
arcs }
emptyRDFGraph :: RDFGraph
emptyRDFGraph :: RDFGraph
emptyRDFGraph = forall a. Monoid a => a
mempty