SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Mehr von 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
 

Mehr von 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
 

Kürzlich hochgeladen

A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024SynarionITSolutions
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
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
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 

Kürzlich hochgeladen (20)

A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
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
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

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

Hinweis der Redaktion

  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