path query patterns
play

Path Query Patterns CIP2017-02-06 a.k.a. (Conjunctive) Regular Path - PowerPoint PPT Presentation

Path Query Patterns CIP2017-02-06 a.k.a. (Conjunctive) Regular Path Queries Regular expressions over Graphs Tobias Lindaaker tobias@neotechnology.com opencypher.org | opencypher@googlegroups.com opencypher.org |


  1. Path Query Patterns CIP2017-02-06 a.k.a. (Conjunctive) Regular Path Queries “Regular expressions over Graphs” Tobias Lindaaker tobias@neotechnology.com opencypher.org | opencypher@googlegroups.com opencypher.org | opencypher@googlegroups.com

  2. Find complex connections MATCH (a)-[~cousin]-(b) MATCH (me)-[:ALLY | [:ENEMY :ENEMY]]-(friend) MATCH (x)-[[:A :B]+ :C+ [:B :A]*]->(y) MATCH p = (a)-[[:KNOWS | :LOVES]+]->() opencypher.org | opencypher@googlegroups.com

  3. Syntax design philosophy ● Reuse and extend existing syntax ● Direct notation for common simple patterns ● Allow for complex patterns ● Avoid repetition and ceremony opencypher.org | opencypher@googlegroups.com

  4. Improved since last time ● Shorthand syntax for node labels! ● Shorthand syntax for matching any edge! ● Shorthand syntax for property predicates! ● Declared Path Patterns are scoped per query And declared at the head of the query ● Non-repetitive syntax for Declared Path Patterns opencypher.org | opencypher@googlegroups.com

  5. Composition of Patterns Regular Expressions over Paths ● Sequence / Concatenation: ()-[ � � ]-() ● Alternative / Disjunction: ()-[ � | � ]-() ● Transitive closure: ()-[ � *]-() // zero or more times ()-[ � +]-() // one or more times ()-[ � *n..]-() // n or more times ()-[ � *n..m]-() // at least n , at most m ● Overriding direction for sub-pattern: ()-[< � ]-() ()-[ � >]-() ()-[< � >]-() opencypher.org | opencypher@googlegroups.com

  6. Predicates for Path Patterns ● Edge Label ()-[:KNOWS]-() ● Node Label ()-[(:Person)]-() ● Edge Properties ()-[:ROAD{length:12}]-() ● Node Properties ()-[({year:2017})]-() ● Edges with any label, and matching empty path ()-[-]-() ()-[()]-() ● Grouping of expressions ()-[[:KNOWS :LOVES]+]-() opencypher.org | opencypher@googlegroups.com

  7. Declared Path Patterns ● Referenced using ~ MATCH (a)-[~my_pattern]-(b) ● Declaration: PATH PATTERN my_pattern = ()-[:FOO :BAR* :BAZ]-() ● Makes the pattern language Context Free opencypher.org | opencypher@googlegroups.com

  8. Advanced property tests ● PATH PATTERN same_color_nodes = (a)-[-]-(b) WHERE a.color = b.color MATCH (x)-[~same_color_nodes+]-(y) ● PATH PATTERN older_friends = (a)-[:KNOWS]-(b) WHERE b.birthday < a.birthday opencypher.org | opencypher@googlegroups.com

  9. Conjunctive Path Queries ● PATH PATTERN friends_in_same_city = (a)-[:KNOWS]-(b) WHERE EXISTS { (a)-[:LIVES_IN]->()<-[:LIVES_IN]-(b) } ● One pattern must be designated the main pattern ● Other patterns are put in WHERE ● The main pattern is presented when binding a matched path: MATCH friendships = (a)-[~friends_in_same_city+]-() opencypher.org | opencypher@googlegroups.com

  10. Balanced Path Matching Classic Context Free use case // treats siblings as “zeroth cousin” PATH PATTERN cousin = ()-[:PARENT> [() | ~cousin] <:PARENT]-() MATCH rel=(me)-[~cousin]-(cus) WHERE length(rel) > 2 // filter away siblings opencypher.org | opencypher@googlegroups.com

  11. Expressive power compared to academic languages ● Covers all of GXPath - except negation ● Weaker scoping reach than Regular Expressions with Memory ○ Variables only reach within single Declared Path Pattern ● Defines a Context Free Language over paths rather than just a Regular Language ● More sophisticated data tests than GXPath opencypher.org | opencypher@googlegroups.com

  12. Sophisticated data test PATH PATTERN same_pet_name = (a)-[:KNOWS]-(b) WHERE EXISTS { MATCH (a)-[:OWNS]-(petA:Animal), (b)-[:OWNS]-(petB:Animal) WHERE petA.name = petB.name } MATCH peculiar_friends = (x)-[~same_pet_name*]-() opencypher.org | opencypher@googlegroups.com

  13. Alternative syntax ideas ● Differentiate between single edge and path MATCH (a)-[single:EDGE]-(and_a)-/~path*/-() ● Single edge matching allows variable binding ● Binding a path results in a whole path value bound opencypher.org | opencypher@googlegroups.com

  14. Next steps “Battle testing” ● Prototype implementation ● Try to express interesting queries ○ Needs to find / define interesting queries ● Measure up against “yardstick queries” ● Academic evaluation of ○ expressive power ○ computational complexity opencypher.org | opencypher@googlegroups.com

  15. Yardstick queries that I have not yet been able to express ● Paths where the property value differs in all nodes ○ quite possibly not tractable ● Paths where the property value in all subsequent nodes differs from the first node opencypher.org | opencypher@googlegroups.com

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend