{-# LANGUAGE CPP #-}
module Swish.RDF.Query
( rdfQueryFind, rdfQueryFilter
, rdfQueryBack, rdfQueryBackFilter, rdfQueryBackModify
, rdfQueryInstance
, rdfQuerySubs, rdfQueryBackSubs
, rdfQuerySubsAll
, rdfQuerySubsBlank, rdfQueryBackSubsBlank
, rdfFindArcs, rdfSubjEq, rdfPredEq, rdfObjEq
, rdfFindPredVal, rdfFindPredInt, rdfFindValSubj
, rdfFindList
, allp
, anyp
, rdfQuerySubs2 )
where
import Swish.Datatype (DatatypeMap(..))
import Swish.VarBinding (VarBinding(..), VarBindingModify(..), VarBindingFilter(..))
import Swish.VarBinding (makeVarBinding, applyVarBinding, joinVarBindings)
import Swish.RDF.Graph
( Arc(..), LDGraph(..)
, arcSubj, arcPred, arcObj
, RDFLabel(..)
, isDatatyped, isBlank, isQueryVar
, getLiteralText, makeBlank
, RDFTriple
, RDFGraph
, allLabels, remapLabels
, resRdfFirst
, resRdfRest
, resRdfNil
, traverseNSGraph
)
import Swish.RDF.VarBinding (RDFVarBinding, RDFVarBindingFilter)
import Swish.RDF.VarBinding (nullRDFVarBinding)
import Swish.RDF.Datatype.XSD.MapInteger (mapXsdInteger)
import Swish.RDF.Vocabulary (xsdInteger, xsdNonNegInteger)
import Swish.Utils.ListHelpers (flist)
import Control.Monad (when)
import Control.Monad.State (State, runState, modify)
import Data.Maybe (mapMaybe, isJust, fromJust)
#if (!defined(__GLASGOW_HASKELL__)) || (__GLASGOW_HASKELL__ < 710)
import Data.Monoid (Monoid(..))
#endif
import qualified Data.Set as S
getTriples :: RDFGraph -> [RDFTriple]
getTriples :: NSGraph RDFLabel -> [RDFTriple]
getTriples = forall a. Set a -> [a]
S.toList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (lg :: * -> *) lb. LDGraph lg lb => lg lb -> ArcSet lb
getArcs
rdfQueryFind ::
RDFGraph
-> RDFGraph
-> [RDFVarBinding]
rdfQueryFind :: NSGraph RDFLabel -> NSGraph RDFLabel -> [RDFVarBinding]
rdfQueryFind =
NodeQuery RDFLabel
-> RDFVarBinding
-> [RDFTriple]
-> NSGraph RDFLabel
-> [RDFVarBinding]
rdfQueryPrim1 NodeQuery RDFLabel
matchQueryVariable RDFVarBinding
nullRDFVarBinding forall b c a. (b -> c) -> (a -> b) -> a -> c
. NSGraph RDFLabel -> [RDFTriple]
getTriples
rdfQueryPrim1 ::
NodeQuery RDFLabel -> RDFVarBinding -> [Arc RDFLabel]
-> RDFGraph
-> [RDFVarBinding]
rdfQueryPrim1 :: NodeQuery RDFLabel
-> RDFVarBinding
-> [RDFTriple]
-> NSGraph RDFLabel
-> [RDFVarBinding]
rdfQueryPrim1 NodeQuery RDFLabel
_ RDFVarBinding
initv [] NSGraph RDFLabel
_ = [RDFVarBinding
initv]
rdfQueryPrim1 NodeQuery RDFLabel
nodeq RDFVarBinding
initv (RDFTriple
qa:[RDFTriple]
qas) NSGraph RDFLabel
tg =
let qam :: RDFTriple
qam = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall a. VarBinding a a -> a -> a
applyVarBinding RDFVarBinding
initv) RDFTriple
qa
newv :: [RDFVarBinding]
newv = NodeQuery RDFLabel
-> RDFTriple -> NSGraph RDFLabel -> [RDFVarBinding]
rdfQueryPrim2 NodeQuery RDFLabel
nodeq RDFTriple
qam NSGraph RDFLabel
tg
in forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
[ NodeQuery RDFLabel
-> RDFVarBinding
-> [RDFTriple]
-> NSGraph RDFLabel
-> [RDFVarBinding]
rdfQueryPrim1 NodeQuery RDFLabel
nodeq RDFVarBinding
v2 [RDFTriple]
qas NSGraph RDFLabel
tg
| RDFVarBinding
v1 <- [RDFVarBinding]
newv
, let v2 :: RDFVarBinding
v2 = forall a b.
(Ord a, Ord b) =>
VarBinding a b -> VarBinding a b -> VarBinding a b
joinVarBindings RDFVarBinding
initv RDFVarBinding
v1
]
rdfQueryPrim2 ::
NodeQuery RDFLabel -> Arc RDFLabel
-> RDFGraph
-> [RDFVarBinding]
rdfQueryPrim2 :: NodeQuery RDFLabel
-> RDFTriple -> NSGraph RDFLabel -> [RDFVarBinding]
rdfQueryPrim2 NodeQuery RDFLabel
nodeq RDFTriple
qa NSGraph RDFLabel
tg =
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (NodeQuery RDFLabel -> RDFTriple -> RDFTriple -> Maybe RDFVarBinding
getBinding NodeQuery RDFLabel
nodeq RDFTriple
qa) (forall a. Set a -> [a]
S.toList forall a b. (a -> b) -> a -> b
$ forall (lg :: * -> *) lb. LDGraph lg lb => lg lb -> ArcSet lb
getArcs NSGraph RDFLabel
tg)
rdfQueryFilter ::
RDFVarBindingFilter -> [RDFVarBinding] -> [RDFVarBinding]
rdfQueryFilter :: RDFVarBindingFilter -> [RDFVarBinding] -> [RDFVarBinding]
rdfQueryFilter RDFVarBindingFilter
qbf = forall a. (a -> Bool) -> [a] -> [a]
filter (forall a b. VarBindingFilter a b -> VarBinding a b -> Bool
vbfTest RDFVarBindingFilter
qbf)
rdfQueryBack ::
RDFGraph
-> RDFGraph
-> [[RDFVarBinding]]
rdfQueryBack :: NSGraph RDFLabel -> NSGraph RDFLabel -> [[RDFVarBinding]]
rdfQueryBack NSGraph RDFLabel
qg NSGraph RDFLabel
tg =
let ga :: NSGraph RDFLabel -> [RDFTriple]
ga = NSGraph RDFLabel -> [RDFTriple]
getTriples
in NodeQuery RDFLabel
-> [RDFVarBinding]
-> [RDFTriple]
-> [RDFTriple]
-> [[RDFVarBinding]]
rdfQueryBack1 NodeQuery RDFLabel
matchQueryVariable [] (NSGraph RDFLabel -> [RDFTriple]
ga NSGraph RDFLabel
qg) (NSGraph RDFLabel -> [RDFTriple]
ga NSGraph RDFLabel
tg)
rdfQueryBack1 ::
NodeQuery RDFLabel -> [RDFVarBinding] -> [Arc RDFLabel] -> [Arc RDFLabel]
-> [[RDFVarBinding]]
rdfQueryBack1 :: NodeQuery RDFLabel
-> [RDFVarBinding]
-> [RDFTriple]
-> [RDFTriple]
-> [[RDFVarBinding]]
rdfQueryBack1 NodeQuery RDFLabel
_ [RDFVarBinding]
initv [RDFTriple]
_ [] = [[RDFVarBinding]
initv]
rdfQueryBack1 NodeQuery RDFLabel
nodeq [RDFVarBinding]
initv [RDFTriple]
qas (RDFTriple
ta:[RDFTriple]
tas) = forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
[ NodeQuery RDFLabel
-> [RDFVarBinding]
-> [RDFTriple]
-> [RDFTriple]
-> [[RDFVarBinding]]
rdfQueryBack1 NodeQuery RDFLabel
nodeq (RDFVarBinding
nvforall a. a -> [a] -> [a]
:[RDFVarBinding]
initv) [RDFTriple]
qas [RDFTriple]
tas
| RDFVarBinding
nv <- NodeQuery RDFLabel -> [RDFTriple] -> RDFTriple -> [RDFVarBinding]
rdfQueryBack2 NodeQuery RDFLabel
nodeq [RDFTriple]
qas RDFTriple
ta ]
rdfQueryBack2 ::
NodeQuery RDFLabel -> [Arc RDFLabel] -> Arc RDFLabel
-> [RDFVarBinding]
rdfQueryBack2 :: NodeQuery RDFLabel -> [RDFTriple] -> RDFTriple -> [RDFVarBinding]
rdfQueryBack2 NodeQuery RDFLabel
nodeq [RDFTriple]
qas RDFTriple
ta =
[ forall a. HasCallStack => Maybe a -> a
fromJust Maybe RDFVarBinding
b | RDFTriple
qa <- [RDFTriple]
qas, let b :: Maybe RDFVarBinding
b = NodeQuery RDFLabel -> RDFTriple -> RDFTriple -> Maybe RDFVarBinding
getBinding NodeQuery RDFLabel
nodeq RDFTriple
qa RDFTriple
ta, forall a. Maybe a -> Bool
isJust Maybe RDFVarBinding
b ]
rdfQueryBackFilter ::
RDFVarBindingFilter -> [[RDFVarBinding]] -> [[RDFVarBinding]]
rdfQueryBackFilter :: RDFVarBindingFilter -> [[RDFVarBinding]] -> [[RDFVarBinding]]
rdfQueryBackFilter RDFVarBindingFilter
qbf = forall a. (a -> Bool) -> [a] -> [a]
filter (forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (forall a b. VarBindingFilter a b -> VarBinding a b -> Bool
vbfTest RDFVarBindingFilter
qbf))
rdfQueryBackModify ::
VarBindingModify a b -> [[VarBinding a b]] -> [[VarBinding a b]]
rdfQueryBackModify :: forall a b.
VarBindingModify a b -> [[VarBinding a b]] -> [[VarBinding a b]]
rdfQueryBackModify VarBindingModify a b
qbm = forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (forall a b.
VarBindingModify a b -> [VarBinding a b] -> [[VarBinding a b]]
rdfQueryBackModify1 VarBindingModify a b
qbm)
rdfQueryBackModify1 ::
VarBindingModify a b -> [VarBinding a b] -> [[VarBinding a b]]
rdfQueryBackModify1 :: forall a b.
VarBindingModify a b -> [VarBinding a b] -> [[VarBinding a b]]
rdfQueryBackModify1 VarBindingModify a b
qbm = forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (forall a b.
VarBindingModify a b -> [VarBinding a b] -> [VarBinding a b]
vbmApply VarBindingModify a b
qbm forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. a -> [a] -> [a]
:[]))
rdfQueryInstance :: RDFGraph -> RDFGraph -> [RDFVarBinding]
rdfQueryInstance :: NSGraph RDFLabel -> NSGraph RDFLabel -> [RDFVarBinding]
rdfQueryInstance =
NodeQuery RDFLabel
-> RDFVarBinding
-> [RDFTriple]
-> NSGraph RDFLabel
-> [RDFVarBinding]
rdfQueryPrim1 NodeQuery RDFLabel
matchQueryBnode RDFVarBinding
nullRDFVarBinding forall b c a. (b -> c) -> (a -> b) -> a -> c
. NSGraph RDFLabel -> [RDFTriple]
getTriples
type NodeQuery a = a -> a -> Maybe Bool
getBinding ::
NodeQuery RDFLabel -> Arc RDFLabel -> Arc RDFLabel
-> Maybe RDFVarBinding
getBinding :: NodeQuery RDFLabel -> RDFTriple -> RDFTriple -> Maybe RDFVarBinding
getBinding NodeQuery RDFLabel
nodeq (Arc RDFLabel
s1 RDFLabel
p1 RDFLabel
o1) (Arc RDFLabel
s2 RDFLabel
p2 RDFLabel
o2) =
[(RDFLabel, RDFLabel)]
-> [(RDFLabel, RDFLabel)] -> Maybe RDFVarBinding
makeBinding [(RDFLabel
s1,RDFLabel
s2),(RDFLabel
p1,RDFLabel
p2),(RDFLabel
o1,RDFLabel
o2)] []
where
makeBinding :: [(RDFLabel, RDFLabel)]
-> [(RDFLabel, RDFLabel)] -> Maybe RDFVarBinding
makeBinding [] [(RDFLabel, RDFLabel)]
bs = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ forall a b. (Ord a, Ord b) => [(a, b)] -> VarBinding a b
makeVarBinding [(RDFLabel, RDFLabel)]
bs
makeBinding (vr :: (RDFLabel, RDFLabel)
vr@(RDFLabel
v,RDFLabel
r):[(RDFLabel, RDFLabel)]
bvrs) [(RDFLabel, RDFLabel)]
bs =
case NodeQuery RDFLabel
nodeq RDFLabel
v RDFLabel
r of
Maybe Bool
Nothing -> forall a. Maybe a
Nothing
Just Bool
False -> [(RDFLabel, RDFLabel)]
-> [(RDFLabel, RDFLabel)] -> Maybe RDFVarBinding
makeBinding [(RDFLabel, RDFLabel)]
bvrs [(RDFLabel, RDFLabel)]
bs
Just Bool
True -> [(RDFLabel, RDFLabel)]
-> [(RDFLabel, RDFLabel)] -> Maybe RDFVarBinding
makeBinding [(RDFLabel, RDFLabel)]
bvrs ((RDFLabel, RDFLabel)
vrforall a. a -> [a] -> [a]
:[(RDFLabel, RDFLabel)]
bs)
matchQueryVariable :: NodeQuery RDFLabel
matchQueryVariable :: NodeQuery RDFLabel
matchQueryVariable (Var String
_) RDFLabel
_ = forall a. a -> Maybe a
Just Bool
True
matchQueryVariable RDFLabel
q RDFLabel
t
| RDFLabel
q forall a. Eq a => a -> a -> Bool
== RDFLabel
t = forall a. a -> Maybe a
Just Bool
False
| Bool
otherwise = forall a. Maybe a
Nothing
matchQueryBnode :: NodeQuery RDFLabel
matchQueryBnode :: NodeQuery RDFLabel
matchQueryBnode (Blank String
_) RDFLabel
_ = forall a. a -> Maybe a
Just Bool
True
matchQueryBnode RDFLabel
q RDFLabel
t
| RDFLabel
q forall a. Eq a => a -> a -> Bool
== RDFLabel
t = forall a. a -> Maybe a
Just Bool
False
| Bool
otherwise = forall a. Maybe a
Nothing
rdfQuerySubs :: [RDFVarBinding] -> RDFGraph -> [RDFGraph]
rdfQuerySubs :: [RDFVarBinding] -> NSGraph RDFLabel -> [NSGraph RDFLabel]
rdfQuerySubs [RDFVarBinding]
vars NSGraph RDFLabel
gr =
forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> a
fst forall a b. (a -> b) -> a -> b
$ forall a. (a -> Bool) -> [a] -> [a]
filter (forall (t :: * -> *) a. Foldable t => t a -> Bool
null forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> b
snd) forall a b. (a -> b) -> a -> b
$ [RDFVarBinding]
-> NSGraph RDFLabel -> [(NSGraph RDFLabel, [RDFLabel])]
rdfQuerySubsAll [RDFVarBinding]
vars NSGraph RDFLabel
gr
rdfQueryBackSubs ::
[[RDFVarBinding]] -> RDFGraph -> [[(RDFGraph,[RDFLabel])]]
rdfQueryBackSubs :: [[RDFVarBinding]]
-> NSGraph RDFLabel -> [[(NSGraph RDFLabel, [RDFLabel])]]
rdfQueryBackSubs [[RDFVarBinding]]
varss NSGraph RDFLabel
gr = [ [RDFVarBinding]
-> NSGraph RDFLabel -> [(NSGraph RDFLabel, [RDFLabel])]
rdfQuerySubsAll [RDFVarBinding]
v NSGraph RDFLabel
gr | [RDFVarBinding]
v <- [[RDFVarBinding]]
varss ]
rdfQuerySubsAll :: [RDFVarBinding] -> RDFGraph -> [(RDFGraph,[RDFLabel])]
rdfQuerySubsAll :: [RDFVarBinding]
-> NSGraph RDFLabel -> [(NSGraph RDFLabel, [RDFLabel])]
rdfQuerySubsAll [RDFVarBinding]
vars NSGraph RDFLabel
gr = [ RDFVarBinding -> NSGraph RDFLabel -> (NSGraph RDFLabel, [RDFLabel])
rdfQuerySubs2 RDFVarBinding
v NSGraph RDFLabel
gr | RDFVarBinding
v <- [RDFVarBinding]
vars ]
rdfQuerySubsBlank :: [RDFVarBinding] -> RDFGraph -> [RDFGraph]
rdfQuerySubsBlank :: [RDFVarBinding] -> NSGraph RDFLabel -> [NSGraph RDFLabel]
rdfQuerySubsBlank [RDFVarBinding]
vars NSGraph RDFLabel
gr =
[ forall lb.
Label lb =>
[lb] -> [lb] -> (lb -> lb) -> NSGraph lb -> NSGraph lb
remapLabels [RDFLabel]
vs [RDFLabel]
bs RDFLabel -> RDFLabel
makeBlank NSGraph RDFLabel
g
| RDFVarBinding
v <- [RDFVarBinding]
vars
, let (NSGraph RDFLabel
g,[RDFLabel]
vs) = RDFVarBinding -> NSGraph RDFLabel -> (NSGraph RDFLabel, [RDFLabel])
rdfQuerySubs2 RDFVarBinding
v NSGraph RDFLabel
gr
, let bs :: [RDFLabel]
bs = 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 RDFLabel -> Bool
isBlank NSGraph RDFLabel
g
]
rdfQueryBackSubsBlank :: [[RDFVarBinding]] -> RDFGraph -> [[RDFGraph]]
rdfQueryBackSubsBlank :: [[RDFVarBinding]] -> NSGraph RDFLabel -> [[NSGraph RDFLabel]]
rdfQueryBackSubsBlank [[RDFVarBinding]]
varss NSGraph RDFLabel
gr = [ [RDFVarBinding] -> NSGraph RDFLabel -> [NSGraph RDFLabel]
rdfQuerySubsBlank [RDFVarBinding]
v NSGraph RDFLabel
gr | [RDFVarBinding]
v <- [[RDFVarBinding]]
varss ]
rdfQuerySubs2 :: RDFVarBinding -> RDFGraph -> (RDFGraph, [RDFLabel])
rdfQuerySubs2 :: RDFVarBinding -> NSGraph RDFLabel -> (NSGraph RDFLabel, [RDFLabel])
rdfQuerySubs2 RDFVarBinding
varb NSGraph RDFLabel
gr = (forall (lg :: * -> *) lb.
(LDGraph lg lb, Ord lb) =>
lg lb -> lg lb -> lg lb
addGraphs forall a. Monoid a => a
mempty NSGraph RDFLabel
g, forall a. Set a -> [a]
S.toList Set RDFLabel
vs)
where
(NSGraph RDFLabel
g,Set RDFLabel
vs) = forall s a. State s a -> s -> (a, s)
runState (forall (f :: * -> *) a.
(Applicative f, Ord a) =>
(a -> f a) -> NSGraph a -> f (NSGraph a)
traverseNSGraph (RDFVarBinding -> RDFLabel -> State (Set RDFLabel) RDFLabel
mapNode RDFVarBinding
varb) NSGraph RDFLabel
gr) forall a. Set a
S.empty
mapNode :: RDFVarBinding -> RDFLabel -> State (S.Set RDFLabel) RDFLabel
mapNode :: RDFVarBinding -> RDFLabel -> State (Set RDFLabel) RDFLabel
mapNode RDFVarBinding
varb RDFLabel
lab =
case forall a b. VarBinding a b -> a -> Maybe b
vbMap RDFVarBinding
varb RDFLabel
lab of
Just RDFLabel
v -> forall (m :: * -> *) a. Monad m => a -> m a
return RDFLabel
v
Maybe RDFLabel
Nothing -> forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (RDFLabel -> Bool
isQueryVar RDFLabel
lab) (forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (forall a. Ord a => a -> Set a -> Set a
S.insert RDFLabel
lab)) forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) a. Monad m => a -> m a
return RDFLabel
lab
allp :: [a->Bool] -> a -> Bool
allp :: forall a. [a -> Bool] -> a -> Bool
allp [a -> Bool]
ps a
a = forall (t :: * -> *). Foldable t => t Bool -> Bool
and (forall a b. [a -> b] -> a -> [b]
flist [a -> Bool]
ps a
a)
anyp :: [a->Bool] -> a -> Bool
anyp :: forall a. [a -> Bool] -> a -> Bool
anyp [a -> Bool]
ps a
a = forall (t :: * -> *). Foldable t => t Bool -> Bool
or (forall a b. [a -> b] -> a -> [b]
flist [a -> Bool]
ps a
a)
rdfFindArcs :: (RDFTriple -> Bool) -> RDFGraph -> [RDFTriple]
rdfFindArcs :: (RDFTriple -> Bool) -> NSGraph RDFLabel -> [RDFTriple]
rdfFindArcs RDFTriple -> Bool
p = forall a. Set a -> [a]
S.toList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. (a -> Bool) -> Set a -> Set a
S.filter RDFTriple -> Bool
p forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (lg :: * -> *) lb. LDGraph lg lb => lg lb -> ArcSet lb
getArcs
rdfSubjEq :: RDFLabel -> RDFTriple -> Bool
rdfSubjEq :: RDFLabel -> RDFTriple -> Bool
rdfSubjEq RDFLabel
s = (RDFLabel
s forall a. Eq a => a -> a -> Bool
==) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall lb. Arc lb -> lb
arcSubj
rdfPredEq :: RDFLabel -> RDFTriple -> Bool
rdfPredEq :: RDFLabel -> RDFTriple -> Bool
rdfPredEq RDFLabel
p = (RDFLabel
p forall a. Eq a => a -> a -> Bool
==) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall lb. Arc lb -> lb
arcPred
rdfObjEq :: RDFLabel -> RDFTriple -> Bool
rdfObjEq :: RDFLabel -> RDFTriple -> Bool
rdfObjEq RDFLabel
o = (RDFLabel
o forall a. Eq a => a -> a -> Bool
==) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall lb. Arc lb -> lb
arcObj
rdfFindPredVal ::
RDFLabel
-> RDFLabel
-> RDFGraph
-> [RDFLabel]
rdfFindPredVal :: RDFLabel -> RDFLabel -> NSGraph RDFLabel -> [RDFLabel]
rdfFindPredVal RDFLabel
s RDFLabel
p = forall a b. (a -> b) -> [a] -> [b]
map forall lb. Arc lb -> lb
arcObj forall b c a. (b -> c) -> (a -> b) -> a -> c
. (RDFTriple -> Bool) -> NSGraph RDFLabel -> [RDFTriple]
rdfFindArcs (forall a. [a -> Bool] -> a -> Bool
allp [RDFLabel -> RDFTriple -> Bool
rdfSubjEq RDFLabel
s,RDFLabel -> RDFTriple -> Bool
rdfPredEq RDFLabel
p])
rdfFindPredInt ::
RDFLabel
-> RDFLabel
-> RDFGraph -> [Integer]
rdfFindPredInt :: RDFLabel -> RDFLabel -> NSGraph RDFLabel -> [Integer]
rdfFindPredInt RDFLabel
s RDFLabel
p = forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe RDFLabel -> Maybe Integer
getint forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. (a -> Bool) -> [a] -> [a]
filter RDFLabel -> Bool
isint forall b c a. (b -> c) -> (a -> b) -> a -> c
. NSGraph RDFLabel -> [RDFLabel]
pvs
where
pvs :: NSGraph RDFLabel -> [RDFLabel]
pvs = RDFLabel -> RDFLabel -> NSGraph RDFLabel -> [RDFLabel]
rdfFindPredVal RDFLabel
s RDFLabel
p
isint :: RDFLabel -> Bool
isint = forall a. [a -> Bool] -> a -> Bool
anyp
[ ScopedName -> RDFLabel -> Bool
isDatatyped ScopedName
xsdInteger
, ScopedName -> RDFLabel -> Bool
isDatatyped ScopedName
xsdNonNegInteger
]
getint :: RDFLabel -> Maybe Integer
getint = forall vt. DatatypeMap vt -> Text -> Maybe vt
mapL2V DatatypeMap Integer
mapXsdInteger forall b c a. (b -> c) -> (a -> b) -> a -> c
. RDFLabel -> Text
getLiteralText
rdfFindValSubj ::
RDFLabel
-> RDFLabel
-> RDFGraph
-> [RDFLabel]
rdfFindValSubj :: RDFLabel -> RDFLabel -> NSGraph RDFLabel -> [RDFLabel]
rdfFindValSubj RDFLabel
p RDFLabel
o = forall a b. (a -> b) -> [a] -> [b]
map forall lb. Arc lb -> lb
arcSubj forall b c a. (b -> c) -> (a -> b) -> a -> c
. (RDFTriple -> Bool) -> NSGraph RDFLabel -> [RDFTriple]
rdfFindArcs (forall a. [a -> Bool] -> a -> Bool
allp [RDFLabel -> RDFTriple -> Bool
rdfPredEq RDFLabel
p,RDFLabel -> RDFTriple -> Bool
rdfObjEq RDFLabel
o])
rdfFindList :: RDFGraph -> RDFLabel -> [RDFLabel]
rdfFindList :: NSGraph RDFLabel -> RDFLabel -> [RDFLabel]
rdfFindList NSGraph RDFLabel
gr RDFLabel
hd = [RDFLabel] -> [RDFLabel]
findhead forall a b. (a -> b) -> a -> b
$ NSGraph RDFLabel -> RDFLabel -> [RDFLabel]
rdfFindList NSGraph RDFLabel
gr RDFLabel
findrest
where
findhead :: [RDFLabel] -> [RDFLabel]
findhead = forall {b}. b -> [b] -> b
headOr (forall a b. a -> b -> a
const []) forall a b. (a -> b) -> a -> b
$
forall a b. (a -> b) -> [a] -> [b]
map (:) (RDFLabel -> RDFLabel -> NSGraph RDFLabel -> [RDFLabel]
rdfFindPredVal RDFLabel
hd RDFLabel
resRdfFirst NSGraph RDFLabel
gr)
findrest :: RDFLabel
findrest = forall {b}. b -> [b] -> b
headOr RDFLabel
resRdfNil (RDFLabel -> RDFLabel -> NSGraph RDFLabel -> [RDFLabel]
rdfFindPredVal RDFLabel
hd RDFLabel
resRdfRest NSGraph RDFLabel
gr)
headOr :: b -> [b] -> b
headOr = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr forall a b. a -> b -> a
const