Hi guys!
I have nodes of types Subject , Object and verbs as relations
verb relation has a property of type list called Synonyms = ["syn1", "syn2","syn3"]
I want to get all nodes of type Subject that are related to Object by any relationship that has a name == passed verb or one of its synonyms that are passed through the query as a list ( i get them from an ontology).
So I need to get the intersection between the passed list and the relation property Synonyms list.
if result is not empty return the Subject What is the best way to do that please?
Something similar to this pseudocode
MATCH (s:Subject)-[r]->(o:Object)
with r
call apoc.coll.intersection(r.synonyms, ["make", "do"]) as res
if res is not empty
RETURN s.name
r.synonyms is not a collection. First you have to collect all distinct r.synonyms
with collect(distinct r.synonyms) as synonyms
call apoc.coll.intersection(synonyms, ["make", "do"]) as res
I am still learning while creating my project. Please, according to your experience, which of the two solutions is better in terms of speed and computational complexity, assuming that the size of the data is much larger?
I would think the list predicate approach, as it will stop searching once one element in the first list is found in the second list. All elements in one list need to be compared to the other list to determine the intersection, so once a first element is found to be in the intersection the algorithm will continue instead of stopping.
Another benefit is you do not have a dependency on the APOC library.
If it is known a priori, set the smaller list as the one that the list predicate function iterates over. That may help performance if the is a large difference in the size of the two lists.