Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
02-23-2022 11:42 AM
Hi,
Have a question about being able to constrain the nodes included in a variable length match.
Match p= (a:owner)-[:Has]->(b:document)-[:Cites*1..]->(d:document)<-[:Has]-(a)
In the path within the variable length relationship [:Cites], I would like to limit the nodes to also satisfy (a)-[:Has]-(intermediate node). The goal is to limit all document nodes to those that also satisfy a relationship of [:Has] with node (a:owner).
Is there a way to add that constraint to the match?
Andy
Solved! Go to Solution.
03-02-2022 08:37 PM
Just as a note, you don't need the final 'has' relationship with the new constraint, since you are requiring each document node to have a 'has' relationship to 'a'. Thus, the following should provide the same result:
match p = (a:owner)-[:Has]->(:document)-[:Cites*1..]->(:document)
with p, a, [i in nodes(p) where i:document] as docNodes
where all (i in docNodes where exists((a)-[:Has]->(i)))
return p
It seems that all that is occurring here, is finding a trail of document citations among a single author's papers.
02-28-2022 12:47 AM
Hi Andy, it is possible to access the nodes in path p with nodes(p). That function returns a list of nodes.
However, albeit without knowing what you are trying to achieve, your approach seems overly complicated to me and this filtering will most likely not be fast.
03-02-2022 05:10 PM
They pattern seems to say:
(a:owner)
:document
node via the ;Has
relationship to :document
'b' that :Cities
r :document
'd' -[:Has]->(b:document)-[:Cites*1..]->(d:document)
:document
'd' is also connected to the node represented by 'a' via a :Has
relationship.
03-02-2022 05:31 PM
I agree with others that maybe we can come up with a more efficient approach if we know more about your requirements. In the meantime, the following query should do what you want. Sorry I don't have data to test it out.
match p = (a:owner)-[:Has]->(:document)-[:Cites*1..]->(:document)<-[:Has]-(a)
with p, a, [i in nodes(p) where i:document] as docNodes
where all (i in docNodes where exists((a)-[:Has]->(i)))
return p
03-02-2022 08:37 PM
Just as a note, you don't need the final 'has' relationship with the new constraint, since you are requiring each document node to have a 'has' relationship to 'a'. Thus, the following should provide the same result:
match p = (a:owner)-[:Has]->(:document)-[:Cites*1..]->(:document)
with p, a, [i in nodes(p) where i:document] as docNodes
where all (i in docNodes where exists((a)-[:Has]->(i)))
return p
It seems that all that is occurring here, is finding a trail of document citations among a single author's papers.
03-03-2022 08:16 AM
Hi,
You are correct in that I am looking for the document trail and in the data set there are links from child to grandparent or even great grandparent. My goal is be able to create a view that isolates the distinct chain of direct parent0child relationships. I am tracking the specific evolution of the document or really the concepts within the document and need to isolate each step. For example what new phrases or terms were added with each generation. I also want to reduce the visual clutter in a representation of the path to the user so they can understand the changes. For my data set this analysis of the path is on a slowly growing data set and only needs to be done once for each document added so I am nodding the result to a property. In y case I add an 'inherited" boolean property to relationships that are also described by the natural evolution of the document.
An alternative approach I have also used is to create a temporary relationship that captures only documents by that specific author and craft a query based on that and then delete that relationship.
Andy
All the sessions of the conference are now available online