SlideShare a Scribd company logo
1 of 57
(Neo4j)-[:   ]->(J)Ruby


                    1
2
A graph database...




                      3
A graph database...

 NO: not for charts & diagrams, or vector artwork




                                                    3
A graph database...

 NO: not for charts & diagrams, or vector artwork
 YES: for storing data that is structured as a graph




                                                       3
A graph database...

 NO: not for charts & diagrams, or vector artwork
 YES: for storing data that is structured as a graph
    remember linked lists, trees?




                                                       3
A graph database...

 NO: not for charts & diagrams, or vector artwork
 YES: for storing data that is structured as a graph
    remember linked lists, trees?
    graphs are the general-purpose data structure




                                                       3
A graph database...

 NO: not for charts & diagrams, or vector artwork
 YES: for storing data that is structured as a graph
    remember linked lists, trees?
    graphs are the general-purpose data structure
 “A relational database may tell you the average age of everyone
    in this session,
 but a graph database will tell you who is most likely to buy you a
    beer.”



                                                                      3
4
You know relational




                      4
You know relational




                      4
You know relational




            foo

                      4
You know relational




            foo       bar

                            4
You know relational




            foo       foo_bar   bar

                                      4
You know relational




            foo       foo_bar   bar

                                      4
You know relational




            foo       foo_bar   bar

                                      4
You know relational




            foo       foo_bar   bar

                                      4
You know relational
now consider relationships...




                                4
You know relational
now consider relationships...




                                4
You know relational
now consider relationships...




                                4
You know relational
now consider relationships...




                                4
You know relational
now consider relationships...




                                4
You know relational
now consider relationships...




                                4
4
5
We're talking about a
Property Graph




                        5
We're talking about a
Property Graph


     Nodes




                        5
We're talking about a
Property Graph


     Nodes


      Relationships




                        5
We're talking about a
Property 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)
                                                                                                                  5
5
And, but, so how do you
query this "graph" database?



                         6
And, but, so how do you
query this "graph" database?
   *hint* Not by writing Map-Reduce Jobs




                                           6
7
You traverse the graph




                         7
You traverse the graph




                         7
You traverse the graph
// lookup starting point in an index
START n=node:People(name = ‘Andreas’)




                        And
                              rea
                                    s




                                        7
You traverse the graph
// lookup starting point in an index
   then traverse to find results
