Slide 1

Slide 1 text

Python & neo4j - Fuck the jvm Stephen McCullough / Pybelfast Jan 2019

Slide 2

Slide 2 text

About me.. cos it is all about me, me, me!!!! • Lead Developer @ Futrli - we’re hiring • I co-organise pyBelfast, BelfastRuby and BelfastElixir • I’ll try and behave and not curse… • You can find me on the inter web on most things as @swmcc apart from twitter!

Slide 3

Slide 3 text

Python & neo4j - Fuck the jvm • First off… I don’t mean “Fuck the jvm” • It is an incendiary title • I find graph databases interesting/fun • I don’t want to have to learn a new language to play with something • Python has a nice eco system around it for neo4j • Standing on others shoulders - Grant Dickerson

Slide 4

Slide 4 text

What is a graph DB? • Composed of nodes (vertices) & relationships (edges) • Completely different paradigm from relationship databases • It focuses on the relationships between values and commonalities among a ‘set’ of values • Designed to treat the relationships between the data as equally important to the data itself • Intended to hold data without constricting it to a pre- defined model

Slide 5

Slide 5 text

Use cases for a graph db • Fraud Detection & Analytics Solution • Ecomm fraud, insurance fraud, link analysis • Knowledge Graph • Asset management, Inventory • Recommendation Engines • Product recommendations, social recommendations • Identity & Access management • Cross referencing of business objects

Slide 6

Slide 6 text

Knowledge Graph • It represents a knowledge domain. • Connects things of different types in a systematic way. • Encodes knowledge arranged in a network of nodes and links rather than tables of rows and columns • Grow a semantic network of facts about “things” and can use it for data integration, knowledge discovery, and in-depth analyses.

Slide 7

Slide 7 text

For example • Homer Simpson (is friends with) with Kenny & Carl • Kenny (is friends with) Carl

Slide 8

Slide 8 text

Nodes • A node is a “vertex between edges that may hold data” • Or as I call it “a wee box of data stores” • [name: Homer] • [name: Lenny] • [name: Carl]

Slide 9

Slide 9 text

What does it look like?

Slide 10

Slide 10 text

Cypher • Cypher is a graph query language supported by neo4j • Based on pattern matching and a SQL-like syntax • …. when I was doing this before I didn’t use it much • I used Gremlin • DSL for Groovy • Wanted to use either ruby or python for an idea I’ve had since 2013

Slide 11

Slide 11 text

Is python fit enough? • I tried this out with ruby in 2013 • It didn’t go well, as you can imagine. • There were libraries but most weren’t fit for purpose • Reason that I went to Groovy • However its now 2019 and there is a very well supported “official” packages for python • Neo4j-python-driver • https://github.com/neo4j-examples/movies-python-bolt • Py2neo • https://py2neo.org/v4/

Slide 12

Slide 12 text

Example Code from py2neo import Node nicole = Node("Person", name="Nicole", age=24) drew = Node("Person", name="Drew", age=20) mtdew = Node("Drink", name="Mountain Dew", calories=9000) cokezero = Node("Drink", name="Coke Zero", calories=0) coke = Node("Manufacturer", name="Coca Cola") pepsi = Node("Manufacturer", name="Pepsi") graph.create(nicole | drew | mtdew | cokezero | coke | pepsi) from scripts.vis import draw options = {"Person": "name", "Drink": "name", "Manufacturer": "name"} draw(graph, options) from py2neo import Relationship graph.create(Relationship(nicole, "LIKES", cokezero)) graph.create(Relationship(nicole, "LIKES", mtdew)) graph.create(Relationship(drew, "LIKES", mtdew)) graph.create(Relationship(coke, "MAKES", cokezero)) graph.create(Relationship(pepsi, "MAKES", mtdew)) draw(graph, options)

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

The Wire

Slide 15

Slide 15 text

The GRROM

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

The Nodes - The Wire • All have common attributes: • Name • First / Last Appearance • Title • Section • Relationship between nodes

Slide 18

Slide 18 text

Joe
 “Proposition Joe” Stewart name: Joe Stewart alias: Prop Joe first_apperance: 1.09 last_apperance: 5.04 section: The Street rank: Kingpin affiliation: [east-side, new day co- op]

Slide 19

Slide 19 text

Russell
 “Stringer” Bell name: Russell Bell alias: Stringer first_apperance: 1.01 last_apperance: 3.12 section: The Street rank: Street Boss affiliation: [west-side, new-day co- op, b&b properties]

Slide 20

Slide 20 text

Cedric Daniels name: Cedric Daniels alias: first_apperance: 1.01 last_apperance: 5.10 section: The Law rank: [Lieutenant, Major, Colonel, Chief Deputy Ops, Commissioner, ] affiliation: [police, lawyer]

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

Why do this??? • It doesn’t remind me of my day to day to work: • Not taking a section of a monolith and making a ‘micro service’ out of it • Not creating an API so that a front end can use it and display information • Nothing at all to do with my work • It is FUCKING FUN (for me at least).

Slide 23

Slide 23 text

Going to do the following • Possibly come back at some stage and give you an actual talk on this, if there is interest • Will blog about it • Want to help me, please get in touch