Project

cayley

0.01
No commit activity in last 3 years
No release in over 3 years
Ruby library for working with Google's Cayley graph database
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 3.1

Runtime

~> 0.8.5
~> 3.2.0
~> 1.8.1
 Project Readme

cayley-ruby

A ruby library for working with Google's Cayley graph database.

Installation

You can install it via gem

gem install cayley

Usage

Start your Cayley

# example using 30kmoviedata from cayley's repository
./cayley http --dbpath=30kmoviedata.nq.gz

You 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').all

You 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']
end

If 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