Foreach is just iterating over a list and in this case creates a "cross-product".
instead of using foreach you can also use unwind, which turns collections back into rows, like this MATCH (entity:Entity)-[:LINKS_TO]->(doc:Document) WITH doc, collect(entity) as entities UNWIND entities as e1 UNWIND entities as e2 WHERE id(e2) > id(e1) RETURN e1,e2,doc > Am 25.04.2015 um 17:28 schrieb Dan <[email protected]>: > > Thanks Michael, that definitely works. > > A final question is there a way to do similar but to only return the links, > not create them? I see that FOREACH statement is apparently used to write to > database (update, create, etc). I was trying to see how to do similar but > only return the links (not actually create them in database). Not sure if > some nested EXTRACT statements would do it. Thanks. > > On Friday, April 24, 2015 at 10:40:23 PM UTC-4, Michael Hunger wrote: > ah, so what I said > > >> MATCH (entity:Entity)-[:LINKS_TO]->(doc:Document) >> WITH doc, collect(entity) as entities > FOREACH (e1 in entities | FOREACH (e2 in filter(e in entities WHERE > id(e) > id(e1)) | CREATE (e1)-[:RELATED_TO]->(e2))) > > Michael > >> Am 25.04.2015 um 04:33 schrieb Dan <ailee...@ <>gmail.com >> <http://gmail.com/>>: >> >> Thanks for info Michael. I believe that query will return the list of >> entities common to each document. What I’m really after is generating >> dynamically (via Cypher) a new graph result (relationships) comprised of >> only one node type derived from the underlying bipartite graph (two node >> types). >> >> e.g., >> >> http://image.slidesharecdn.com/pn2013-130704162301-phpapp01/95/sna-in-technologyenhanced-learning-a-shift-to-personal-network-perspective-using-clustered-graphs-9-638.jpg?cb=1373000400 >> >> <http://image.slidesharecdn.com/pn2013-130704162301-phpapp01/95/sna-in-technologyenhanced-learning-a-shift-to-personal-network-perspective-using-clustered-graphs-9-638.jpg?cb=1373000400> >> So if neo4j database includes links between entities and documents, I want >> to generate a new graph result that would just contain links between one >> entity type: entities to entities or documents to documents. These new >> dynamic (query time) links would be based on shared connections between >> entities and documents in the underlying graph database. >> >> So if E1 is linked to D1 and D2, E2 is linked to D1, and E3 is linked to D3, >> a Cypher query would return: >> >> 1) 1) For a entity only graph result: E1 linked to E2 and E3 by itself. >> >> 2) 2) For a document only graph result: D1 linked to D2 and D3 by >> itself. >> >> Thanks, Dan >> >> >> >> On Friday, April 24, 2015 at 9:04:43 PM UTC-4, Michael Hunger wrote: >> Do you mean something like this? >> >> MATCH (entity:Entity)-[:LINKS_TO]->(doc:Document) >> RETURN doc, collect(entity) as entities >> >> Michael >> >>> Am 25.04.2015 um 02:38 schrieb Dan <[email protected] <>>: >>> >>> I was wondering if it is possible to generate a single mode graph >>> projection from a bipartite (2-mode) graph via a Cypher query? >>> >>> e.g., >>> http://upload.wikimedia.org/wikipedia/commons/f/f9/Bipartite_network_projection.png >>> >>> <http://upload.wikimedia.org/wikipedia/commons/f/f9/Bipartite_network_projection.png> >>> So let's say I have text mining related data such as entities (X) linked to >>> documents (Y) in a neo4j graph database. And I want a query result set >>> that links X's to X's (for example) based on links to common Y's. Can such >>> be done via a Cypher query sequence? >>> >>> Thanks, Dan >>> >>> >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "Neo4j" group. >>> To unsubscribe from this group and stop receiving emails from it, send an >>> email to neo4j+un...@ <>googlegroups.com <http://googlegroups.com/>. >>> For more options, visit https://groups.google.com/d/optout >>> <https://groups.google.com/d/optout>. >> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Neo4j" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected] <>. >> For more options, visit https://groups.google.com/d/optout >> <https://groups.google.com/d/optout>. > > > -- > You received this message because you are subscribed to the Google Groups > "Neo4j" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected] > <mailto:[email protected]>. > For more options, visit https://groups.google.com/d/optout > <https://groups.google.com/d/optout>. -- You received this message because you are subscribed to the Google Groups "Neo4j" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
