Reputation: 11
I am new to graph database and stuck with the following issue. I'm trying to store below conditional information in the graph.
when a=1 and b=2 then sum=3
, when a=2 and b=3 then sum=5 and mul=6
4 pre-conditions[(a=1, b=2),(a=2, b=3)]
, 3 post conditions(sum=3,sum=5,mul=6)
The number of pre/post conditions can change from sentence to sentence.Or please do suggest any other scalable way to store such info which can be easily queried.
Upvotes: 1
Views: 59
Reputation: 16033
One option is to use something like this graph, only Input
, Cond
and Res
nodes:
MERGE (a:Input{key: 'a', value: 2})
MERGE (b:Input{key: 'b', value: 1})
MERGE (c:Res{key: 'sum', value: 5})
MERGE (d:Input{key: 'a', value: 7})
MERGE (e:Res{key: 'sum', value: 19})
MERGE (a)-[:POINTS]-(c)
MERGE (b)-[:POINTS]-(c)
MERGE (d)-[:POINTS]-(e)
MERGE (b)-[:POINTS]-(e)
With a result from a query like this:
MATCH (n:Res{key: 'sum'})<-[:POINTS]-(a:Input{key: 'a', value: 2})
WITH n
MATCH (n)<-[:POINTS]-(b:Input{key: 'b', value: 1})
WITH n
MATCH (n)<--(p:Input)
WITH n, COUNT(p) as inputCount
WHERE inputCount=2
RETURN n
Or:
MATCH (res:Res)<--(i:Input)
WITH res, count(i) as inputCount
WHERE EXISTS {MATCH (res)<--(Input{key: 'a', value: 2})}
AND EXISTS {MATCH (res)<--(Input{key: 'b', value: 1})}
AND inputCount=2
RETURN res
But keep in mind that this works for 'AND' conditions only
Upvotes: 0