(Neo4j)-[:          ]->Cypher   Michael Hunger - Neo Technology                                     1
(Michael) -[:WORKS_ON]-> (Neo4j)                                         consoleCypher             community              ...
3
is a       4
NOSQL       Neo4j        5
Graph Database                 6
7
Were talking about aProperty Graph                        7
Were talking about aProperty Graph     Nodes                        7
Were talking about aProperty Graph     Nodes      Relationships                        7
Were talking about aProperty Graph                                             Em                                       Jo...
7
8
(Neo4j) -[:IS_A]-> (Graph Database)                                                                                       ...
How do you query this  graph database?                   10
With a Graph Query     Language:     Cypher                 11
What is Cypher?๏Pattern-Matching Query Language๏Humane language๏Expressive๏Declarative: Say what you want, not how๏borrows...
Something new? Why?๏ Existing Neo4j query mechanisms were not simple enough   • Too verbose (Java API)   • Too prescriptiv...
A GraphCan‘t see the Patterns for the Trees               http://maxdemarzi.com/2012/02/13/visualizing-a-network-with-cyph...
It‘s all about Patterns                 A             B       CWe want to find this Pattern!                               15
Patterns in a Graph                      16
17
18
19
20
Patterns as ASCII-ART                   21
Patterns as ASCII-ART   () --> ()                   21
Named Nodes A      B              22
Named Nodes A      B(A) --> (B)              22
Named Directed Rels        LOVES    A           B                    23
Named Directed Rels        LOVES    A           B   A -[:LOVES]-> B                     23
PathsA     B     C                24
PathsA     B     CA --> B --> C                24
Cyclic-Path-Patterns          A      B       C                   25
Cyclic-Path-Patterns           A       B       CA --> B --> C, A --> C                     25
Cyclic-Path-Patterns           A       B       CA --> B --> C, A --> C A --> B --> C <-- A                     25
Variable Length Paths        A     B    A             BA                      B        ...    A -[*]-> B        26
Optional Relationships     A         B                    27
Optional Relationships     A         B   A -[?]-> B                    27
28
How does it work?                    28
How does it work?                    28
How does it work?// lookup starting point in an indexstart n=node:People(name = ‘Andreas’)                        And     ...
How does it work?// lookup starting point in an index   then traverse to find resultsstart n=node:People(name = ‘Andreas’)...
28
The Parts of Cypher                  29
30
Cypher: START + RETURN๏ START <lookup> RETURN <expressions>๏ START binds terms using simple look-up   •directly using know...
Cypher: START + RETURN๏ START <lookup> RETURN <expressions>๏ START binds terms using simple look-up   •directly using know...
31
Cypher: MATCH๏ START <lookup> MATCH <pattern> RETURN <expr>๏ MATCH describes a pattern of nodes+relationships   •node term...
Cypher: MATCH๏ START <lookup> MATCH <pattern> RETURN <expr>๏ MATCH describes a pattern of nodes+relationships   •node term...
32
Cypher: RETURN๏ RETURN <expressions>, aggregation(expr) as alias๏ RETURN nodes, rels, properties๏ RETURN expressions of fu...
Cypher: RETURN๏ RETURN <expressions>, aggregation(expr) as alias๏ RETURN nodes, rels, properties๏ RETURN expressions of fu...
33
Cypher: WHERE๏ START <lookup> [MATCH <pattern>] WHERE <condition> RETURN <expr>๏ WHERE filters nodes or relationships   •us...
Cypher: WHERE๏ START <lookup> [MATCH <pattern>] WHERE <condition> RETURN <expr>๏ WHERE filters nodes or relationships   •us...
34
Cypher: CREATE๏ CREATE <node>[,node or relationship] RETURN <expr>  •create nodes with optional properties  •create relati...
Cypher: CREATE๏ CREATE <node>[,node or relationship] RETURN <expr>  •create nodes with optional properties  •create relati...
35
Cypher: CREATE UNIQUE๏ CREATE UNIQUE node-[rel]->(node {prop : value})   •„fixes“ the graph   •starts at bound nodes, prope...
Cypher: CREATE UNIQUE๏ CREATE UNIQUE node-[rel]->(node {prop : value})   •„fixes“ the graph   •starts at bound nodes, prope...
36
Cypher: SET๏ SET [<node property>] [<relationship property>]   •update a property on a node or relationship   •must follow...
Cypher: SET๏ SET [<node property>] [<relationship property>]   •update a property on a node or relationship   •must follow...
37
Cypher: DELETE๏ DELETE [<node>|<relationship>|<property>]  •delete a node, relationship or property  •toall relationships ...
Cypher: DELETE๏ DELETE [<node>|<relationship>|<property>]  •delete a node, relationship or property  •toall relationships ...
More Advanced  Examples                38
START user = node(1)                                           MATCH user -[user_skill]-> skill                           ...
Example:               Old, Influential FriendsSTART me = node(...)MATCH (me) - [f:FRIEND] - (old_friend)           - [:FR...
Example:                     Simple RecommendationSTART me = node(...)MATCH (me) -[r1:RATED   ]->(thing)          <-[r2:RA...
Cypher Cheat Sheet             http://neo4j.org/resources/cypher                                       42
The Rabbithole                  http://console.neo4j.org                 This Graph: http://tinyurl.com/7cnvmlq           ...
How to use Cypherin YOUR programs                44
Neo4j API ExecutionEngine engine = new ExecutionEngine(graphDB); String query = „start n=node:Person(name={name})  match n...
How to get started?                      46
How to get started?๏ Documentation                      46
How to get started?๏ Documentation    • docs.neo4j.org - tutorials+reference                                             46
How to get started?๏ Documentation    • docs.neo4j.org - tutorials+reference    • http://console.neo4j.org                ...
How to get started?๏ Documentation    • docs.neo4j.org - tutorials+reference    • http://console.neo4j.org    • Neo4j in A...
How to get started?๏ Documentation    • docs.neo4j.org - tutorials+reference    • http://console.neo4j.org    • Neo4j in A...
How to get started?๏ Documentation    • docs.neo4j.org - tutorials+reference    • http://console.neo4j.org    • Neo4j in A...
How to get started?๏ Documentation    • docs.neo4j.org - tutorials+reference    • http://console.neo4j.org    • Neo4j in A...
How to get started?๏ Documentation    • docs.neo4j.org - tutorials+reference    • http://console.neo4j.org    • Neo4j in A...
How to get started?๏ Documentation    • docs.neo4j.org - tutorials+reference    • http://console.neo4j.org    • Neo4j in A...
http://console.neo4j.org/r/GoThttps://dl.dropbox.com/u/14493611/got.txt                                        47
Neo4j-JDBC Driver & MovieDB Datasethttp://blog.neo4j.org/2012/06/wanted-your-       help-in-testing-neo4j-jdbc.html       ...
Got a Conference? Need a Dataset?http://blog.neo4j.org/2012/08/at-conference-          need-dataset-neo4j-at.html         ...
Neo4j in ActionSoftware Metrics                   50
Graphs in Software Technolgoy๏ UML Diagrams are graphs๏ dependencies between classes, packages, modules etc are graphs๏ So...
Code City            52
Class Diagram is a Graph                           53
SonarJ         54
But there is more๏Visualize & query Method, Field   dependencies๏Collaborative filtering (co-usage)๏Ranking๏God classes๏Pat...
Welcome to Class-Graph๏take a JAR๏put it under ASM๏scan it superfast๏pull everything into Neo4j๏add categories, indexes๏Ha...
Welcome to Class-Graph                         57
Interactive Hands-On Session๏Lots of tasks๏use Cypher to solve them   http://neo4j.org/resources/cypher๏be creative, work ...
Task: Find java.lang.Number and return it                                            59
Task: Find java.lang.Number and return itSTART o=node:types(name="java.lang.Number") RETURN o;                            ...
Task: Subclasses of Number?•Return just the name•Order them alphabetically                              60
Task: Subclasses of Number?START n=node:types(name="java.lang.Number")  MATCH n<-[:SUPER_TYPE]-s RETURN s.name ORDER BY s....
Task: Which Methods does it have / how many•Find the top 5 classes with the most members                                  ...
Task: Which Methods does it have / how manySTART n=node:types(name="java.lang.Number") MATCH n-[:METHOD_OF|FIELD_OF]->mRET...
Task: Calculate the fan-out ofjava.lang.StringBuilder•Calculate fan-in•Which class has the highest fan-out•What about pack...
Task: Calculate the fan-out of java.lang.StringBuilderSTART o=node:types(name="j.l.StringBuilder")MATCH o-[:FIELD_OF]->f-[...
Task: Find longest Inheritance Path                                      63
Task: Find longest Inheritance Pathstart c=node:types(name="java.lang.Object") match path=p<-[:SUPER_TYPE*]-c return extra...
Task: Find the class that used IOExceptionmost often                                             64
Task: Find the class that used IOExceptionmost oftenSTART ex=node:types(name="java.io.IOException"MATCH ex<-[:THROWS]-m<-[...
Task: Which other classes did classes that threw IOException use most often?•What could be a source of IOExceptions       ...
Task: Which other classes did classes that threw IOException use most often?START ex=node:types(name="java.io.IOException"...
Task: Find a class you like and add a field withyour name and some type                                            66
Task: Find a class you like and add a field with your name and some typeSTART c=node:types(name="void"), t=node:types(name=...
Task: Delete the most annoying class and all itsmethods, fields and their relationships                                    ...
Task: Delete the most annoying class and all its methods, fields and their relationshipsSTART c=node:types(name="java.awt.L...
Upcoming SlideShare
Loading in...5
×

Intro to Cypher

3,435

Published on

Putting your data in a graph database is easy. We wanted to make it as easy to query the data. That's why we set out to create the cypher query language. This session introduces cypher shows a lot of examples and explains how it is used.

Published in: Technology
1 Comment
14 Likes
Statistics
Notes
  • Hello,

    Thanks so much for adding the presentation.

    Although, I've been having a awful time trying to view it.
    First, the suffix was .key.
    I changed this to .ppt, but I still get errors.
    Now it won't open.

    How can I get a simple and reliable PDF?

    Thanks a lot!

    Rodger
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
3,435
On Slideshare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
244
Comments
1
Likes
14
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • There existed a number of different ways to query a graph database. This one aims to make querying easy, and to produce queries that are readable.\n\nWe looked at alternatives - SPARQL, SQL, Gremlin and other...\n
  • There existed a number of different ways to query a graph database. This one aims to make querying easy, and to produce queries that are readable.\n\nWe looked at alternatives - SPARQL, SQL, Gremlin and other...\n
  • There existed a number of different ways to query a graph database. This one aims to make querying easy, and to produce queries that are readable.\n\nWe looked at alternatives - SPARQL, SQL, Gremlin and other...\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • There existed a number of different ways to query a graph database. This one aims to make querying easy, and to produce queries that are readable.\n\nWe looked at alternatives - SPARQL, SQL, Gremlin and other...\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • There existed a number of different ways to query a graph database. This one aims to make querying easy, and to produce queries that are readable.\n\nWe looked at alternatives - SPARQL, SQL, Gremlin and other...\n
  • \n
  • \n
  • 3rd minute\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • 5th minute\n
  • \n
  • Life-Console\n&amp;#x2022;In Memory GDBs in Web Session\n&amp;#x2022;Set up with mutating Cypher (or Geoff)\n&amp;#x2022;Executes Cypher (also mutating)\n&amp;#x2022;Visualizes Graph &amp; Query Results (d3)\n&amp;#x2022;Multiple Cypher Versions\n&amp;#x2022;Share: short link, tweet, yUML\n&amp;#x2022;Embeddable &lt;iframe&gt;\n&amp;#x2022;Live Console for Docs\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Intro to Cypher

    1. 1. (Neo4j)-[: ]->Cypher Michael Hunger - Neo Technology 1
    2. 2. (Michael) -[:WORKS_ON]-> (Neo4j) consoleCypher community graph Community MEServer Spring Cloud 2
    3. 3. 3
    4. 4. is a 4
    5. 5. NOSQL Neo4j 5
    6. 6. Graph Database 6
    7. 7. 7
    8. 8. Were talking about aProperty Graph 7
    9. 9. Were talking about aProperty Graph Nodes 7
    10. 10. Were talking about aProperty Graph Nodes Relationships 7
    11. 11. Were talking about aProperty Graph Em Joh il a n knows knows Alli Tob Lar Nodes son ias knows s knows And And knows knows rea rés s knows knows knows Pet Miic Mc knows Ian er knows a a knows knows De Mic lia h ael Relationships Properties (each a key+value) + Indexes (for easy look-ups) 7
    12. 12. 7
    13. 13. 8
    14. 14. (Neo4j) -[:IS_A]-> (Graph Database) LuceneSharding 1 M/s Master/ Index LS Slave TRAVERSA HIG TES H_A VA RA G IL. TE IN PROVIDES ACID Server RUN S_A LI TX S CE NS ED _L ES_T Ruby IK RU JS E MySQL S _A NS SC AL OClojure _O NS .net RU N Mongo 34bn embedded Heroku Nodes 9
    15. 15. How do you query this graph database? 10
    16. 16. With a Graph Query Language: Cypher 11
    17. 17. What is Cypher?๏Pattern-Matching Query Language๏Humane language๏Expressive๏Declarative: Say what you want, not how๏borrows from well known query langs๏Aggregation, Ordering, Limit๏Update the Graph 12
    18. 18. Something new? Why?๏ Existing Neo4j query mechanisms were not simple enough • Too verbose (Java API) • Too prescriptive (Gremlin)๏ SQL: Unable to express paths • these are crucial for graph-based reasoning • Neo4j is schema/table free๏ SPARQL: designed for a different data model • namespaces • properties as nodes 13
    19. 19. A GraphCan‘t see the Patterns for the Trees http://maxdemarzi.com/2012/02/13/visualizing-a-network-with-cypher/ 14
    20. 20. It‘s all about Patterns A B CWe want to find this Pattern! 15
    21. 21. Patterns in a Graph 16
    22. 22. 17
    23. 23. 18
    24. 24. 19
    25. 25. 20
    26. 26. Patterns as ASCII-ART 21
    27. 27. Patterns as ASCII-ART () --> () 21
    28. 28. Named Nodes A B 22
    29. 29. Named Nodes A B(A) --> (B) 22
    30. 30. Named Directed Rels LOVES A B 23
    31. 31. Named Directed Rels LOVES A B A -[:LOVES]-> B 23
    32. 32. PathsA B C 24
    33. 33. PathsA B CA --> B --> C 24
    34. 34. Cyclic-Path-Patterns A B C 25
    35. 35. Cyclic-Path-Patterns A B CA --> B --> C, A --> C 25
    36. 36. Cyclic-Path-Patterns A B CA --> B --> C, A --> C A --> B --> C <-- A 25
    37. 37. Variable Length Paths A B A BA B ... A -[*]-> B 26
    38. 38. Optional Relationships A B 27
    39. 39. Optional Relationships A B A -[?]-> B 27
    40. 40. 28
    41. 41. How does it work? 28
    42. 42. How does it work? 28
    43. 43. How does it work?// lookup starting point in an indexstart n=node:People(name = ‘Andreas’) And rea s 28
    44. 44. How does it work?// lookup starting point in an index then traverse to find resultsstart n=node:People(name = ‘Andreas’) match (n)--()--(foaf) return foaf And rea s 28
    45. 45. 28
    46. 46. The Parts of Cypher 29
    47. 47. 30
    48. 48. Cypher: START + RETURN๏ START <lookup> RETURN <expressions>๏ START binds terms using simple look-up •directly using known ids •or based on indexed Property๏ RETURN expressions specify result set 30
    49. 49. Cypher: START + RETURN๏ START <lookup> RETURN <expressions>๏ START binds terms using simple look-up •directly using known ids •or based on indexed Property๏ RETURN expressions specify result set // lookup node id 0, return that node start n=node(0) return n // lookup node in Index, return that node start n=node:Person(name="Andreas") return n // lookup all nodes, return all name properties start n=node(*) return n.name 30
    50. 50. 31
    51. 51. Cypher: MATCH๏ START <lookup> MATCH <pattern> RETURN <expr>๏ MATCH describes a pattern of nodes+relationships •node terms in optional parenthesis •lines with arrows for relationships 31
    52. 52. Cypher: MATCH๏ START <lookup> MATCH <pattern> RETURN <expr>๏ MATCH describes a pattern of nodes+relationships •node terms in optional parenthesis •lines with arrows for relationships // lookup n, traverse any relationship to some m start n=node(0) match (n)--(m) return n,m // any outgoing relationship from n to m start n=node(0) match n-->m return n,m // only KNOWS relationships from n to m start n=node(0) match n-[:KNOWS]->m return n,m // from n to m and capture the relationship as r start n=node(0) match n-[r]->m return n,r,m // from n outgoing to m, then incoming from o start n=node(0) match n-->m<--o return n,m,o 31
    53. 53. 32
    54. 54. Cypher: RETURN๏ RETURN <expressions>, aggregation(expr) as alias๏ RETURN nodes, rels, properties๏ RETURN expressions of functions and operators๏ RETURN aggregation functions on the above 32
    55. 55. Cypher: RETURN๏ RETURN <expressions>, aggregation(expr) as alias๏ RETURN nodes, rels, properties๏ RETURN expressions of functions and operators๏ RETURN aggregation functions on the above // aggregate on n, count the m‘s start n=node(0) match n--m return n,count(*) // alias n.name as name start n=node(0) return n.name as name // aggregate m‘s into list start n=node(*) match n--m return n,collect(m) // filter m‘s by name start n=node(*) match n--m return n,filter(x in collect(m): m.name ˜= /A.*/) as a_block 32
    56. 56. 33
    57. 57. Cypher: WHERE๏ START <lookup> [MATCH <pattern>] WHERE <condition> RETURN <expr>๏ WHERE filters nodes or relationships •uses expressions to constrain elements 33
    58. 58. Cypher: WHERE๏ START <lookup> [MATCH <pattern>] WHERE <condition> RETURN <expr>๏ WHERE filters nodes or relationships •uses expressions to constrain elements // lookup all nodes as n, constrained to name Andreas start n=node(*) where n.name=Andreas return n // filter nodes where age is less than 30 start n=node(*) where n.age<30 return n // filter using a regular expression start n=node(*) where n.name =~ /Tob.*/ return n // filter for a property exists start n=node(*) where has(n.name) return n 33
    59. 59. 34
    60. 60. Cypher: CREATE๏ CREATE <node>[,node or relationship] RETURN <expr> •create nodes with optional properties •create relationship (must have a type) 34
    61. 61. Cypher: CREATE๏ CREATE <node>[,node or relationship] RETURN <expr> •create nodes with optional properties •create relationship (must have a type) // create an anonymous node create n // create node with a property, returning it create n={name:Andreas} return n // lookup 2 nodes, then create a relationship and return it start n=node(0),m=node(1) create n-[r:KNOWS]-m return r // lookup nodes, then create a relationship with properties start n=node(1),m=node(2) create n-[r:KNOWS {since:2008}]->m 34
    62. 62. 35
    63. 63. Cypher: CREATE UNIQUE๏ CREATE UNIQUE node-[rel]->(node {prop : value}) •„fixes“ the graph •starts at bound nodes, properties rels and nodes by comparing types and tries to find •if not found creates them 35
    64. 64. Cypher: CREATE UNIQUE๏ CREATE UNIQUE node-[rel]->(node {prop : value}) •„fixes“ the graph •starts at bound nodes, properties rels and nodes by comparing types and tries to find •if not found creates them // create a new relationship start n=.., m=.. create unique n-[:KNOWS]->m // create a new node AND relationship start n=... create unique n-[:TAGGED]->(tag {name:“neo“}) // matches the tag node by name only creates new relationship start n=... create unique n-[:TAGGED]->(tag {name:“neo“}) 35
    65. 65. 36
    66. 66. Cypher: SET๏ SET [<node property>] [<relationship property>] •update a property on a node or relationship •must follow a START 36
    67. 67. Cypher: SET๏ SET [<node property>] [<relationship property>] •update a property on a node or relationship •must follow a START // update the name property start n=node(0) set n.name=Peter // update many nodes, using a calculation start n=node(*) set n.size=n.size+1 // match & capture a relationship, update a property start n=node(1) match n-[r]-m set r.times=10 36
    68. 68. 37
    69. 69. Cypher: DELETE๏ DELETE [<node>|<relationship>|<property>] •delete a node, relationship or property •toall relationships must be deleted first delete a node, 37
    70. 70. Cypher: DELETE๏ DELETE [<node>|<relationship>|<property>] •delete a node, relationship or property •toall relationships must be deleted first delete a node, // delete a node start n=node(5) delete n // remove a node and all relationships start n=node(3) match n-[r]-() delete n, r // remove a property start n=node(3) delete n.age 37
    71. 71. More Advanced Examples 38
    72. 72. START user = node(1) MATCH user -[user_skill]-> skill RETURN skill, user_skillSELECT skills.*, user_skill.*FROM usersJOIN user_skill ON users.id = user_skill.user_idJOIN skills ON user_skill.skill_id = skill.id WHERE users.id = 1 39
    73. 73. Example: Old, Influential FriendsSTART me = node(...)MATCH (me) - [f:FRIEND] - (old_friend) - [:FRIEND ] - (fof)WHERE ({today}-f.begin) > 365*10WITH  old_friend, collect(fof.name) as namesWHERE length(names) > 100RETURN old_friend, namesORDER BY old_friend.name ASC f:FRIEND :FRIEND me friend fof
    74. 74. Example: Simple RecommendationSTART me = node(...)MATCH (me) -[r1:RATED ]->(thing) <-[r2:RATED ]- (someone) -[r3:RATED ]->(cool_thing)WHERE ABS(r1.stars-r2.stars) <= 2 AND r3.stars > 3RETURN cool_thing, count(*) AS cntORDER BY cnt DESC LIMIT 10 r1:RATED thing r2:RATED me so TED r 3: RA cool thing 41
    75. 75. Cypher Cheat Sheet http://neo4j.org/resources/cypher 42
    76. 76. The Rabbithole http://console.neo4j.org This Graph: http://tinyurl.com/7cnvmlq 43
    77. 77. How to use Cypherin YOUR programs 44
    78. 78. Neo4j API ExecutionEngine engine = new ExecutionEngine(graphDB); String query = „start n=node:Person(name={name}) match n-[:ACTS_IN]->movie<-[:ACTS_IN]-friend return friend“; ExecutionResult result = engine.query(query, map(„name“, „Keanu“); for (Map<String,Object> row : result) { Node friend = row.get(„friend“); } Iterator<Node> friends = result.columnAs(„friend“);http://bit.ly/cypher-queries 45
    79. 79. How to get started? 46
    80. 80. How to get started?๏ Documentation 46
    81. 81. How to get started?๏ Documentation • docs.neo4j.org - tutorials+reference 46
    82. 82. How to get started?๏ Documentation • docs.neo4j.org - tutorials+reference • http://console.neo4j.org 46
    83. 83. How to get started?๏ Documentation • docs.neo4j.org - tutorials+reference • http://console.neo4j.org • Neo4j in Action 46
    84. 84. How to get started?๏ Documentation • docs.neo4j.org - tutorials+reference • http://console.neo4j.org • Neo4j in Action • Good Relationships 46
    85. 85. How to get started?๏ Documentation • docs.neo4j.org - tutorials+reference • http://console.neo4j.org • Neo4j in Action • Good Relationships๏ Get Neo4j 46
    86. 86. How to get started?๏ Documentation • docs.neo4j.org - tutorials+reference • http://console.neo4j.org • Neo4j in Action • Good Relationships๏ Get Neo4j • http://neo4j.org/download 46
    87. 87. How to get started?๏ Documentation • docs.neo4j.org - tutorials+reference • http://console.neo4j.org • Neo4j in Action • Good Relationships๏ Get Neo4j • http://neo4j.org/download • http://addons.heroku.com/neo4j/๏ Participate • http://groups.google.com/group/neo4j • http://neo4j.meetup.com 46
    88. 88. How to get started?๏ Documentation • docs.neo4j.org - tutorials+reference • http://console.neo4j.org • Neo4j in Action • Good Relationships๏ Get Neo4j • http://neo4j.org/download • http://addons.heroku.com/neo4j/๏ Participate • http://groups.google.com/group/neo4j • http://neo4j.meetup.com • a session like this one ;) 46
    89. 89. http://console.neo4j.org/r/GoThttps://dl.dropbox.com/u/14493611/got.txt 47
    90. 90. Neo4j-JDBC Driver & MovieDB Datasethttp://blog.neo4j.org/2012/06/wanted-your- help-in-testing-neo4j-jdbc.html 48
    91. 91. Got a Conference? Need a Dataset?http://blog.neo4j.org/2012/08/at-conference- need-dataset-neo4j-at.html 49
    92. 92. Neo4j in ActionSoftware Metrics 50
    93. 93. Graphs in Software Technolgoy๏ UML Diagrams are graphs๏ dependencies between classes, packages, modules etc are graphs๏ Software Metrics use dependency analysis๏ Visualizations๏ Cyclomatic Complexity,๏ Fan-in (afferent-coupling) / Fan-out (efferent coupling) etc. 51
    94. 94. Code City 52
    95. 95. Class Diagram is a Graph 53
    96. 96. SonarJ 54
    97. 97. But there is more๏Visualize & query Method, Field dependencies๏Collaborative filtering (co-usage)๏Ranking๏God classes๏Paths between classes 55
    98. 98. Welcome to Class-Graph๏take a JAR๏put it under ASM๏scan it superfast๏pull everything into Neo4j๏add categories, indexes๏Have Fun http://github.com/jexp/class-graph 56
    99. 99. Welcome to Class-Graph 57
    100. 100. Interactive Hands-On Session๏Lots of tasks๏use Cypher to solve them http://neo4j.org/resources/cypher๏be creative, work together๏ask !๏Server http://bit.ly/innoq-neo4j๏just the beginning 58
    101. 101. Task: Find java.lang.Number and return it 59
    102. 102. Task: Find java.lang.Number and return itSTART o=node:types(name="java.lang.Number") RETURN o; 59
    103. 103. Task: Subclasses of Number?•Return just the name•Order them alphabetically 60
    104. 104. Task: Subclasses of Number?START n=node:types(name="java.lang.Number")  MATCH n<-[:SUPER_TYPE]-s RETURN s.name ORDER BY s.name;•Return just the name•Order them alphabetically 60
    105. 105. Task: Which Methods does it have / how many•Find the top 5 classes with the most members 61
    106. 106. Task: Which Methods does it have / how manySTART n=node:types(name="java.lang.Number") MATCH n-[:METHOD_OF|FIELD_OF]->mRETURN m;•Find the top 5 classes with the most members 61
    107. 107. Task: Calculate the fan-out ofjava.lang.StringBuilder•Calculate fan-in•Which class has the highest fan-out•What about package-level? 62
    108. 108. Task: Calculate the fan-out of java.lang.StringBuilderSTART o=node:types(name="j.l.StringBuilder")MATCH o-[:FIELD_OF]->f-[:FIELD_TYPE]->tf, o-[:METHOD_OF]->m-[:PARAM_TYPE]->tp, m-[:RETURN_TYPE]->trRETURN o,count(distinct tf) + count(distinct tp) + count(distinct tr) as fan_out;•Calculate fan-in•Which class has the highest fan-out•What about package-level? 62
    109. 109. Task: Find longest Inheritance Path 63
    110. 110. Task: Find longest Inheritance Pathstart c=node:types(name="java.lang.Object") match path=p<-[:SUPER_TYPE*]-c return extract(n in nodes(path) : n.name),length(path) as lenorder by len desc limit 5; 63
    111. 111. Task: Find the class that used IOExceptionmost often 64
    112. 112. Task: Find the class that used IOExceptionmost oftenSTART ex=node:types(name="java.io.IOException"MATCH ex<-[:THROWS]-m<-[:METHOD_OF]-cRETURN c, count(*)ORDER BY count(*)LIMIT 5; 64
    113. 113. Task: Which other classes did classes that threw IOException use most often?•What could be a source of IOExceptions 65
    114. 114. Task: Which other classes did classes that threw IOException use most often?START ex=node:types(name="java.io.IOException")MATCH ex<-[:THROWS]-m<-[:METHOD_OF]-c,  mbr<-[:METHOD_OF|FIELD_OF]-c, mbr-[:FIELD_TYPE|PARAM_TYPE| RETURN_TYPE|THROWS]->other_typeWHERE other_type.name =~ /.+[.].+/RETURN other_type.name, count(*)ORDER BY count(*) descLIMIT 10;•What could be a source of IOExceptions 65
    115. 115. Task: Find a class you like and add a field withyour name and some type 66
    116. 116. Task: Find a class you like and add a field with your name and some typeSTART c=node:types(name="void"), t=node:types(name="java.lang.reflect.Proxy") CREATE c-[:FIELD_OF]->(field {name:“Michael“}) -[:FIELD_TYPE]->t; 66
    117. 117. Task: Delete the most annoying class and all itsmethods, fields and their relationships 67
    118. 118. Task: Delete the most annoying class and all its methods, fields and their relationshipsSTART c=node:types(name="java.awt.List"),MATCH c-[r1:FIELD_OF|METHOD_OF]->mbr-[r2]-() c-[r]-()DELETE c,mbr,r1,r2,r; 67
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×