Date post: | 10-May-2015 |
Category: |
Technology |
Upload: | fernand-galiana |
View: | 225 times |
Download: | 3 times |
In the land of graphsFernand Galiana
@kitesurfer
Agenda• Graph morphology
• Persistence mechanisms
• Terminology
• Modeling
• Graph databases and API’s
• Integrating with Ruby/Rails
• How to win $1,000,000
Graph Databases
Morphology
Dots and lines
Undirected graph (~200BC)
Directed graph (~14th-16th century)
MultiRelational Graph (19th century)
followsfollows
likes
likes
Property Graph (present)
followsfollows
likes
likes
name: Fred age: 29
name: Jim age: 19
Property Graph (cont)
followsfollows
likes
likes
name: Fred age: 29
name: James age: 19
weight: 0.9 date: 11/12/13
@jimweirich
Persistence
Any database can model a graph
Index Base Traversal
DC
E
A
BB,C E E,D
CB
D E
A
DC
E
A
BB,C E E,D
CB
D E
A
Index Base Traversal
DC
E
A
BB,C E E,D
CB
D E
A
Index Base Traversal
DC
E
A
BB,C E E,D
CB
D E
A
Index Base Traversal
A graph database is any storage system that can provide index-free adjacency.
GraphDB
DC
E
A
B
GraphDB
DC
E
A
B
Performance
Depth SQL Neo4j Recs
2 0.01 0.01 2.5k
3 30.26 0.16 100k
4 1,543 1.35 600k
5 Toast! 2.1 800k
@jimweirich
Why use a graph DB?
• Recommendations - densifying the graph
• Social
• Ranking
• Merging domains
• Data analysis
Terminology
Terminology
1 2follows
3
likesloves
Terminology
1 2follows
3
likesloves
OUT Vertex IN Vertex
Terminology
1 2follows
3
likesloves
vertex 1 OUT edges
Terminology
1 2follows
3
likesloves
vertex 2 IN edges
Terminology
1 2follows
3
likesloves
vertex 3 BOTH edges
@jimweirich
Modeling
A B
Modeling
• Vertex
• Edge
• Properties
• Relationships
Modeling
• Assess the space
• Nodes = Entities
• Edges = connections + semantic context
• NProperties = entity attrs + meta
• EProperties = strength + weight
@jimweirich
The Scene
…
DSLs
• Cypher (Neo4j)
• Gremlin (BluePrint)
• SPARQL
Rexster
• Rexster (REST)
• RexPro (bin)
• Rexster Kibbles
Blueprints
Gremlin
Gremlin[CruD]
• g.addVertex(id,[a:10,b:’Hello’])
• g.addEdge(id,v1,v2,’friend’,[a:10])
• g.removeVertex(g.v(id))
• g.removeEdge(g.e(id))
• g.v(id).remove()
• …
2
4
5
6
7
1 3
Oscar
Rango
BatisteGustave
Gertrude
Stew
Olaf
friend
friend
friend
friend
friend
friend
friend
friend
gremlin> g = rexster.getGraph('derailed_graph')
2
4
5
6
7
1 3
Oscar
Rango
BatisteGustave
Gertrude
Stew
Olaf
friend
friend
friend
friend
friend
friend
friend
friend
gremlin> g.V ==> v[1], v[2], v[3], v[4], v[5], v[6], v[7]
gremlin> g.E ==> e[1][1-friend-2], e[2][1-friend-3], etc…
2
4
5
6
7
1 3
Oscar
Rango
BatisteGustave
Gertrude
Stew
Olaf
friend
friend
friend
friend
friend
friend
friend
friend
2
4
5
6
7
1 3
Oscar
Rango
BatisteGustave
Gertrude
Stew
Olaf
friend
friend
friend
friend
friend
friend
friend
friend
gremlin> g.v(1) ==> v[1]
2
4
5
6
7
1 3
Oscar
Rango
BatisteGustave
Gertrude
Stew
Olaf
friend
friend
friend
friend
friend
friend
friend
friend
gremlin> g.V(‘name’, ‘Gustave’) ==> v[1]
2
4
5
6
7
1 3
Oscar
Rango
BatisteGustave
Gertrude
Stew
Olaf
friend
friend
friend
friend
friend
friend
friend
friend
gremlin> g.e(1) ==> e[1][1-friend-2]
gremlin> g.v(1).outE ==> e[1][1-friend-2], e[2][1-friend-3],e[3][1-friend-4]
2
4
5
6
7
1 3
Oscar
Rango
BatisteGustave
Gertrude
Stew
Olaf
friend
friend
friend
friend
friend
friend
friend
friend
gremlin> g.v(7).inE ==> e[7][3-friend-7]
2
4
5
6
7
1 3
Oscar
Rango
BatisteGustave
Gertrude
Stew
Olaf
friend
friend
friend
friend
friend
friend
friend
friend
gremlin> g.v(4).bothE ==> e[3][1-friend-4], e[8][4-friend-6]
2
4
5
6
7
1 3
Oscar
Rango
BatisteGustave
Gertrude
Stew
Olaf
friend
friend
friend
friend
friend
friend
friend
friend
2
4
5
6
7
1 3
Oscar
Rango
BatisteGustave
Gertrude
Stew
Olaf
friend
friend
friend
friend
friend
friend
friend
friend
gremlin> g.v(4).both ==> v[1], v[6]
2
4
5
6
7
1 3
Oscar
Rango
BatisteGustave
Gertrude
Stew
Olaf
friend
friend
friend
friend
friend
friend
friend
friend
gremlin> g.v(1) ==> v[1]
2
4
5
6
7
1 3
Oscar
Rango
BatisteGustave
Gertrude
Stew
Olaf
friend
friend
friend
friend
friend
friend
friend
friend
gremlin> g.v(1).out(‘friend’) ==> v[2], v[3], v[4]
2
4
5
6
7
1 3
Oscar
Rango
BatisteGustave
Gertrude
Stew
Olaf
friend
friend
friend
friend
friend
friend
friend
friend
gremlin> g.v(1).out(‘friend’).out(‘friend’) ==> v[5], v[6], v[6], v[6], v[7]
2
4
5
6
7
1 3
Oscar
Rango
BatisteGustave
Gertrude
Stew
Olaf
friend
friend
friend
friend
friend
friend
friend
friend
gremlin> g.v(1).out(‘friend’).out(‘friend’).groupCount.cap ==> {v[5]=1,v[6]=3,v[7]=1}
DEMO!
• Rexster DogHouse
• Wewoo(coz self promotion is underated!)
@jimweirich
Conclusion
• Mining relationships
• Recommendation, data analysis
• Scoring, Ranking
• Understand problem space
• Search engine integration
• Combining several problem spaces
References
• https://github.com/tinkerpop/gremlin
• http://gremlindocs.com
• http://sql2gremlin.com
• github.com/derailed/wewoo
• @jimweirich
Is a Graph worth a thousand joins? !
!
!
Thank you! @kitesurfer