SlideShare a Scribd company logo
A gremlin
in your graph
in your graph

Montreal, Québec, Canada, February, 28th 2014
What is gremlin?

G : graph, or the dataset
V : Vertices, or nodes or objects
E : Edges, or links or relations
A gremlin in my graph confoo 2014
graph database, http://www.neo4j.org/
Speaker
Damien Seguy
dams@php.net
Exakat : Expert services in PHP
Yes we take
questions

?
Graph Database
http://www.neo4j.org/
http://localhost:7474/
Console -> Gremlin

==>
==>
,,,/
==>
(o o)
==> -----oOOo-(_)-oOOo----==>
==> Available variables:
==>
g = (neo4jgraph[EmbeddedGraphDatabase [data/graph.db]]
==> , null) out = (java.io.PrintStream@398a3257
==> , null)
gremlin>

Console in web browser!
Welcome to the
graph
g is the graph where the nodes live
v represents all the vertices

g.v(1) =>
Nodes always have an id

v(1)
Properties
Graph is schemaless

g.v(1).id
=> 1
g.v(1).name
=> ext/datetime
g.v(1).version => null
Node discovery
g.v(2).map =>
{name=timezonedb, version=2013.9}

map is convenient to discover the
graph
In the graph
Only objects and relations
Vertices have id and properties
Edges have id, label and properties
Edges
g.v(1).in => v(4)
g.v(1).out => v(2)
v(3)
g.v(1).both => v(2)
v(3)
v(4)
Directed graph
g.v(1).inE.id => 2
3
4
8

g.v(1).inE.label => WROTE
WROTE
WROTE
HAS
PECL database
database of PHP extension authors.
The extensions are stored in categories
http://pecl.php.net/
Gephi
Following edges
g.v(1).in(‘WROTE’).name => Derick Rethans
Hannes Magnusson
Jeremy Mikola

g.v(1).in(‘WROTE’,‘HAS’).name =>
/*same as previous plus */ DB
Collaborators
g.v(2).out(‘WROTE’).in(‘WROTE’).name =>
Hannes Magnusson
Jeremy Mikola
Derick Rethans
Collaborators
g.v(2).out(‘WROTE’).in(‘WROTE’).
except(g.v(2)).name =>
Hannes Magnusson
Jeremy Mikola
Intro recap
nodes and vertices : basic blocs
in and out (and both) : navigation
except(), in(‘label’) : filtering
Traversing the
graph
Means reading information in the graph
Traversing involves listing nodes then following
links until all conditions are met
The graph contains Vertices and Edges. Is there
anything else ?
PECL database
Authors

Ext

Categories
Count authors
count()
All vertices are
created equal
Count contributors
g.V.out(‘wrote’)
.count()
=> 5
Too manys!
Arrays or pipes
g.V.out(‘wrote’)[1]
v(12)
g.V.out(‘wrote’)[1..2]
.name ext/xdebug
ext/mongo
Count contributors

g.V.in(‘wrote’)
.unique()
.count()==> 3
Gremlin functions
Pipe level function
in, out, unique, count,
Node level function
map, has, filter{}
Value level
{property}
Property level

// making name UPPERCASE
g.v(79).name.toUpperCase(); EXT/GEARMAN
// size of the name’s string
g.v(130).name.toList().size(); 13

// extracting words http://groovy.codehaus.o
in a string
Documentation
g.v(146).transform{ it.name.tokenize();}
[Johann-Peter, Hartmann]
Vertex level
g.v(130).map;
{name=Ben Ramsey}
g.v(14).propertykeys name
g.v(12).setProperty(‘ext_nb’,
g(12).out(‘wrote’).count()
);
Collaborating
Adding collaborators to the graph

g.addEdge(

g.v(1),
g.v(1).out(‘WROTE’).
in(‘WROTE’).
except(g.v(1)),
‘COLLABORATE’);

==> No signature of method: com.tinkerpop.gremlin.groovy.GremlinGro
ovyPipeline.except() is applicable for argument types: (com.tinkerp
op.blueprints.pgm.impls.neo4j.Neo4jVertex) values: [v[1]]
==> Possible solutions: except(java.util.Collection), select(),
next(), reset(), cap(), toSet()

Except() produces a pipe!
g.addedge doesn’t accept it
Collaborating
Adding collaborator
g.addEdge(

g.v(1),
g.v(1).out(‘WROTE’).
in(‘WROTE’).
except(g.v(1)).next(),
‘COLLABORATE’);

Adding collaborators
g.v(1).out(‘WROTE’).in(‘WROTE’).except(g.v(1)).each{
g.addEdge(g.v(1), it, ‘COLLABORATE’)
}

