{-# LANGUAGE TypeFamilies #-}
module Pattern.Graph
(
GraphLens(..)
, mkGraphLens
, nodes
, isNode
, isRelationship
, relationships
, source
, target
, reverseRel
, isWalk
, walks
, walkNodes
, neighbors
, incidentRels
, degree
, fromGraphLens
, toGraphView
, GraphView(..)
, Substitution(..)
) where
import Pattern.Core (Pattern(..))
import Data.Maybe (mapMaybe)
import Pattern.Graph.GraphClassifier (GraphClass(..), GraphClassifier(..), GraphValue(..))
import Pattern.Graph.GraphQuery (GraphQuery(..))
import Pattern.Graph.Types (GraphView(..), Substitution(..))
data GraphLens v = GraphLens
{ forall v. GraphLens v -> Pattern v
scopePattern :: Pattern v
, forall v. GraphLens v -> Pattern v -> Bool
testNode :: Pattern v -> Bool
}
mkGraphLens :: Pattern v -> (Pattern v -> Bool) -> GraphLens v
mkGraphLens :: forall v. Pattern v -> (Pattern v -> Bool) -> GraphLens v
mkGraphLens = Pattern v -> (Pattern v -> Bool) -> GraphLens v
forall v. Pattern v -> (Pattern v -> Bool) -> GraphLens v
GraphLens
isValidWalk :: GraphValue v => (Pattern v -> Bool) -> [Pattern v] -> Bool
isValidWalk :: forall v.
GraphValue v =>
(Pattern v -> Bool) -> [Pattern v] -> Bool
isValidWalk Pattern v -> Bool
_ [] = Bool
False
isValidWalk Pattern v -> Bool
p [Pattern v]
rels = Bool -> Bool
not ([Pattern v] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null (([Pattern v] -> Pattern v -> [Pattern v])
-> [Pattern v] -> [Pattern v] -> [Pattern v]
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl [Pattern v] -> Pattern v -> [Pattern v]
step [] [Pattern v]
rels))
where
step :: [Pattern v] -> Pattern v -> [Pattern v]
step [] (Pattern v
_ [Pattern v
a, Pattern v
b]) = if Pattern v -> Bool
p Pattern v
a Bool -> Bool -> Bool
&& Pattern v -> Bool
p Pattern v
b then [Pattern v
a, Pattern v
b] else []
step [Pattern v]
active (Pattern v
_ [Pattern v
a, Pattern v
b]) =
if Pattern v -> Bool
p Pattern v
a Bool -> Bool -> Bool
&& Pattern v -> Bool
p Pattern v
b then
let fromA :: [Pattern v]
fromA = if (Pattern v -> Bool) -> [Pattern v] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (\Pattern v
x -> v -> Id v
forall v. GraphValue v => v -> Id v
identify (Pattern v -> v
forall v. Pattern v -> v
value Pattern v
a) Id v -> Id v -> Bool
forall a. Eq a => a -> a -> Bool
== v -> Id v
forall v. GraphValue v => v -> Id v
identify (Pattern v -> v
forall v. Pattern v -> v
value Pattern v
x)) [Pattern v]
active then [Pattern v
b] else []
fromB :: [Pattern v]
fromB = if (Pattern v -> Bool) -> [Pattern v] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (\Pattern v
x -> v -> Id v
forall v. GraphValue v => v -> Id v
identify (Pattern v -> v
forall v. Pattern v -> v
value Pattern v
b) Id v -> Id v -> Bool
forall a. Eq a => a -> a -> Bool
== v -> Id v
forall v. GraphValue v => v -> Id v
identify (Pattern v -> v
forall v. Pattern v -> v
value Pattern v
x)) [Pattern v]
active then [Pattern v
a] else []
in [Pattern v]
fromA [Pattern v] -> [Pattern v] -> [Pattern v]
forall a. [a] -> [a] -> [a]
++ [Pattern v]
fromB
else []
step [Pattern v]
_ Pattern v
_ = []
nodes :: GraphLens v -> [Pattern v]
nodes :: forall v. GraphLens v -> [Pattern v]
nodes lens :: GraphLens v
lens@(GraphLens (Pattern v
_ [Pattern v]
elems) Pattern v -> Bool
_) =
(Pattern v -> Bool) -> [Pattern v] -> [Pattern v]
forall a. (a -> Bool) -> [a] -> [a]
filter (GraphLens v -> Pattern v -> Bool
forall v. GraphLens v -> Pattern v -> Bool
isNode GraphLens v
lens) [Pattern v]
elems
isNode :: GraphLens v -> Pattern v -> Bool
isNode :: forall v. GraphLens v -> Pattern v -> Bool
isNode (GraphLens Pattern v
_ Pattern v -> Bool
test) Pattern v
p = Pattern v -> Bool
test Pattern v
p
isRelationship :: GraphLens v -> Pattern v -> Bool
isRelationship :: forall v. GraphLens v -> Pattern v -> Bool
isRelationship lens :: GraphLens v
lens@(GraphLens Pattern v
_ Pattern v -> Bool
test) p :: Pattern v
p@(Pattern v
_ [Pattern v]
els) =
Bool -> Bool
not (Pattern v -> Bool
test Pattern v
p) Bool -> Bool -> Bool
&& [Pattern v] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Pattern v]
els Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
2 Bool -> Bool -> Bool
&& (Pattern v -> Bool) -> [Pattern v] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all Pattern v -> Bool
test [Pattern v]
els
relationships :: GraphLens v -> [Pattern v]
relationships :: forall v. GraphLens v -> [Pattern v]
relationships lens :: GraphLens v
lens@(GraphLens (Pattern v
_ [Pattern v]
elems) Pattern v -> Bool
_) =
(Pattern v -> Bool) -> [Pattern v] -> [Pattern v]
forall a. (a -> Bool) -> [a] -> [a]
filter (GraphLens v -> Pattern v -> Bool
forall v. GraphLens v -> Pattern v -> Bool
isRelationship GraphLens v
lens) [Pattern v]
elems
source :: GraphLens v -> Pattern v -> Maybe (Pattern v)
source :: forall v. GraphLens v -> Pattern v -> Maybe (Pattern v)
source GraphLens v
lens p :: Pattern v
p@(Pattern v
_ (Pattern v
s:[Pattern v]
_))
| GraphLens v -> Pattern v -> Bool
forall v. GraphLens v -> Pattern v -> Bool
isRelationship GraphLens v
lens Pattern v
p = Pattern v -> Maybe (Pattern v)
forall a. a -> Maybe a
Just Pattern v
s
| Bool
otherwise = Maybe (Pattern v)
forall a. Maybe a
Nothing
source GraphLens v
_ Pattern v
_ = Maybe (Pattern v)
forall a. Maybe a
Nothing
target :: GraphLens v -> Pattern v -> Maybe (Pattern v)
target :: forall v. GraphLens v -> Pattern v -> Maybe (Pattern v)
target GraphLens v
lens p :: Pattern v
p@(Pattern v
_ [Pattern v
_, Pattern v
t])
| GraphLens v -> Pattern v -> Bool
forall v. GraphLens v -> Pattern v -> Bool
isRelationship GraphLens v
lens Pattern v
p = Pattern v -> Maybe (Pattern v)
forall a. a -> Maybe a
Just Pattern v
t
| Bool
otherwise = Maybe (Pattern v)
forall a. Maybe a
Nothing
target GraphLens v
_ Pattern v
_ = Maybe (Pattern v)
forall a. Maybe a
Nothing
reverseRel :: Pattern v -> Pattern v
reverseRel :: forall v. Pattern v -> Pattern v
reverseRel (Pattern v
v [Pattern v
a, Pattern v
b]) = v -> [Pattern v] -> Pattern v
forall v. v -> [Pattern v] -> Pattern v
Pattern v
v [Pattern v
b, Pattern v
a]
reverseRel Pattern v
p = Pattern v
p
consecutivelyConnected :: GraphValue v => GraphLens v -> [Pattern v] -> Bool
consecutivelyConnected :: forall v. GraphValue v => GraphLens v -> [Pattern v] -> Bool
consecutivelyConnected GraphLens v
lens [Pattern v]
rels =
case [Pattern v]
rels of
[] -> Bool
True
[Pattern v
_] -> Bool
True
(Pattern v
r1:Pattern v
r2:[Pattern v]
rest) ->
case (GraphLens v -> Pattern v -> Maybe (Pattern v)
forall v. GraphLens v -> Pattern v -> Maybe (Pattern v)
target GraphLens v
lens Pattern v
r1, GraphLens v -> Pattern v -> Maybe (Pattern v)
forall v. GraphLens v -> Pattern v -> Maybe (Pattern v)
source GraphLens v
lens Pattern v
r2) of
(Just Pattern v
t, Just Pattern v
s) -> v -> Id v
forall v. GraphValue v => v -> Id v
identify (Pattern v -> v
forall v. Pattern v -> v
value Pattern v
t) Id v -> Id v -> Bool
forall a. Eq a => a -> a -> Bool
== v -> Id v
forall v. GraphValue v => v -> Id v
identify (Pattern v -> v
forall v. Pattern v -> v
value Pattern v
s) Bool -> Bool -> Bool
&& GraphLens v -> [Pattern v] -> Bool
forall v. GraphValue v => GraphLens v -> [Pattern v] -> Bool
consecutivelyConnected GraphLens v
lens (Pattern v
r2Pattern v -> [Pattern v] -> [Pattern v]
forall a. a -> [a] -> [a]
:[Pattern v]
rest)
(Maybe (Pattern v), Maybe (Pattern v))
_ -> Bool
False
isWalk :: GraphValue v => GraphLens v -> Pattern v -> Bool
isWalk :: forall v. GraphValue v => GraphLens v -> Pattern v -> Bool
isWalk lens :: GraphLens v
lens@(GraphLens Pattern v
_ Pattern v -> Bool
test) p :: Pattern v
p@(Pattern v
_ [Pattern v]
els) =
Bool -> Bool
not (Pattern v -> Bool
test Pattern v
p) Bool -> Bool -> Bool
&& Bool -> Bool
not ([Pattern v] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Pattern v]
els)
Bool -> Bool -> Bool
&& (Pattern v -> Bool) -> [Pattern v] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (\Pattern v
e -> [Pattern v] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length (Pattern v -> [Pattern v]
forall v. Pattern v -> [Pattern v]
elements Pattern v
e) Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
2 Bool -> Bool -> Bool
&& (Pattern v -> Bool) -> [Pattern v] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all Pattern v -> Bool
test (Pattern v -> [Pattern v]
forall v. Pattern v -> [Pattern v]
elements Pattern v
e)) [Pattern v]
els
Bool -> Bool -> Bool
&& (Pattern v -> Bool) -> [Pattern v] -> Bool
forall v.
GraphValue v =>
(Pattern v -> Bool) -> [Pattern v] -> Bool
isValidWalk Pattern v -> Bool
test [Pattern v]
els
walks :: GraphValue v => GraphLens v -> [Pattern v]
walks :: forall v. GraphValue v => GraphLens v -> [Pattern v]
walks lens :: GraphLens v
lens@(GraphLens (Pattern v
_ [Pattern v]
elems) Pattern v -> Bool
_) =
(Pattern v -> Bool) -> [Pattern v] -> [Pattern v]
forall a. (a -> Bool) -> [a] -> [a]
filter (GraphLens v -> Pattern v -> Bool
forall v. GraphValue v => GraphLens v -> Pattern v -> Bool
isWalk GraphLens v
lens) [Pattern v]
elems
walkNodes :: GraphValue v => GraphLens v -> Pattern v -> [Pattern v]
walkNodes :: forall v. GraphValue v => GraphLens v -> Pattern v -> [Pattern v]
walkNodes GraphLens v
lens p :: Pattern v
p@(Pattern v
_ [Pattern v]
rels)
| GraphLens v -> Pattern v -> Bool
forall v. GraphValue v => GraphLens v -> Pattern v -> Bool
isWalk GraphLens v
lens Pattern v
p = case [Pattern v]
rels of
[] -> []
(Pattern v
r:[Pattern v]
rest) -> case GraphLens v -> Pattern v -> Maybe (Pattern v)
forall v. GraphLens v -> Pattern v -> Maybe (Pattern v)
source GraphLens v
lens Pattern v
r of
Just Pattern v
s -> Pattern v
s Pattern v -> [Pattern v] -> [Pattern v]
forall a. a -> [a] -> [a]
: (Pattern v -> Maybe (Pattern v)) -> [Pattern v] -> [Pattern v]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (GraphLens v -> Pattern v -> Maybe (Pattern v)
forall v. GraphLens v -> Pattern v -> Maybe (Pattern v)
target GraphLens v
lens) (Pattern v
rPattern v -> [Pattern v] -> [Pattern v]
forall a. a -> [a] -> [a]
:[Pattern v]
rest)
Maybe (Pattern v)
Nothing -> []
| Bool
otherwise = []
neighbors :: GraphValue v => GraphLens v -> Pattern v -> [Pattern v]
neighbors :: forall v. GraphValue v => GraphLens v -> Pattern v -> [Pattern v]
neighbors GraphLens v
lens Pattern v
node =
let rels :: [Pattern v]
rels = GraphLens v -> [Pattern v]
forall v. GraphLens v -> [Pattern v]
relationships GraphLens v
lens
nodeId :: Id v
nodeId = v -> Id v
forall v. GraphValue v => v -> Id v
identify (Pattern v -> v
forall v. Pattern v -> v
value Pattern v
node)
connectedNodes :: [Pattern v]
connectedNodes = (Pattern v -> [Pattern v]) -> [Pattern v] -> [Pattern v]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (\Pattern v
r ->
case (GraphLens v -> Pattern v -> Maybe (Pattern v)
forall v. GraphLens v -> Pattern v -> Maybe (Pattern v)
source GraphLens v
lens Pattern v
r, GraphLens v -> Pattern v -> Maybe (Pattern v)
forall v. GraphLens v -> Pattern v -> Maybe (Pattern v)
target GraphLens v
lens Pattern v
r) of
(Just Pattern v
s, Just Pattern v
t) | v -> Id v
forall v. GraphValue v => v -> Id v
identify (Pattern v -> v
forall v. Pattern v -> v
value Pattern v
s) Id v -> Id v -> Bool
forall a. Eq a => a -> a -> Bool
== Id v
nodeId -> [Pattern v
t]
| v -> Id v
forall v. GraphValue v => v -> Id v
identify (Pattern v -> v
forall v. Pattern v -> v
value Pattern v
t) Id v -> Id v -> Bool
forall a. Eq a => a -> a -> Bool
== Id v
nodeId -> [Pattern v
s]
(Maybe (Pattern v), Maybe (Pattern v))
_ -> []
) [Pattern v]
rels
in [Pattern v]
connectedNodes
incidentRels :: GraphValue v => GraphLens v -> Pattern v -> [Pattern v]
incidentRels :: forall v. GraphValue v => GraphLens v -> Pattern v -> [Pattern v]
incidentRels GraphLens v
lens Pattern v
node =
let nodeId :: Id v
nodeId = v -> Id v
forall v. GraphValue v => v -> Id v
identify (Pattern v -> v
forall v. Pattern v -> v
value Pattern v
node)
in (Pattern v -> Bool) -> [Pattern v] -> [Pattern v]
forall a. (a -> Bool) -> [a] -> [a]
filter (\Pattern v
r ->
case (GraphLens v -> Pattern v -> Maybe (Pattern v)
forall v. GraphLens v -> Pattern v -> Maybe (Pattern v)
source GraphLens v
lens Pattern v
r, GraphLens v -> Pattern v -> Maybe (Pattern v)
forall v. GraphLens v -> Pattern v -> Maybe (Pattern v)
target GraphLens v
lens Pattern v
r) of
(Just Pattern v
s, Maybe (Pattern v)
_) | v -> Id v
forall v. GraphValue v => v -> Id v
identify (Pattern v -> v
forall v. Pattern v -> v
value Pattern v
s) Id v -> Id v -> Bool
forall a. Eq a => a -> a -> Bool
== Id v
nodeId -> Bool
True
(Maybe (Pattern v)
_, Just Pattern v
t) | v -> Id v
forall v. GraphValue v => v -> Id v
identify (Pattern v -> v
forall v. Pattern v -> v
value Pattern v
t) Id v -> Id v -> Bool
forall a. Eq a => a -> a -> Bool
== Id v
nodeId -> Bool
True
(Maybe (Pattern v), Maybe (Pattern v))
_ -> Bool
False
) (GraphLens v -> [Pattern v]
forall v. GraphLens v -> [Pattern v]
relationships GraphLens v
lens)
degree :: GraphValue v => GraphLens v -> Pattern v -> Int
degree :: forall v. GraphValue v => GraphLens v -> Pattern v -> Int
degree GraphLens v
lens Pattern v
node = [Pattern v] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length (GraphLens v -> Pattern v -> [Pattern v]
forall v. GraphValue v => GraphLens v -> Pattern v -> [Pattern v]
incidentRels GraphLens v
lens Pattern v
node)
fromGraphLens :: (GraphValue v, Eq v) => GraphLens v -> GraphQuery v
fromGraphLens :: forall v. (GraphValue v, Eq v) => GraphLens v -> GraphQuery v
fromGraphLens GraphLens v
lens = GraphQuery
{ queryNodes :: [Pattern v]
queryNodes = GraphLens v -> [Pattern v]
forall v. GraphLens v -> [Pattern v]
nodes GraphLens v
lens
, queryRelationships :: [Pattern v]
queryRelationships = GraphLens v -> [Pattern v]
forall v. GraphLens v -> [Pattern v]
relationships GraphLens v
lens
, queryIncidentRels :: Pattern v -> [Pattern v]
queryIncidentRels = GraphLens v -> Pattern v -> [Pattern v]
forall v. GraphValue v => GraphLens v -> Pattern v -> [Pattern v]
incidentRels GraphLens v
lens
, querySource :: Pattern v -> Maybe (Pattern v)
querySource = GraphLens v -> Pattern v -> Maybe (Pattern v)
forall v. GraphLens v -> Pattern v -> Maybe (Pattern v)
source GraphLens v
lens
, queryTarget :: Pattern v -> Maybe (Pattern v)
queryTarget = GraphLens v -> Pattern v -> Maybe (Pattern v)
forall v. GraphLens v -> Pattern v -> Maybe (Pattern v)
target GraphLens v
lens
, queryDegree :: Pattern v -> Int
queryDegree = GraphLens v -> Pattern v -> Int
forall v. GraphValue v => GraphLens v -> Pattern v -> Int
degree GraphLens v
lens
, queryNodeById :: Id v -> Maybe (Pattern v)
queryNodeById = \Id v
i ->
(Pattern v -> Maybe (Pattern v) -> Maybe (Pattern v))
-> Maybe (Pattern v) -> [Pattern v] -> Maybe (Pattern v)
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (\Pattern v
n Maybe (Pattern v)
acc -> if v -> Id v
forall v. GraphValue v => v -> Id v
identify (Pattern v -> v
forall v. Pattern v -> v
value Pattern v
n) Id v -> Id v -> Bool
forall a. Eq a => a -> a -> Bool
== Id v
i then Pattern v -> Maybe (Pattern v)
forall a. a -> Maybe a
Just Pattern v
n else Maybe (Pattern v)
acc)
Maybe (Pattern v)
forall a. Maybe a
Nothing
(GraphLens v -> [Pattern v]
forall v. GraphLens v -> [Pattern v]
nodes GraphLens v
lens)
, queryRelationshipById :: Id v -> Maybe (Pattern v)
queryRelationshipById = \Id v
i ->
(Pattern v -> Maybe (Pattern v) -> Maybe (Pattern v))
-> Maybe (Pattern v) -> [Pattern v] -> Maybe (Pattern v)
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (\Pattern v
r Maybe (Pattern v)
acc -> if v -> Id v
forall v. GraphValue v => v -> Id v
identify (Pattern v -> v
forall v. Pattern v -> v
value Pattern v
r) Id v -> Id v -> Bool
forall a. Eq a => a -> a -> Bool
== Id v
i then Pattern v -> Maybe (Pattern v)
forall a. a -> Maybe a
Just Pattern v
r else Maybe (Pattern v)
acc)
Maybe (Pattern v)
forall a. Maybe a
Nothing
(GraphLens v -> [Pattern v]
forall v. GraphLens v -> [Pattern v]
relationships GraphLens v
lens)
, queryContainers :: Pattern v -> [Pattern v]
queryContainers = \Pattern v
p ->
let nodeId :: Id v
nodeId = v -> Id v
forall v. GraphValue v => v -> Id v
identify (Pattern v -> v
forall v. Pattern v -> v
value Pattern v
p)
inRel :: Pattern v -> Bool
inRel Pattern v
r = case (GraphLens v -> Pattern v -> Maybe (Pattern v)
forall v. GraphLens v -> Pattern v -> Maybe (Pattern v)
source GraphLens v
lens Pattern v
r, GraphLens v -> Pattern v -> Maybe (Pattern v)
forall v. GraphLens v -> Pattern v -> Maybe (Pattern v)
target GraphLens v
lens Pattern v
r) of
(Just Pattern v
s, Maybe (Pattern v)
_) | v -> Id v
forall v. GraphValue v => v -> Id v
identify (Pattern v -> v
forall v. Pattern v -> v
value Pattern v
s) Id v -> Id v -> Bool
forall a. Eq a => a -> a -> Bool
== Id v
nodeId -> Bool
True
(Maybe (Pattern v)
_, Just Pattern v
t) | v -> Id v
forall v. GraphValue v => v -> Id v
identify (Pattern v -> v
forall v. Pattern v -> v
value Pattern v
t) Id v -> Id v -> Bool
forall a. Eq a => a -> a -> Bool
== Id v
nodeId -> Bool
True
(Maybe (Pattern v), Maybe (Pattern v))
_ -> Bool
False
containingRels :: [Pattern v]
containingRels = (Pattern v -> Bool) -> [Pattern v] -> [Pattern v]
forall a. (a -> Bool) -> [a] -> [a]
filter Pattern v -> Bool
inRel (GraphLens v -> [Pattern v]
forall v. GraphLens v -> [Pattern v]
relationships GraphLens v
lens)
containingWalks :: [Pattern v]
containingWalks = (Pattern v -> Bool) -> [Pattern v] -> [Pattern v]
forall a. (a -> Bool) -> [a] -> [a]
filter
(\Pattern v
w -> (Pattern v -> Bool) -> [Pattern v] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (\Pattern v
r -> v -> Id v
forall v. GraphValue v => v -> Id v
identify (Pattern v -> v
forall v. Pattern v -> v
value Pattern v
r) Id v -> Id v -> Bool
forall a. Eq a => a -> a -> Bool
== Id v
nodeId) (Pattern v -> [Pattern v]
forall v. Pattern v -> [Pattern v]
elements Pattern v
w))
(GraphLens v -> [Pattern v]
forall v. GraphValue v => GraphLens v -> [Pattern v]
walks GraphLens v
lens)
in [Pattern v]
containingRels [Pattern v] -> [Pattern v] -> [Pattern v]
forall a. [a] -> [a] -> [a]
++ [Pattern v]
containingWalks
}
toGraphView
:: (GraphValue v, Eq v)
=> GraphClassifier extra v
-> GraphLens v
-> GraphView extra v
toGraphView :: forall v extra.
(GraphValue v, Eq v) =>
GraphClassifier extra v -> GraphLens v -> GraphView extra v
toGraphView GraphClassifier extra v
classifier GraphLens v
lens =
GraphView
{ viewQuery :: GraphQuery v
viewQuery = GraphLens v -> GraphQuery v
forall v. (GraphValue v, Eq v) => GraphLens v -> GraphQuery v
fromGraphLens GraphLens v
lens
, viewElements :: [(GraphClass extra, Pattern v)]
viewElements = (Pattern v -> (GraphClass extra, Pattern v))
-> [Pattern v] -> [(GraphClass extra, Pattern v)]
forall a b. (a -> b) -> [a] -> [b]
map (\Pattern v
p -> (GraphClassifier extra v -> Pattern v -> GraphClass extra
forall extra v.
GraphClassifier extra v -> Pattern v -> GraphClass extra
classify GraphClassifier extra v
classifier Pattern v
p, Pattern v
p)) [Pattern v]
scopeElems
}
where
GraphLens (Pattern v
_ [Pattern v]
scopeElems) Pattern v -> Bool
_ = GraphLens v
lens