cayley-ruby
A ruby library for working with Google's Cayley graph database.
Installation
You can install it via gem
gem install cayleyUsage
Start your Cayley
# example using 30kmoviedata from cayley's repository
./cayley http --dbpath=30kmoviedata.nq.gzYou can use methods from Gremlin API documentation, just translate method names to snake style equivalent.
As a first step you need to create your client
require 'cayley'
graph = Cayley::Graph.new
# or
graph = Cayley::Graph.new(host: 'localhost', port: 64210)Then using 30kmovies.nt db from cayley's repository you can do this
graph.vertex.get_limit(5)
graph.vertex('Humphrey Bogart').all
graph.v('Humphrey Bogart').all
graph.v('Humphrey Bogart').in('name').all
graph.v('Casablanca').in('name').all
graph.v.has('name', 'Casablanca').allYou can also use morphism
film_to_actor = graph.morphism
.out('/film/film/starring')
.out('/film/performance/actor')
graph.v
.has('name', 'Casablanca')
.follow(film_to_actor)
.out('name').all
For more info take a look at Cayley's repository
Advanced
By default result of your queries are wrapped in Hashie::Mash so you can do things like these
graph.v.all.each do |result|
puts result.id # instead of result['id']
endIf you want to use plain ruby hashes you can disable wrapping by
graph = Cayley::Graph.new(result_wrapper: nil)Or you can use some custom wrapper if you put class instead of nil.
Debugging
If you are not sure why you are getting nil as a result of your query and you are not able to find out the solution you can turn on debug mode where used Gremlin query is printed out.
graph = Cayley::Graph.new(debug: true)TODO
- logger
- tests