wonderful world of closures
Working with pipes
Pipes functions often offer possibility for closure
Closure is between {}
and uses ‘it’ as current node
Closure often have a standard default behavior, so
they are sometimes stealth
Filtering
filter links by label (in/out/both(‘label’))
Filter node with has(‘property’,

‘value’)

or

hasNot(‘property’, null)

Filter authors with 14 or more extensions
g.V.in(‘WROTE’).filter{it.out(‘WROTE’).count() > 14}
Ilia Alshanetsky, Wez Furlong, Sara Golemon

Filter allows us to work within the pipe
Filtering
List of contributors with more ext in two categories
g.V.in(‘wrote’).filter{
it.out(‘wrote’).in(‘has’).unique().count() > 2
}.name

Filter longer than query ?
GroupCount
groupCount(m)

Number of categories by author
g.V.out(‘wrote’).in(‘has’).groupCount(m)

Apparently counted but
who is v(274) ?

==> v[380]=1=
v[379]=1==>
v[378]=2==>
v[273]=2==>
v[274]=2==>
v[272]=2==>
v[173]=3==>
v[240]=2==>
GroupCount

g.V.out(‘has’)
.in(‘wrote’)
.groupCount(m)
Georg Richter =2==> Warren Read =2==> Jay Kint =2==> shekhar
euvel =1==>{it.name}
Grant Croker =1
GroupCount
Count of categories, without PHP standard
distribution
The second closure counts elements (default +1)
g.V.has(‘wrote’)
.in(‘has’)
.groupCount(m)
{it.name}
{if (!it.name in [‘mysql’, ‘timezonedb’,’gd’,
‘dbase’ /* ....*/]) { it.b + 1;} }
Pipes
array notation
closure usage
useful function for pipes :
groupcount, groupby{key}{value}{mapreduce},
ordermap, [n..m] operator,
More on http://gremlindocs.com/
Graph modifications
Gremlin allows graph modification
Adding a type property to authors
g.V.in(‘WROTE’).each{
it.setProperty(‘type’, ‘author’);
}
Updating on the way
sideEffect runs a closure, but keep running the
query
Adding type to extensions AND categories in the
same query
g.V.as(‘ext’)
.in(‘HAS’)
.sideEffect{
it.setProperty(‘type’, ‘Category’);
.back(‘ext’)
.sideEffect{
it.setProperty(‘type’, ‘Extension’);

}
}
back tracking
back( ‘name’ ) : goes back to the vertex or edge
that was named with as(‘name’)
back( n ) : goes back n vertex or edges behind
Make is possible to check a branch, come back and
check another branch
Manipulating vertex
g.addVertex(id or null, [property:value,...]);
g.addEdge(origin vertex,
destination vertex,
label,
[property:value...]);
g.removeVertex(vertex);
g.removeEdge(edge);
Application to OOP?
Gremlin goes beyond class specifics
g.v(1).out(‘WROTE’).in(‘HAS’).unique().count()
$total = array();
$author = new Author(1);foreach($author>getExtensions() as $ext) {
$total[$ext->getCategory()] = true;}
return count($total);
return count($total);

Gremlin generalizes the navigation
Thanks

Dams@php.net
http://www.slideshare.net/dseguy/
on the http://confoo.ca/
Kevin Bacon
Suggest collaborators to authors ?
Authors who worked with collaborators but not with
the author, are recommendations
g.V.has(‘name’, ‘contrib’).sideEffect{init =
it}out(‘wrote’).in(‘wrote’).except(init).has(‘name’,‘con
trib2’).path

More Related Content

PDF
Make Testing Groovy
PDF
Is writing performant code too expensive?
PPTX
Is your C# optimized
PDF
High performance web programming with C++14
PDF
Automatically Describing Program Structure and Behavior (PhD Defense)
PPTX
concurrency gpars
PPTX
C- Programs - Harsh
PDF
Use PEG to Write a Programming Language Parser
Make Testing Groovy
Is writing performant code too expensive?
Is your C# optimized
High performance web programming with C++14
Automatically Describing Program Structure and Behavior (PhD Defense)
concurrency gpars
C- Programs - Harsh
Use PEG to Write a Programming Language Parser

What's hot (20)

PDF
(Greach 2015) Dsl'ing your Groovy
PDF
Python 1 liners
DOCX
Computer science project work
PPTX
C# 7.0 Hacks and Features
PDF
GPars For Beginners
DOCX
C++ file
PDF
ConFess Vienna 2015 - Metaprogramming with Groovy
PDF
C++ practical
PDF
Project_Euler_No_104_Pandigital_Fibonacci_ends
 
