Reputation: 753
I have a database containing used strategies in a game.
(strategy_1:Human) - [:BEATS] -> (strategy_1:Alien)
(strategy_2:Human) - [:BEATS] -> (strategy_1:Alien)
(strategy_3:Human) - [:LOSES] -> (strategy_1:Alien)
(strategy_4:Human) - [:DRAWS] -> (strategy_1:Alien)
(strategy_1:Human) - [:LOSES] -> (strategy_2:Alien)
(strategy_2:Human) - [:LOSES] -> (strategy_2:Alien)
(strategy_3:Human) - [:LOSES] -> (strategy_2:Alien)
(strategy_4:Human) - [:DRAWS] -> (strategy_2:Alien)
So a strategy of a Human can BEAT,DRAW or LOSE against a strategy of an Alien. I am trying to find all strategies which have equal relations, so BEAT,DRAW or LOSE against the same Alien strategies.
In the example case it would be strategy_1 and strategy_2. Right now I am going this way:
MATCH (strategyA:Human)-[r1]->(strategyB:Alien)<-[r2]-(strategyC:Human)
WHERE type(r1) = type(r2) AND NOT strategyA = strategyC
RETURN strategyA
But this will of course only give me all strategies with at least one matching relationship. How can I now make the step to test all relations of strategyA and strategyC against each other? Or is there a much easier way of doing this?
Upvotes: 0
Views: 60
Reputation: 9369
If you want collect all human strategies that are linked to an alien strategy with a given relationship type you can simply do:
MATCH (alien_strategy:Alien)
OPTIONAL MATCH (alien_strategy)<-[rel]-(human_strategy:Human)
RETURN alien_strategy, type(rel), collect(DISTINCT human_strategy)
This will list all alien strategies, the relationship types and the collected list of human strategies for each combination of alien strategy and relationship type.
Following your example the result would look like this:
strategy_1:alien, BEATS, [strategy_1:Human, strategy_2:Human]
strategy_2:alien, LOSES, [strategy_1:Human, strategy_2:Human, strategy_2:Human]
Upvotes: 1