Your SlideShare is downloading. ×
0
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Neo4j & (J) Ruby Presentation JRubyConf.EU
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Neo4j & (J) Ruby Presentation JRubyConf.EU

2,215

Published on

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,215
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
37
Comments
0
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Transcript

    • 1. (Neo4j)-[: ]->(J)Ruby 1
    • 2. 2
    • 3. A graph database... 3
    • 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
    • 10. You know relational 4
    • 11. You know relational 4
    • 12. You know relational foo 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 relationalnow consider relationships... 4
    • 19. You know relationalnow consider relationships... 4
    • 20. You know relationalnow consider relationships... 4
    • 21. You know relationalnow consider relationships... 4
    • 22. You know relationalnow consider relationships... 4
    • 23. You know relationalnow consider relationships... 4
    • 24. 4
    • 25. 5
    • 26. Were talking about aProperty Graph 5
    • 27. Were talking about aProperty Graph Nodes 5
    • 28. Were talking about aProperty Graph Nodes Relationships 5
    • 29. Were talking about aProperty 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 youquery this "graph" database? 6
    • 32. And, but, so how do youquery 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 indexSTART n=node:People(name = ‘Andreas’) And rea s 7
    • 37. You traverse the graph// lookup starting point in an index then traverse to find resultsSTART 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_skillSELECT skills.*, user_skill.*FROM usersJOIN user_skill ON users.id = user_skill.user_idJOIN 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 neologyneography 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 somebodys 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 & JavaScriptmaxdemarzi.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 Codegithub.com/jexp/rfid-graph based onMax De Marzi‘s Neovigator based onMichael Aufreiter‘s Ask Ken 19
    • 52. Some Code if we have time leftgithub.com/jexp/rfid-graph based onMax De Marzi‘s Neovigator based onMichael 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
    • 57. Neovigator processing.js visualization 24

    ×