PDF
Scalaz 8 vs Akka Actors
PDF
Expression trees in c#
PDF
Дмитрий Верескун «Синтаксический сахар C#»
DOC
Pads lab manual final
PPTX
Expression trees in c#, Алексей Голубь (Svitla Systems)
PDF
C++ TUTORIAL 7
PDF
C++ Programming - 1st Study
TXT
c++ program for Railway reservation
PDF
Lambdas and Streams Master Class Part 2
DOCX
2 a networkflow
PDF
C++ TUTORIAL 2
(Greach 2015) Dsl'ing your Groovy
Python 1 liners
Computer science project work
C# 7.0 Hacks and Features
GPars For Beginners
C++ file
ConFess Vienna 2015 - Metaprogramming with Groovy
C++ practical
Project_Euler_No_104_Pandigital_Fibonacci_ends
 
Scalaz 8 vs Akka Actors
Expression trees in c#
Дмитрий Верескун «Синтаксический сахар C#»
Pads lab manual final
Expression trees in c#, Алексей Голубь (Svitla Systems)
C++ TUTORIAL 7
C++ Programming - 1st Study
c++ program for Railway reservation
Lambdas and Streams Master Class Part 2
2 a networkflow
C++ TUTORIAL 2
Ad

Viewers also liked (11)

PDF
The Path-o-Logical Gremlin
PDF
Gremlin: A Graph-Based Programming Language
PDF
The Gremlin in the Graph
PPTX
Introduction to Gremlin
PDF
10 guiones de obras de teatro cortas (ejemplos gratis)
PDF
A Gremlin ate my graph
PDF
Php in the graph (Gremlin 3)
PDF
The Gremlin Graph Traversal Language
PDF
Intro to Graphs and Neo4j
KEY
Intro to Neo4j presentation
PPTX
Knowledge Architecture: Graphing Your Knowledge
The Path-o-Logical Gremlin
Gremlin: A Graph-Based Programming Language
The Gremlin in the Graph
Introduction to Gremlin
10 guiones de obras de teatro cortas (ejemplos gratis)
A Gremlin ate my graph
Php in the graph (Gremlin 3)
The Gremlin Graph Traversal Language
Intro to Graphs and Neo4j
Intro to Neo4j presentation
Knowledge Architecture: Graphing Your Knowledge
Ad

Similar to A gremlin in my graph confoo 2014 (20)

PDF
A walk in graph databases v1.0
PPTX
Meet Gremlin – your guide through graphs in Cosmos DB
PDF
DataStax: What's New in Apache TinkerPop - the Graph Computing Framework
PDF
What's New in Apache TinkerPop - the Graph Computing Framework
PPTX
Cassandra Summit - What's New In Apache TinkerPop?
PPTX
Gremlin's Anatomy
PDF
Gremlin 101.3 On Your FM Dial
PDF
In The Land Of Graphs...
PDF
The Pathology of Graph Databases
PDF
Design and Implementation of the Security Graph Language
PDF
1st UIM-GDB - Connections to the Real World
PPTX
Betabit - syrwag 2018-03-28
PDF
Neo4j Graph DB & LLM.graphs & genAI introduction & cheatsheet.with links.pdf
PPT
EgoSystem: Presentation to LITA, American Library Association, Nov 8 2014
PDF
Traversing Graph Databases with Gremlin
PPT
10b. Graph Databases Lab
PDF
Graph Modelling
PDF
Gremlin's Graph Traversal Machinery
A walk in graph databases v1.0
Meet Gremlin – your guide through graphs in Cosmos DB
DataStax: What's New in Apache TinkerPop - the Graph Computing Framework
What's New in Apache TinkerPop - the Graph Computing Framework
Cassandra Summit - What's New In Apache TinkerPop?
Gremlin's Anatomy
Gremlin 101.3 On Your FM Dial
In The Land Of Graphs...
The Pathology of Graph Databases
Design and Implementation of the Security Graph Language
1st UIM-GDB - Connections to the Real World
Betabit - syrwag 2018-03-28
Neo4j Graph DB & LLM.graphs & genAI introduction & cheatsheet.with links.pdf
EgoSystem: Presentation to LITA, American Library Association, Nov 8 2014
Traversing Graph Databases with Gremlin
10b. Graph Databases Lab
Graph Modelling
Gremlin's Graph Traversal Machinery

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
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
KodekX | Application Modernization Development
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
cuic standard and advanced reporting.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Encapsulation_ Review paper, used for researhc scholars
Spectral efficient network and resource selection model in 5G networks
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
MIND Revenue Release Quarter 2 2025 Press Release
20250228 LYD VKU AI Blended-Learning.pptx
NewMind AI Weekly Chronicles - August'25 Week I
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Per capita expenditure prediction using model stacking based on satellite ima...
KodekX | Application Modernization Development
Programs and apps: productivity, graphics, security and other tools
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
cuic standard and advanced reporting.pdf

A gremlin in my graph confoo 2014