SlideShare a Scribd company logo
A gremlin
ate my graph
Barcelona, Spain, October, 30th 2015
Agenda
Discover the Graph
Steps with a gremlin
The state of the Gremlin
Damien Seguy
CTO at Exakat
PHP code as Dataset
Speaker
A Gremlin ate my graph
What is gremlin?
V :Vertices, or nodes or objects
E : Edges, or links or relations
G : graph, or the dataset
The Vertices
g.vrepresents all the vertices
g.v(1) is one of the nodes
Vertices always have an id
g.v(1) => v(1)
1
g.v(1).id => 1
g.v(1).name => apply_filter
g.v(1).version => true
g.v(1).compat => [4.0, 4.1, 4.2, 4.3]
// non-existing properties
g.v(1).isFedAfterMidnight => null
Properties
Graph is schemaless
apply_filter
Vertice discovery
Use map to discover the graph
g.v(2).map => {name=wp_die, leaf=true}
wp_die
The Edges
Edges have id, properties
also : start, end and label
g.E represents all the edges
g.e(1) is the edge with Id 1
g.e(1) => e(1)
g.e(1).map => { }
g.e(1).id => 1
g.e(1).label => CALLS
Edge discovery
wp_diewp_ajax_fetch
_list
CALLS
Edges link the vertices
g.e(5).outV => v(2)
g.e(6).outV => v(3)
g.e(1).inV => v(4)
Running on the Edges
2
3
4
1
5
6
7
Directed graph
g.v(1).out => v(2)
v(3)
g.v(1).in => v(4)
g.v(1).both => v(2)
v(3)
v(4)
Following Edges
2
3
4
1
5
6
7
g.v(1).inE => e(7)
g.v(1).out.id => 2
3
g.v(2).in.in.id => 4
g.v(1).both.id => 2
3
4
Chaining
2
3
4
1
5
6
7
Wordpress Calls Graph
The graph of all Wordpress internal function calls
function
:name
function
:name
CALLS
function functionCALLS
A Gremlin ate my graph
g.v(19).out(‘CALLS’).name => wp_hash_password
wp_cache_delete
g.v(19).in(‘CALLS’).name => reset_password
wp_check_password
Calling home
wp_set_
password
reset_
password
wp_hash_
password
wp_check_
password
wp_cache_
delete
CALLS
CALLS
CALLS
CALLS
g.v(30).out(‘CALLS’)
.retain([g.v(30)])

