How can I assign a node property value to a variable in Cypher?

TUrwin

We're trying to propagate a property on nodes with a specific label ("Concept") to connected nodes (with predicate "CONTAINS_OBJECT") as a new label, but are struggling to assign the property to a variable within the query. How can this be done assuming there will be multiple "Concept" nodes, with the assumption that no "Concept" nodes will have overlapping connections with other "Concept" nodes.

i.e. The following will never occur, where n0 and n1 are distinct:

(n0:Concept)-[:CONTAINS_OBJECT]->(o:Object)<-[:CONTAINS_OBJECT]-(n1:Concept)

Basically, how should this be done with Cypher?

Disclaimer: We're quite new to Cypher - any and all advice is appreciated.

We have tried a few more restricted queries but have had issues getting variable assignment working there as well.

This query achieved the desired result for a single specified "Concept" node:

    MATCH p = (c:Concept{ Name: 'Con0' })-[:CONTAINS_OBJECT]->(END)
    FOREACH (n in nodes(p) | SET n:Con0)

The following query was our attempt to bind the "Concept" node's 'Name' property to a variable", but 'p' isn't being assigned in this instance:

    MATCH p = (c:Concept{ Name: 'Con0' })-[:CONTAINS_OBJECT]->(END)
    WITH c.Name as conceptName
    FOREACH (n in nodes(p) | SET n:conceptName)

To simplify the result we're after as much as possible, the end result is that the following two MATCH statements should return the same results for any given "Concept" node:

1)

    MATCH (c:Concept{ Name: 'Con0' })-[:CONTAINS_OBJECT]->(o:Object)

2)

    MATCH (c:Concept{ Name: 'Con0' })-[:CONTAINS_OBJECT]->(o:Con0)

Looking to build a query along these lines:

    MATCH p = (c:Concept)-[:CONTAINS_OBJECT]->(END)
    WITH c.Name as conceptName
    FOREACH (n in nodes(p) | SET n:conceptName)
TUrwin

For anyone that comes to this post with similar requirements, we eventually came to the following query which got us exactly the result we were after:

call apoc.periodic.commit("MATCH (n:Concept)-[:CONTAINS_OBJECT]->(o:Object)
    WITH o, n, replace(n.Name, ' ', '_') as label limit {limit} call
    apoc.create.addLabels(o, [label]) yield node
    with node
    RETURN node",
{limit:100000});

Note that we have < 150 nodes labelled with "Concept", and had 'Name' fields containing spaces which we've replaced with underscores.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I assign the value of a variable using eval in python?

Can I assign a null value to an anonymous type property?

How to access and mutate node property value by the property name string in Cypher?

How can I assign a value to KMutableProperty parameter?

How can I count the number of relationships each node has in Cypher?

How can I assign a value to a property of a static object inside a static class?

How can I assign the value to pointer?

How can I assign a value inside a loop?

How can I assign a value to a constant variable (not in declaration)?

How can I assign values with mypy and @property?

How can I use a class property index to assign a variable?

How can I assign by value in python

How can I assign Cell Part as Variable?

How can I assign an element to variable?

Oracle PL/SQL: How can i assign &value to local variable

Can I instantiate a variable but assign a value to value later?

How can I assign a property value using 'With {...}' syntax?

How can I assign variable from json?

How can I assign a variable to a value in a dictionary in Python?

How can i use a variable value to call an object property?

In SwiftUI how can I assign variable in view?

How can I assign element count to the variable?

Why can't I assign the value of property in this case?

How can i assign data as variable in node?

How can I define a Neo4j node property from 2 possible paths with a cypher query?

How can I assign a value to a variable of a callable type?

How can I assign a variable with the value of another variable in Kotlin?

Can not assign value to a variable

How can I delete relationships belonging to a node using Cypher in Memgraph?