{-# LANGUAGE OverloadedStrings #-}
module Swish.RDF.VarBinding
( RDFVarBinding
, RDFVarBindingModify, RDFOpenVarBindingModify, RDFOpenVarBindingModifyMap
, RDFVarBindingFilter
, nullRDFVarBinding
, rdfVarBindingUriRef, rdfVarBindingBlank
, rdfVarBindingLiteral
, rdfVarBindingUntypedLiteral, rdfVarBindingTypedLiteral
, rdfVarBindingXMLLiteral, rdfVarBindingDatatyped
, rdfVarBindingMemberProp
)
where
import Swish.Namespace (ScopedName)
import Swish.VarBinding (VarBinding(..), VarBindingModify(..), OpenVarBindingModify, VarBindingFilter(..))
import Swish.VarBinding (nullVarBinding, applyVarBinding, makeVarTestFilter)
import Swish.RDF.Graph
( RDFLabel(..)
, isLiteral, isUntypedLiteral, isTypedLiteral, isXMLLiteral
, isDatatyped, isMemberProp, isUri, isBlank
)
import Swish.RDF.Vocabulary (swishName)
import qualified Data.Map as M
type RDFVarBinding = VarBinding RDFLabel RDFLabel
nullRDFVarBinding :: RDFVarBinding
nullRDFVarBinding :: RDFVarBinding
nullRDFVarBinding = RDFVarBinding
forall a b. VarBinding a b
nullVarBinding
type RDFVarBindingModify = VarBindingModify RDFLabel RDFLabel
type RDFOpenVarBindingModify = OpenVarBindingModify RDFLabel RDFLabel
type RDFOpenVarBindingModifyMap = M.Map ScopedName RDFOpenVarBindingModify
type RDFVarBindingFilter = VarBindingFilter RDFLabel RDFLabel
rdfVarBindingUriRef :: RDFLabel -> RDFVarBindingFilter
rdfVarBindingUriRef :: RDFLabel -> RDFVarBindingFilter
rdfVarBindingUriRef =
ScopedName -> (RDFLabel -> Bool) -> RDFLabel -> RDFVarBindingFilter
forall b a. ScopedName -> (b -> Bool) -> a -> VarBindingFilter a b
makeVarTestFilter (LName -> ScopedName
swishName LName
"rdfVarBindingUriRef") RDFLabel -> Bool
isUri
rdfVarBindingBlank :: RDFLabel -> RDFVarBindingFilter
rdfVarBindingBlank :: RDFLabel -> RDFVarBindingFilter
rdfVarBindingBlank =
ScopedName -> (RDFLabel -> Bool) -> RDFLabel -> RDFVarBindingFilter
forall b a. ScopedName -> (b -> Bool) -> a -> VarBindingFilter a b
makeVarTestFilter (LName -> ScopedName
swishName LName
"rdfVarBindingBlank") RDFLabel -> Bool
isBlank
rdfVarBindingLiteral :: RDFLabel -> RDFVarBindingFilter
rdfVarBindingLiteral :: RDFLabel -> RDFVarBindingFilter
rdfVarBindingLiteral =
ScopedName -> (RDFLabel -> Bool) -> RDFLabel -> RDFVarBindingFilter
forall b a. ScopedName -> (b -> Bool) -> a -> VarBindingFilter a b
makeVarTestFilter (LName -> ScopedName
swishName LName
"rdfVarBindingLiteral") RDFLabel -> Bool
isLiteral
rdfVarBindingUntypedLiteral :: RDFLabel -> RDFVarBindingFilter
rdfVarBindingUntypedLiteral :: RDFLabel -> RDFVarBindingFilter
rdfVarBindingUntypedLiteral =
ScopedName -> (RDFLabel -> Bool) -> RDFLabel -> RDFVarBindingFilter
forall b a. ScopedName -> (b -> Bool) -> a -> VarBindingFilter a b
makeVarTestFilter (LName -> ScopedName
swishName LName
"rdfVarBindingUntypedLiteral") RDFLabel -> Bool
isUntypedLiteral
rdfVarBindingTypedLiteral :: RDFLabel -> RDFVarBindingFilter
rdfVarBindingTypedLiteral :: RDFLabel -> RDFVarBindingFilter
rdfVarBindingTypedLiteral =
ScopedName -> (RDFLabel -> Bool) -> RDFLabel -> RDFVarBindingFilter
forall b a. ScopedName -> (b -> Bool) -> a -> VarBindingFilter a b
makeVarTestFilter (LName -> ScopedName
swishName LName
"rdfVarBindingTypedLiteral") RDFLabel -> Bool
isTypedLiteral
rdfVarBindingXMLLiteral :: RDFLabel -> RDFVarBindingFilter
rdfVarBindingXMLLiteral :: RDFLabel -> RDFVarBindingFilter
rdfVarBindingXMLLiteral =
ScopedName -> (RDFLabel -> Bool) -> RDFLabel -> RDFVarBindingFilter
forall b a. ScopedName -> (b -> Bool) -> a -> VarBindingFilter a b
makeVarTestFilter (LName -> ScopedName
swishName LName
"rdfVarBindingXMLLiteral") RDFLabel -> Bool
isXMLLiteral
rdfVarBindingMemberProp :: RDFLabel -> RDFVarBindingFilter
rdfVarBindingMemberProp :: RDFLabel -> RDFVarBindingFilter
rdfVarBindingMemberProp =
ScopedName -> (RDFLabel -> Bool) -> RDFLabel -> RDFVarBindingFilter
forall b a. ScopedName -> (b -> Bool) -> a -> VarBindingFilter a b
makeVarTestFilter (LName -> ScopedName
swishName LName
"rdfVarBindingMemberProp") RDFLabel -> Bool
isMemberProp
rdfVarBindingDatatyped ::
RDFLabel
-> RDFLabel
-> RDFVarBindingFilter
rdfVarBindingDatatyped :: RDFLabel -> RDFLabel -> RDFVarBindingFilter
rdfVarBindingDatatyped RDFLabel
dvar RDFLabel
lvar = VarBindingFilter :: forall a b.
ScopedName
-> [a] -> (VarBinding a b -> Bool) -> VarBindingFilter a b
VarBindingFilter
{ vbfName :: ScopedName
vbfName = LName -> ScopedName
swishName LName
"rdfVarBindingDatatyped"
, vbfVocab :: [RDFLabel]
vbfVocab = [RDFLabel
dvar,RDFLabel
lvar]
, vbfTest :: RDFVarBinding -> Bool
vbfTest = \RDFVarBinding
vb -> RDFVarBinding -> RDFLabel -> RDFLabel -> Bool
testDatatyped RDFVarBinding
vb RDFLabel
dvar RDFLabel
lvar
}
testDatatyped :: RDFVarBinding -> RDFLabel -> RDFLabel -> Bool
testDatatyped :: RDFVarBinding -> RDFLabel -> RDFLabel -> Bool
testDatatyped RDFVarBinding
vb RDFLabel
dvar RDFLabel
lvar = [Bool] -> Bool
forall (t :: * -> *). Foldable t => t Bool -> Bool
and
[ RDFLabel -> Bool
isUri RDFLabel
dtype
, ScopedName -> RDFLabel -> Bool
isDatatyped ScopedName
dqnam (RDFLabel -> Bool) -> RDFLabel -> Bool
forall a b. (a -> b) -> a -> b
$ RDFVarBinding -> RDFLabel -> RDFLabel
forall a. VarBinding a a -> a -> a
applyVarBinding RDFVarBinding
vb RDFLabel
lvar
]
where
dtype :: RDFLabel
dtype = RDFVarBinding -> RDFLabel -> RDFLabel
forall a. VarBinding a a -> a -> a
applyVarBinding RDFVarBinding
vb RDFLabel
dvar
dqnam :: ScopedName
dqnam = case RDFLabel
dtype of
Res ScopedName
x -> ScopedName
x
RDFLabel
_ -> [Char] -> ScopedName
forall a. HasCallStack => [Char] -> a
error ([Char] -> ScopedName) -> [Char] -> ScopedName
forall a b. (a -> b) -> a -> b
$ [Char]
"dqnam should not be evaluated with " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ RDFLabel -> [Char]
forall a. Show a => a -> [Char]
show RDFLabel
dtype