.name => get_category_parents
Is it Recursive
get_permalink get_category_
link
get_category_
parents
id : 30
CALLS
CALLS
CALLS
Is it Recursive
g.v(30).in(‘CALLS’)
.retain([g.v(30)])
.name => get_category_parents
get_permalink get_category_
link
get_category_
parents
id : 30
CALLS
CALLS
CALLS
g.v(47).out(‘CALLS’).except([g.v(47)])
.out('CALLS').retain([g.v(47)])
.name
=> wp_trash_comment
Ping-Pong Function
CALLS
wp_trash
_comment
id: 47
wp_delete
_comment
id : 148
CALLS
CALLS
CALLS
CALLS
CALLS
CALLS
CALLS
CALLS
Up to now
nodes and vertices : basic blocs
in and out (and both) : navigation
except(), retain(), in(‘label’) : filtering
Starting at the vertices
Traversing the graph
Finding nodes in the graph that satisfy criteria
Traversing involves listing nodes, following
links, applying filters, processing data until all
conditions are met
Starting point : g.V and g.E
Counting
g.V.count() => 2691
g.E.count() => 9013
function functionCALLS
Sampling
g.V[0..3].name => do_activate_header
do_action
wpmu_activate_stylesheet
comment_footer_die
g.V[0..3].id => 1
3
5
4
Filtering
g.V.has('name','wp_die') => v(25);
wp_die
Dying Functions
g.V.out('CALLS')
.has('name','wp_die')
.count() => 84
???? wp_dieCALLS
g.V.out('CALLS')
.has('name','wp_die')
.name =>
Dying Functions
???? wp_dieCALLS
PROCESSING
wp_die
wp_die
wp_die
wp_die
wp_die
wp_die
wp_die
wp_die
wp_die
g.V.has('name','wp_die')
.in('CALLS')
.name => wp_ajax_trash_post
wp_ajax_delete_post
wp_ajax_delete_meta
wp_ajax_delete_link
wp_ajax_delete_tag
wp_ajax_delete_comment
wp_ajax_oembed_cache
wp_ajax_imgedit_preview
we_ajax_fetch_list
Dying Functions
???? wp_dieCALLS
PROCESSING
g.V.as('start')
.out('CALLS')
.has('name','wp_die')
.back('start')
.name => wp_ajax_trash_post
wp_ajax_delete_post
wp_ajax_delete_meta
wp_ajax_delete_link
wp_ajax_delete_tag
wp_ajax_delete_comment
wp_ajax_oembed_cache
wp_ajax_imgedit_preview
Dying Functions
???? wp_dieCALLS
PROCESSING
Relay Functions
g.V.filter{ it.out('CALLS').count() == 1}
.count() => 650
CALLS
CALLS
CALLS
Closures
Steps often offer possibility for closure
Closure is between {} , uses ‘it’ as current node,
is written in Groovy (or else)
Closure often have a standard default behavior,
so they are sometimes stealth
Applied to properties
Non standard functions
g.V.filter{ it.name != it.name.toLowerCase()}
.count() => 73
Leaf and Roots
LEAF
ROOT
g.V.filter{ it.out('CALLS').any() == false}
.count() => 407
g.V.filter{ it.in('CALLS').any() == false}
.count() => 1304
Get Linking Index
g.V.transform{['name':it.name,
'links':it.in('CALLS').count()]}
=> ...
{'name':wpmu_signup_stylesheet, 'links':0}
{'name':show_blog_form, 'links':7}
{'name':validate_blog_form, 'links':3}
{'name':show_user_form, 'links':4}
Get Called Index
g.V.transform{['name':it.name,
'links':it.in('CALLS').count()]
}
.order{ it.a.links <=> it.b.links}
=> {'name':get_post, 'links':191}
{'name':get_option, 'links':218}
{'name':_deprecated_function, 'links':296}
{'name':__, 'links':442}
{'name':apply_filters, 'links':598}
Most linked Function
groupCount(m)
m = [:];
g.V.groupCount(m);
m;
=> {
v[1] = 1,
v[2] = 1,
...
v[47] = 1,
}
Most linked Function
groupCount(m){key}{value}
m = [:];
g.V.groupCount(m){it.name}
{it.in('CALLS').count()};
m;
=> {
wp_restore_image = 1,
press_this_media_buttons = 0,
WP_Filesystem = 3,
...
}
Most linked Function
groupCount(m){key}{value}
m = [:];
g.V.groupCount(m){it.name}
{it.in('CALLS').count()};
m.sort{ -it.value }[0..2];
=> {
apply_filters = 598,
__ = 442,
_deprecated_function = 296
}
Most linked Function
m = [:];n = [:];
g.V.groupCount(m){it.name}
{it.in('CALLS').count()}
.groupCount(n){it.name}
{it.out('CALLS').count()};
n.sort{ -it.value}[0..2];
=> {
redirect_canonical = 60,
export_wp = 47,
edit_post = 36
SideEffect Steps
sideEffect : emit incoming but allows for side
computation
m = [:];n = [:];
g.V.groupCount(m){it.name}
{it.in('CALLS').count()}
.groupCount(n){it.name}
{it.out('CALLS').count()}
.count();
=> 2692
Nature of Steps
filter step : emit input if condition is satisfied :
has(), filter(), retain(), except()
map step : transform input into another object :
in(), out(), BOTH()
sideEffect step : emit input but allows for side
computation : transform, groupCount, each,
sideEffect
Branch and flatMap
Lonely Functions
g.V.filter{ it.in('CALLS').any() == false}
.filter{ it.out('CALLS').any() == false}
.sideEffect{ it.lonely = true; }
.count()
=> 184
SELECT, UPDATE AND COUNT
Updating a node
g.V.sideEffect{
incoming = it.in('CALLS').count();
}
.each{
it.setProperty('incoming', incoming);
it.setProperty('outgoing',
it.out('CALLS').count());
}
Updating The Graph
// removing deprecated functions
g.V.filter{ it.out('CALLS')
.has('name', '_deprecated_function'
.any()
}
.each{
it.bothE.each{ g.removeEdge(it); }
g.removeVertex(it);
}
State of Gremlin
Apache TinkerPop
http://tinkerpop.incubator.apache.org/
Version : 3.0.2
TP2 and TP3
groupCount{}{}
map
group().by().by()
ValueMap()
Vendors
StarDog
sqlg
Gremlin Variants
Gremlin For PHP
https://github.com/PommeVerte/gremlin-php
Get up and running with Tinkerpop 3 and PHP :
https://dylanmillikin.wordpress.com/2015/07/20/
get-up-and-running-with-tinkerpop-3-and-php/
Using with Neo4j : REST API
Older API : neo4jPHP, rexpro-php
Thanks
dseguy@exakat.io @exakat
http://www.slideshare.net/dseguy/
on the http://2015.phpconference.es//

More Related Content

PDF
Let the type system be your friend
PDF
Being functional in PHP (PHPDay Italy 2016)
PPTX
Category theory, Monads, and Duality in the world of (BIG) Data
PDF
PHP Performance Trivia
PDF
Promise: async programming hero
PDF
JavaScript Functions
PPTX
Chapter 7 functions (c)
PDF
Powerful JavaScript Tips and Best Practices
Let the type system be your friend
Being functional in PHP (PHPDay Italy 2016)
Category theory, Monads, and Duality in the world of (BIG) Data
PHP Performance Trivia
Promise: async programming hero
JavaScript Functions
Chapter 7 functions (c)
Powerful JavaScript Tips and Best Practices

What's hot (20)

PPTX
Functional Programming in JavaScript by Luis Atencio
PDF
Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017
PDF
"Немного о функциональном программирование в JavaScript" Алексей Коваленко
PPTX
LinkedIn TBC JavaScript 100: Functions
PDF
Java Script Best Practices
PDF
PHP Enums - PHPCon Japan 2021
PPTX
ES6 in Real Life
PDF
Intro to Functional Programming
PDF
Functions, Types, Programs and Effects
PDF
Functional Javascript
PDF
PPT
JavaScript Functions
PDF
Symfony World - Symfony components and design patterns
PDF
Programmation fonctionnelle en JavaScript
PDF
Joe Bew - Apprendi un nuovo linguaggio sfruttando il TDD e il Clean Code - Co...
PPSX
DIWE - Working with MySQL Databases
PDF
Functional solid
PDF
Atomically { Delete Your Actors }
PPTX
Java script
PDF
Lucio Floretta - TensorFlow and Deep Learning without a PhD - Codemotion Mila...
Functional Programming in JavaScript by Luis Atencio
Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017
"Немного о функциональном программирование в JavaScript" Алексей Коваленко
LinkedIn TBC JavaScript 100: Functions
Java Script Best Practices
PHP Enums - PHPCon Japan 2021
ES6 in Real Life
Intro to Functional Programming
Functions, Types, Programs and Effects
Functional Javascript
JavaScript Functions
Symfony World - Symfony components and design patterns
Programmation fonctionnelle en JavaScript
Joe Bew - Apprendi un nuovo linguaggio sfruttando il TDD e il Clean Code - Co...
DIWE - Working with MySQL Databases
Functional solid
Atomically { Delete Your Actors }
Java script
Lucio Floretta - TensorFlow and Deep Learning without a PhD - Codemotion Mila...
Ad

Viewers also liked (20)

PDF
E2M - Full 3D Black Box Navigation Application for Android
DOC
Formato hv foto sena copia2 sammymar
PDF
Haris Hamza- Resume
PDF
1 han va cat_trong_dong_tau
PPT
5 cuento fran
PDF
Ort business breakfast mailer deloitte final
PDF
50 Highlights der 37. Auktion am 18. April 2015 - 50 Highlights of Scripophil...
PDF
Institucional Agroads.com 2013
PDF
REGIONE VENETO - Turismo flash - Febbraio 2011
PDF
Cuidadores Clase Lorena Javet
PPTX
La imagen educativa - Cómo se escribe
PPTX
PDF
Bases premios i certamen de arte. el valor del vino y el aceite en la cultura...
PDF
1945 PHI brochure EN final lowres 130516
DOC
Curriculum Vitae Gianluca Dusio
PPT
InstantFiler oct 2010
PPT
CLASE 5 Gruposde google
PPSX
Mercado de valores
PDF
gestion infraestructura vial
E2M - Full 3D Black Box Navigation Application for Android
Formato hv foto sena copia2 sammymar
Haris Hamza- Resume
1 han va cat_trong_dong_tau
5 cuento fran
Ort business breakfast mailer deloitte final
50 Highlights der 37. Auktion am 18. April 2015 - 50 Highlights of Scripophil...
Institucional Agroads.com 2013
REGIONE VENETO - Turismo flash - Febbraio 2011
Cuidadores Clase Lorena Javet
La imagen educativa - Cómo se escribe
Bases premios i certamen de arte. el valor del vino y el aceite en la cultura...
1945 PHI brochure EN final lowres 130516
Curriculum Vitae Gianluca Dusio
InstantFiler oct 2010
CLASE 5 Gruposde google
Mercado de valores
gestion infraestructura vial
Ad

Similar to A Gremlin ate my graph (20)

PDF
Php in the graph (Gremlin 3)
PPT
A gremlin in my graph confoo 2014
PDF
jQuery & 10,000 Global Functions: Working with Legacy JavaScript
PPT
Svcc Building Rich Applications with Groovy's SwingBuilder
PPT
CodeMash - Building Rich Apps with Groovy SwingBuilder
PDF
Rapid Development with Ruby/JRuby and Rails
ODP
Gpars concepts explained
PPTX
Clojure And Swing
PDF
Introductionto fp with groovy
PDF
Griffon @ Svwjug
KEY
Symfony2 Building on Alpha / Beta technology
PDF
A walk in graph databases v1.0
PPTX
Closure
PPTX
Art of Javascript
KEY
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
KEY
Advanced jQuery
PPTX
FunctionalJS - George Shevtsov
PPTX
1. George Shevtsov - Functional JavaScript
PPTX
Groovy
Php in the graph (Gremlin 3)
A gremlin in my graph confoo 2014
jQuery & 10,000 Global Functions: Working with Legacy JavaScript
Svcc Building Rich Applications with Groovy's SwingBuilder
CodeMash - Building Rich Apps with Groovy SwingBuilder
Rapid Development with Ruby/JRuby and Rails
Gpars concepts explained
Clojure And Swing
Introductionto fp with groovy
Griffon @ Svwjug
Symfony2 Building on Alpha / Beta technology
A walk in graph databases v1.0
Closure
Art of Javascript
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Advanced jQuery
FunctionalJS - George Shevtsov
1. George Shevtsov - Functional JavaScript
Groovy

More from Damien Seguy (20)

PDF
Strong typing @ php leeds
PPTX
Strong typing : adoption, adaptation and organisation
PDF
Qui a laissé son mot de passe dans le code
PDF
Analyse statique et applications
PDF
Top 10 pieges php afup limoges
PDF
Top 10 php classic traps DPC 2020
PDF
Meilleur du typage fort (AFUP Day, 2020)
PDF
Top 10 php classic traps confoo
PDF
Tout pour se préparer à PHP 7.4
PDF
Top 10 php classic traps php serbia
PDF
Top 10 php classic traps
PDF
Top 10 chausse trappes
PDF
Code review workshop
PDF
Understanding static analysis php amsterdam 2018
PDF
Review unknown code with static analysis php ce 2018
PDF
Everything new with PHP 7.3
PDF
Php 7.3 et ses RFC (AFUP Toulouse)
PDF
Tout sur PHP 7.3 et ses RFC
PDF
Review unknown code with static analysis php ipc 2018
PDF
Code review for busy people
Strong typing @ php leeds
Strong typing : adoption, adaptation and organisation
Qui a laissé son mot de passe dans le code
Analyse statique et applications
Top 10 pieges php afup limoges
Top 10 php classic traps DPC 2020
Meilleur du typage fort (AFUP Day, 2020)
Top 10 php classic traps confoo
Tout pour se préparer à PHP 7.4
Top 10 php classic traps php serbia
Top 10 php classic traps
Top 10 chausse trappes
Code review workshop
Understanding static analysis php amsterdam 2018
Review unknown code with static analysis php ce 2018
Everything new with PHP 7.3
Php 7.3 et ses RFC (AFUP Toulouse)
Tout sur PHP 7.3 et ses RFC
Review unknown code with static analysis php ipc 2018
Code review for busy people

Recently uploaded (20)

PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Machine learning based COVID-19 study performance prediction
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Encapsulation theory and applications.pdf
PPTX
Spectroscopy.pptx food analysis technology
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Cloud computing and distributed systems.
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Approach and Philosophy of On baking technology
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
A comparative analysis of optical character recognition models for extracting...
Machine learning based COVID-19 study performance prediction
Mobile App Security Testing_ A Comprehensive Guide.pdf
Encapsulation_ Review paper, used for researhc scholars
Encapsulation theory and applications.pdf
Spectroscopy.pptx food analysis technology
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Cloud computing and distributed systems.
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
MYSQL Presentation for SQL database connectivity
Per capita expenditure prediction using model stacking based on satellite ima...
Diabetes mellitus diagnosis method based random forest with bat algorithm
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
The AUB Centre for AI in Media Proposal.docx
sap open course for s4hana steps from ECC to s4
Approach and Philosophy of On baking technology
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf

A Gremlin ate my graph