Giter VIP home page Giter VIP logo

cayley-ruby's Introduction

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

cayley-ruby's People

Contributors

reneklacan avatar ready4god2513 avatar

Stargazers

 avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.