CIR-2017-186
It would be useful to add the notion of query approximation to Cypher. This is particularly relevant when the underlying data is complex, and the user either is not familiar with the underlying graph, or wishes to gain further insights into the data.
A prerequisite would be the inception of Regular Path Queries (RPQs) into Cypher, as detailed in CIR-2017-179.
In this context, query approximation when applied to RPQs extends the idea of regular expression matching by including a set of edit operations - enumerated below - that may be applied to the relationship types making up the language of the regular expression.
Let R be the regular expression in the path pattern, and let A be the alphabet of all relationship types in the graph. The proposed edit operations include:
-
inserting a relationship type r (taken from A) into R
-
deleting a relationship type from R
-
substituting a relationship type r in R with another relationship type r' (taken from A) where r <> r'
Each edit operation has an associated configurable cost, which is some integer >= 0.
Each application of an edit operation to a sequence of relationship types in the language of R increases the 'distance' from the original sequence by the cost configured for the edit operation.
Answers obtained at greater distances are ranked lower than ones exactly matching R, as well as those obtained at a smaller distance. Therefore, exact answers are returned first, followed by answers corresponding to ever-increasing distances.
It is advisable that these queries are provided with a limit, or maximum distance, in order to not return the whole graph.
Examples
Assume R = a*.b.c, and assume A = {a, b, c, d} (the set of all relationship types in the graph).
Insertion operation (assume a cost of 1)
-
d can be inserted between b and c to form R' = a*.b.d.c at a cost of 1. So, all answers would be returned at a distance of 1, after the answers for R.
-
b can be inserted before a in R', giving rise to R'' = b.a*.b.d.c at a cost of 1, yielding a total cost of 2. This means all answers to R'' would be returned at a distance of 2, after the answers for R' and R.
Deletion operation (assume a cost of 1)
-
c can be deleted from R to give rise to R' = a*.b at a cost of 1. All answers would be returned at a distance of 1, after the answers for R.
-
Note that removing a from R would have no effect owing to the presence of the Kleene operator.
Substitution operation (assume a cost of 1)
a can be substituted with d giving rise to the following variants (owing to the Kleene operator): d.a*.b.c, a*.d.b.c, a*.d.a*.b.c, all at a cost of 1.
Insertion & substitution operations (assume a cost of 1 for insertion, and 2 for deletion)
-
d is inserted between b and c to form R' = a*.b.d.c at a cost of 1
-
c substituted by a in R' to form R'' = a*.b.d.a at a cost of 2
-
Therefore, answers corresponding to R'' will be returned at a distance of 3
CIR-2017-186
It would be useful to add the notion of query approximation to Cypher. This is particularly relevant when the underlying data is complex, and the user either is not familiar with the underlying graph, or wishes to gain further insights into the data.
A prerequisite would be the inception of Regular Path Queries (RPQs) into Cypher, as detailed in CIR-2017-179.
In this context, query approximation when applied to RPQs extends the idea of regular expression matching by including a set of edit operations - enumerated below - that may be applied to the relationship types making up the language of the regular expression.
Let
Rbe the regular expression in the path pattern, and letAbe the alphabet of all relationship types in the graph. The proposed edit operations include:inserting a relationship type
r(taken fromA) intoRdeleting a relationship type from
Rsubstituting a relationship type
rinRwith another relationship typer'(taken fromA) wherer<>r'Each edit operation has an associated configurable cost, which is some integer >= 0.
Each application of an edit operation to a sequence of relationship types in the language of
Rincreases the 'distance' from the original sequence by the cost configured for the edit operation.Answers obtained at greater distances are ranked lower than ones exactly matching
R, as well as those obtained at a smaller distance. Therefore, exact answers are returned first, followed by answers corresponding to ever-increasing distances.It is advisable that these queries are provided with a limit, or maximum distance, in order to not return the whole graph.
Examples
Assume
R = a*.b.c, and assumeA = {a, b, c, d}(the set of all relationship types in the graph).Insertion operation (assume a cost of 1)
dcan be inserted betweenbandcto formR' = a*.b.d.cat a cost of1. So, all answers would be returned at a distance of1, after the answers forR.bcan be inserted beforeainR', giving rise toR'' = b.a*.b.d.cat a cost of1, yielding a total cost of2. This means all answers toR''would be returned at a distance of2, after the answers forR'andR.Deletion operation (assume a cost of 1)
ccan be deleted fromRto give rise toR' = a*.bat a cost of1. All answers would be returned at a distance of1, after the answers forR.Note that removing
afromRwould have no effect owing to the presence of the Kleene operator.Substitution operation (assume a cost of 1)
acan be substituted withdgiving rise to the following variants (owing to the Kleene operator):d.a*.b.c,a*.d.b.c,a*.d.a*.b.c, all at a cost of1.Insertion & substitution operations (assume a cost of 1 for insertion, and 2 for deletion)
dis inserted betweenbandcto formR' = a*.b.d.cat a cost of1csubstituted byainR'to formR'' = a*.b.d.aat a cost of2Therefore, answers corresponding to
R''will be returned at a distance of3