START n=node:People(name ==‘Andreas’)
      me=node:People(name   ‘Andreas’
MATCH (me)-[:FRIEND]-(friend)-[:FRIEND]-(friend2)
RETURN friend2




                        And
                              rea
                                    s




                                                    7
7
START user = node(1)
                                           MATCH user -[user_skill]-> skill
                                           RETURN skill, user_skill
SELECT skills.*, user_skill.*
FROM users
JOIN user_skill ON users.id = user_skill.user_id
JOIN skills ON user_skill.skill_id = skill.id WHERE users.id = 1


                                                                    8
(Neo4j)-[:   ]->(J)Ruby


                    9
Bindings

           REST://




                     10
Bindings

           REST://




                     10
neoid
                                                Jogger
                    neology

neography
                                        Pacer



 Server
 #REST                                          embedded
                                                  JRuby

                              Cypher-
                                DSL

                                        neo4j.rb
   roll                   Rails/
                           AR
 your own
                                                     11
neo4j.rb by Andreas Ronge
    gem install neo4j

  require 'rubygems'
  require 'neo4j'

  class Person
    include Neo4j::NodeMixin
    property :name, :age, :rank
    index :name
    has_n :friends
  end

  Neo4j::Transaction.run do
    neo = Person.new :name=>'Neo', :age=>29
    morpheus =
  Person.new :name=>'Morpheus', :rank=>'Captain'
    neo.friends << morpheus
  end

  neo.friends.each {|p|...}


       neo4j.rubyforge.org
neography by Max De Marzi
 @neo = Neography::Rest.new

 def suggestions_for(node)
   node.incoming(:friends)
       .order("breadth first")
       .uniqueness("node global")
      .filter("position.length() == 2;").depth(2)
 end

 john   = Neography::Node.create("name" =>'John')
 ....
 luke   = Neography::Node.create("name" =>'Luke')

 johnathan.both(:friends) << mark
 ...
 luke.both(:friends) << mary
 john.both(:friends) << luke

 puts "John should become friends with
   #{suggestions_for(john).map{|n| n.name }.join(', ')}"


   github.com/maxdemarzi/neography
pacer by Darrick Wiebe (DSL for TP Pipes)
  neo = Pacer.neo '/tmp/neo_demo'
  michael = neo.create_vertex :name => 'Michael',
                              :type => 'user'
  group = neo.create_vertex :name => 'Neo4j',
                            :type => 'group'
  neo.v.properties # Show node properties

   #<V[1024]> #<V[1025]>
   Total: 2
  => #<GraphV>

  Add many relationships:

  group.add_edges_to :member, neo.v(:type => 'user')

  # Traversals/Suggestions
  friends = person.out_e(:friend).in_v(:type => 'user')
  friends.out_e(:friend).in_v(:type => 'person')
   .except(friends).except(person).most_frequent(0...10)



      github.com/pangloss/pacer
jogger by Jannis Hermann (MoviePilot)
  class Jogger
    module NamedTraversals

      # Traverse to somebody's woman friends
      def self.friends(current_traversal, gender)
        t = current_traversal.in(:friends)
        t = t.filter(gender: gender)
      end

      # Group and sort
      def self.top_list(current_traversal, type)
        t = current_traversal.out(type)
        t = t.filter(type: 'Movie')
        t = t.group_count{ |v| v }
      end
    end
  end




      github.com/moviepilot/jogger
Sites created with Ruby & Neo4j
Simple & Cool Viz: Ruby & JavaScript




maxdemarzi.com
Go get hacking
๏ neo4j.org
๏ devcenter.heroku.com/articles/neo4j
๏ http://maxdemarzi.com/tag/ruby/
๏ neo4j.rubyforge.org / neo4jrb google group
๏ video.neo4j.org/videos/search/?query=ruby
๏ www.markhneedham.com/blog/tag/neo4j
๏ ....



                                               18
Some Code
github.com/jexp/rfid-graph
         based on
Max De Marzi‘s Neovigator
         based on
Michael Aufreiter‘s Ask Ken
                              19
Some Code
       if we have time left


github.com/jexp/rfid-graph
         based on
Max De Marzi‘s Neovigator
         based on
Michael Aufreiter‘s Ask Ken
                              19
OpenBeacon JSON format
 { "id":3456,
   "api":{"name":"openbeacon-tracker","ver":"0.9.1-dirty"},
   "time":1344647727,
   "packets":{
     "per_key":[0,0,0,0,0,0,0,0,15536],
     "rate":61,
     "invalid_protocol":2,
     "crc_ok":15538
     },
   "tag":[
     {"id":598,"px":200,"py":100,"key":8,"reader":1126},
     {"id":585,"px":200,"py":100,"key":8,"reader":1126,"button":true},
     {"id":574,"px":200,"py":100,"key":8,"reader":1126}],
   "reader":[
     {"id":1126,"px":200,"py":100,"room":1,"floor":1,"group":1}],
   "edge":[
     {"tag":[585,598],"power":5},
     {"tag":[574,598],"power":8}]}



      openbeacon.org
Neo4j data storage
  def add_tags(tags)
    query("start n=node(0) foreach (tag in {tags} :
          create t={ tag: tag })", {:tags => tags})
  end


  def batch_connect_simple(tags, time = Time.now.to_i)
    prepared = tags.map { |tag| prepare(tag[0],tag[1],time); }
    @cypher.batch(prepared)
  end


  # tag1-[talk:TALKED {begin,end}]->tag2
  def prepare(tag1,tag2,time = Time.now.to_i)
    (tag1,tag2) = [tag2, tag1] if tag2.to_i < tag1.to_i
    { :query =>
    "START tag1=node:node_auto_index(tag={tag1}),
           tag2=node:node_auto_index(tag={tag2})
     CREATE UNIQUE tag1-[talk:TALKED]->tag2
     set talk.begin = coalesce(talk.begin?,{now}), talk.end = {now}",
      :params => {:tag1 => tag1, :tag2 => tag2, :now => time}}


                                                                   21
Neo4j data querying & mangling
  QUERY = "START tag=node({id})
      MATCH tag-[r:TALKED]-other<-[?:HAS_TAG]-other_user
      RETURN ID(other) as id, other.tag as tag, r, type(r) as type,
             coalesce(other_user.name?,other.tag) as name"
  def direction(node, rel)
    rel.end_node.to_i == node ? "Incoming" : "Outgoing"
  end


  get '/resources/show' do
    content_type :json
    props = get_properties(node_for(params[:id]))
    connections = cypher.query(QUERY,{:id => props["id"]})
    rels = connections.group_by
           { |row| [direction(id,row["r"]), row["type"]] }
    attributes = rels.collect { |keys, values|
     {:id => keys.last, :name => keys.join(":"), :values => values } }


    @node = {:details_html =>
             "<h2>User: #{user}</h2><p>#{get_info(props)}</p>",
             :data => {:id => id, :attributes => attributes,
                       :name => props["name"] }}.to_json
  end                                                                 22
Pusher RFID data stream
 require ,pusher-client‘


 socket = PusherClient::Socket.new(,KEY‘)
 socket.subscribe(,openbeacon‘)
 socket BRACKET ,openbeacon‘ BRACKET .bind(,sighting‘) do PIPE json
 PIPE
   ...
 end


 socket.connect




                                                                  23
Neovigator processing.js visualization




                                         24

More Related Content

More from jexp

Looming Marvelous - Virtual Threads in Java Javaland.pdf
Looming Marvelous - Virtual Threads in Java Javaland.pdfLooming Marvelous - Virtual Threads in Java Javaland.pdf
Looming Marvelous - Virtual Threads in Java Javaland.pdfjexp
 
Easing the daily grind with the awesome JDK command line tools
Easing the daily grind with the awesome JDK command line toolsEasing the daily grind with the awesome JDK command line tools
Easing the daily grind with the awesome JDK command line toolsjexp
 
Looming Marvelous - Virtual Threads in Java
Looming Marvelous - Virtual Threads in JavaLooming Marvelous - Virtual Threads in Java
Looming Marvelous - Virtual Threads in Javajexp
 
GraphConnect 2022 - Top 10 Cypher Tuning Tips & Tricks.pptx
GraphConnect 2022 - Top 10 Cypher Tuning Tips & Tricks.pptxGraphConnect 2022 - Top 10 Cypher Tuning Tips & Tricks.pptx
GraphConnect 2022 - Top 10 Cypher Tuning Tips & Tricks.pptxjexp
 
Neo4j Connector Apache Spark FiNCENFiles
Neo4j Connector Apache Spark FiNCENFilesNeo4j Connector Apache Spark FiNCENFiles
Neo4j Connector Apache Spark FiNCENFilesjexp
 
How Graphs Help Investigative Journalists to Connect the Dots
How Graphs Help Investigative Journalists to Connect the DotsHow Graphs Help Investigative Journalists to Connect the Dots
How Graphs Help Investigative Journalists to Connect the Dotsjexp
 
The Home Office. Does it really work?
The Home Office. Does it really work?The Home Office. Does it really work?
The Home Office. Does it really work?jexp
 
Polyglot Applications with GraalVM
Polyglot Applications with GraalVMPolyglot Applications with GraalVM
Polyglot Applications with GraalVMjexp
 
Neo4j Graph Streaming Services with Apache Kafka
Neo4j Graph Streaming Services with Apache KafkaNeo4j Graph Streaming Services with Apache Kafka
Neo4j Graph Streaming Services with Apache Kafkajexp
 
How Graph Databases efficiently store, manage and query connected data at s...
How Graph Databases efficiently  store, manage and query  connected data at s...How Graph Databases efficiently  store, manage and query  connected data at s...
How Graph Databases efficiently store, manage and query connected data at s...jexp
 
APOC Pearls - Whirlwind Tour Through the Neo4j APOC Procedures Library
APOC Pearls - Whirlwind Tour Through the Neo4j APOC Procedures LibraryAPOC Pearls - Whirlwind Tour Through the Neo4j APOC Procedures Library
APOC Pearls - Whirlwind Tour Through the Neo4j APOC Procedures Libraryjexp
 
Refactoring, 2nd Edition
Refactoring, 2nd EditionRefactoring, 2nd Edition
Refactoring, 2nd Editionjexp
 
New Features in Neo4j 3.4 / 3.3 - Graph Algorithms, Spatial, Date-Time & Visu...
New Features in Neo4j 3.4 / 3.3 - Graph Algorithms, Spatial, Date-Time & Visu...New Features in Neo4j 3.4 / 3.3 - Graph Algorithms, Spatial, Date-Time & Visu...
New Features in Neo4j 3.4 / 3.3 - Graph Algorithms, Spatial, Date-Time & Visu...jexp
 
GraphQL - The new "Lingua Franca" for API-Development
GraphQL - The new "Lingua Franca" for API-DevelopmentGraphQL - The new "Lingua Franca" for API-Development
GraphQL - The new "Lingua Franca" for API-Developmentjexp
 
A whirlwind tour of graph databases
A whirlwind tour of graph databasesA whirlwind tour of graph databases
A whirlwind tour of graph databasesjexp
 
Practical Graph Algorithms with Neo4j
Practical Graph Algorithms with Neo4jPractical Graph Algorithms with Neo4j
Practical Graph Algorithms with Neo4jjexp
 
A Game of Data and GraphQL
A Game of Data and GraphQLA Game of Data and GraphQL
A Game of Data and GraphQLjexp
 
Querying Graphs with GraphQL
Querying Graphs with GraphQLQuerying Graphs with GraphQL
Querying Graphs with GraphQLjexp
 
Graphs & Neo4j - Past Present Future
Graphs & Neo4j - Past Present FutureGraphs & Neo4j - Past Present Future
Graphs & Neo4j - Past Present Futurejexp
 
Intro to Graphs and Neo4j
Intro to Graphs and Neo4jIntro to Graphs and Neo4j
Intro to Graphs and Neo4jjexp
 

More from jexp (20)

Looming Marvelous - Virtual Threads in Java Javaland.pdf
Looming Marvelous - Virtual Threads in Java Javaland.pdfLooming Marvelous - Virtual Threads in Java Javaland.pdf
Looming Marvelous - Virtual Threads in Java Javaland.pdf
 
Easing the daily grind with the awesome JDK command line tools
Easing the daily grind with the awesome JDK command line toolsEasing the daily grind with the awesome JDK command line tools
Easing the daily grind with the awesome JDK command line tools
 
Looming Marvelous - Virtual Threads in Java
Looming Marvelous - Virtual Threads in JavaLooming Marvelous - Virtual Threads in Java
Looming Marvelous - Virtual Threads in Java
 
GraphConnect 2022 - Top 10 Cypher Tuning Tips & Tricks.pptx
GraphConnect 2022 - Top 10 Cypher Tuning Tips & Tricks.pptxGraphConnect 2022 - Top 10 Cypher Tuning Tips & Tricks.pptx
GraphConnect 2022 - Top 10 Cypher Tuning Tips & Tricks.pptx
 
Neo4j Connector Apache Spark FiNCENFiles
Neo4j Connector Apache Spark FiNCENFilesNeo4j Connector Apache Spark FiNCENFiles
Neo4j Connector Apache Spark FiNCENFiles
 
How Graphs Help Investigative Journalists to Connect the Dots
How Graphs Help Investigative Journalists to Connect the DotsHow Graphs Help Investigative Journalists to Connect the Dots
How Graphs Help Investigative Journalists to Connect the Dots
 
The Home Office. Does it really work?
The Home Office. Does it really work?The Home Office. Does it really work?
The Home Office. Does it really work?
 
Polyglot Applications with GraalVM
Polyglot Applications with GraalVMPolyglot Applications with GraalVM
Polyglot Applications with GraalVM
 
Neo4j Graph Streaming Services with Apache Kafka
Neo4j Graph Streaming Services with Apache KafkaNeo4j Graph Streaming Services with Apache Kafka
Neo4j Graph Streaming Services with Apache Kafka
 
How Graph Databases efficiently store, manage and query connected data at s...
How Graph Databases efficiently  store, manage and query  connected data at s...How Graph Databases efficiently  store, manage and query  connected data at s...
How Graph Databases efficiently store, manage and query connected data at s...
 
APOC Pearls - Whirlwind Tour Through the Neo4j APOC Procedures Library
APOC Pearls - Whirlwind Tour Through the Neo4j APOC Procedures LibraryAPOC Pearls - Whirlwind Tour Through the Neo4j APOC Procedures Library
APOC Pearls - Whirlwind Tour Through the Neo4j APOC Procedures Library
 
Refactoring, 2nd Edition
Refactoring, 2nd EditionRefactoring, 2nd Edition
Refactoring, 2nd Edition
 
New Features in Neo4j 3.4 / 3.3 - Graph Algorithms, Spatial, Date-Time & Visu...
New Features in Neo4j 3.4 / 3.3 - Graph Algorithms, Spatial, Date-Time & Visu...New Features in Neo4j 3.4 / 3.3 - Graph Algorithms, Spatial, Date-Time & Visu...
New Features in Neo4j 3.4 / 3.3 - Graph Algorithms, Spatial, Date-Time & Visu...
 
GraphQL - The new "Lingua Franca" for API-Development
GraphQL - The new "Lingua Franca" for API-DevelopmentGraphQL - The new "Lingua Franca" for API-Development
GraphQL - The new "Lingua Franca" for API-Development
 
A whirlwind tour of graph databases
A whirlwind tour of graph databasesA whirlwind tour of graph databases
A whirlwind tour of graph databases
 
Practical Graph Algorithms with Neo4j
Practical Graph Algorithms with Neo4jPractical Graph Algorithms with Neo4j
Practical Graph Algorithms with Neo4j
 
A Game of Data and GraphQL
A Game of Data and GraphQLA Game of Data and GraphQL
A Game of Data and GraphQL
 
Querying Graphs with GraphQL
Querying Graphs with GraphQLQuerying Graphs with GraphQL
Querying Graphs with GraphQL
 
Graphs & Neo4j - Past Present Future
Graphs & Neo4j - Past Present FutureGraphs & Neo4j - Past Present Future
Graphs & Neo4j - Past Present Future
 
Intro to Graphs and Neo4j
Intro to Graphs and Neo4jIntro to Graphs and Neo4j
Intro to Graphs and Neo4j
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard37
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAnitaRaj43
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMKumar Satyam
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 

Recently uploaded (20)

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 

Neo4j & (J) Ruby Presentation JRubyConf.EU

  • 1. (Neo4j)-[: ]->(J)Ruby 1
  • 2. 2
  • 4. A graph database... NO: not for charts & diagrams, or vector artwork 3
  • 5. A graph database... NO: not for charts & diagrams, or vector artwork YES: for storing data that is structured as a graph 3
  • 6. A graph database... NO: not for charts & diagrams, or vector artwork YES: for storing data that is structured as a graph remember linked lists, trees? 3
  • 7. A graph database... NO: not for charts & diagrams, or vector artwork YES: for storing data that is structured as a graph remember linked lists, trees? graphs are the general-purpose data structure 3
  • 8. A graph database... NO: not for charts & diagrams, or vector artwork YES: for storing data that is structured as a graph remember linked lists, trees? graphs are the general-purpose data structure “A relational database may tell you the average age of everyone in this session, but a graph database will tell you who is most likely to buy you a beer.” 3
  • 9. 4
  • 13. You know relational foo bar 4
  • 14. You know relational foo foo_bar bar 4
  • 15. You know relational foo foo_bar bar 4
  • 16. You know relational foo foo_bar bar 4
  • 17. You know relational foo foo_bar bar 4
  • 18. You know relational now consider relationships... 4
  • 19. You know relational now consider relationships... 4
  • 20. You know relational now consider relationships... 4
  • 21. You know relational now consider relationships... 4
  • 22. You know relational now consider relationships... 4
  • 23. You know relational now consider relationships... 4
  • 24. 4
  • 25. 5
  • 26. We're talking about a Property Graph 5
  • 27. We're talking about a Property Graph Nodes 5
  • 28. We're talking about a Property Graph Nodes Relationships 5
  • 29. We're talking about a Property 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) 5
  • 30. 5
  • 31. And, but, so how do you query this "graph" database? 6
  • 32. And, but, so how do you query this "graph" database? *hint* Not by writing Map-Reduce Jobs 6
  • 33. 7
  • 34. You traverse the graph 7
  • 35. You traverse the graph 7
  • 36. You traverse the graph // lookup starting point in an index START n=node:People(name = ‘Andreas’) And rea s 7
  • 37. You traverse the graph // lookup starting point in an index then traverse to find results START n=node:People(name ==‘Andreas’) me=node:People(name ‘Andreas’ MATCH (me)-[:FRIEND]-(friend)-[:FRIEND]-(friend2) RETURN friend2 And rea s 7
  • 38. 7
  • 39. START user = node(1) MATCH user -[user_skill]-> skill RETURN skill, user_skill SELECT skills.*, user_skill.* FROM users JOIN user_skill ON users.id = user_skill.user_id JOIN skills ON user_skill.skill_id = skill.id WHERE users.id = 1 8
  • 40. (Neo4j)-[: ]->(J)Ruby 9
  • 41. Bindings REST:// 10
  • 42. Bindings REST:// 10
  • 43. neoid Jogger neology neography Pacer Server #REST embedded JRuby Cypher- DSL neo4j.rb roll Rails/ AR your own 11
  • 44. neo4j.rb by Andreas Ronge gem install neo4j require 'rubygems' require 'neo4j' class Person include Neo4j::NodeMixin property :name, :age, :rank index :name has_n :friends end Neo4j::Transaction.run do neo = Person.new :name=>'Neo', :age=>29 morpheus = Person.new :name=>'Morpheus', :rank=>'Captain' neo.friends << morpheus end neo.friends.each {|p|...} neo4j.rubyforge.org
  • 45. neography by Max De Marzi @neo = Neography::Rest.new def suggestions_for(node) node.incoming(:friends) .order("breadth first") .uniqueness("node global") .filter("position.length() == 2;").depth(2) end john = Neography::Node.create("name" =>'John') .... luke = Neography::Node.create("name" =>'Luke') johnathan.both(:friends) << mark ... luke.both(:friends) << mary john.both(:friends) << luke puts "John should become friends with #{suggestions_for(john).map{|n| n.name }.join(', ')}" github.com/maxdemarzi/neography
  • 46. pacer by Darrick Wiebe (DSL for TP Pipes) neo = Pacer.neo '/tmp/neo_demo' michael = neo.create_vertex :name => 'Michael', :type => 'user' group = neo.create_vertex :name => 'Neo4j', :type => 'group' neo.v.properties # Show node properties #<V[1024]> #<V[1025]> Total: 2 => #<GraphV> Add many relationships: group.add_edges_to :member, neo.v(:type => 'user') # Traversals/Suggestions friends = person.out_e(:friend).in_v(:type => 'user') friends.out_e(:friend).in_v(:type => 'person') .except(friends).except(person).most_frequent(0...10) github.com/pangloss/pacer
  • 47. jogger by Jannis Hermann (MoviePilot) class Jogger module NamedTraversals # Traverse to somebody's woman friends def self.friends(current_traversal, gender) t = current_traversal.in(:friends) t = t.filter(gender: gender) end # Group and sort def self.top_list(current_traversal, type) t = current_traversal.out(type) t = t.filter(type: 'Movie') t = t.group_count{ |v| v } end end end github.com/moviepilot/jogger
  • 48. Sites created with Ruby & Neo4j
  • 49. Simple & Cool Viz: Ruby & JavaScript maxdemarzi.com
  • 50. Go get hacking ๏ neo4j.org ๏ devcenter.heroku.com/articles/neo4j ๏ http://maxdemarzi.com/tag/ruby/ ๏ neo4j.rubyforge.org / neo4jrb google group ๏ video.neo4j.org/videos/search/?query=ruby ๏ www.markhneedham.com/blog/tag/neo4j ๏ .... 18
  • 51. Some Code github.com/jexp/rfid-graph based on Max De Marzi‘s Neovigator based on Michael Aufreiter‘s Ask Ken 19
  • 52. Some Code if we have time left github.com/jexp/rfid-graph based on Max De Marzi‘s Neovigator based on Michael Aufreiter‘s Ask Ken 19
  • 53. OpenBeacon JSON format { "id":3456, "api":{"name":"openbeacon-tracker","ver":"0.9.1-dirty"}, "time":1344647727, "packets":{ "per_key":[0,0,0,0,0,0,0,0,15536], "rate":61, "invalid_protocol":2, "crc_ok":15538 }, "tag":[ {"id":598,"px":200,"py":100,"key":8,"reader":1126}, {"id":585,"px":200,"py":100,"key":8,"reader":1126,"button":true}, {"id":574,"px":200,"py":100,"key":8,"reader":1126}], "reader":[ {"id":1126,"px":200,"py":100,"room":1,"floor":1,"group":1}], "edge":[ {"tag":[585,598],"power":5}, {"tag":[574,598],"power":8}]} openbeacon.org
  • 54. Neo4j data storage def add_tags(tags) query("start n=node(0) foreach (tag in {tags} : create t={ tag: tag })", {:tags => tags}) end def batch_connect_simple(tags, time = Time.now.to_i) prepared = tags.map { |tag| prepare(tag[0],tag[1],time); } @cypher.batch(prepared) end # tag1-[talk:TALKED {begin,end}]->tag2 def prepare(tag1,tag2,time = Time.now.to_i) (tag1,tag2) = [tag2, tag1] if tag2.to_i < tag1.to_i { :query => "START tag1=node:node_auto_index(tag={tag1}), tag2=node:node_auto_index(tag={tag2}) CREATE UNIQUE tag1-[talk:TALKED]->tag2 set talk.begin = coalesce(talk.begin?,{now}), talk.end = {now}", :params => {:tag1 => tag1, :tag2 => tag2, :now => time}} 21
  • 55. Neo4j data querying & mangling QUERY = "START tag=node({id}) MATCH tag-[r:TALKED]-other<-[?:HAS_TAG]-other_user RETURN ID(other) as id, other.tag as tag, r, type(r) as type, coalesce(other_user.name?,other.tag) as name" def direction(node, rel) rel.end_node.to_i == node ? "Incoming" : "Outgoing" end get '/resources/show' do content_type :json props = get_properties(node_for(params[:id])) connections = cypher.query(QUERY,{:id => props["id"]}) rels = connections.group_by { |row| [direction(id,row["r"]), row["type"]] } attributes = rels.collect { |keys, values| {:id => keys.last, :name => keys.join(":"), :values => values } } @node = {:details_html => "<h2>User: #{user}</h2><p>#{get_info(props)}</p>", :data => {:id => id, :attributes => attributes, :name => props["name"] }}.to_json end 22
  • 56. Pusher RFID data stream require ,pusher-client‘ socket = PusherClient::Socket.new(,KEY‘) socket.subscribe(,openbeacon‘) socket BRACKET ,openbeacon‘ BRACKET .bind(,sighting‘) do PIPE json PIPE ... end socket.connect 23

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. \n
  57. \n
  58. \n
  59. \n
  60. \n
  61. \n
  62. \n
  63. \n
  64. \n
  65. \n
  66. \n
  67. \n
  68. \n
  69. \n
  70. \n
  71. \n
  72. \n
  73. \n
  74. \n
  75. \n
  76. \n
  77. \n
  78. \n
  79. \n
  80. \n
  81. \n
  82. \n
  83. \n
  84. \n
  85. \n
  86. \n
  87. \n
  88. \n
  89. \n
  90. \n
  91. \n
  92. \n
  93. \n
  94. \n
  95. \n
  96. \n
  97. \n
  98. \n
  99. \n
  100. \n
  101. \n
  102. \n
  103. \n
  104. \n
  105. \n