• Stars
    star
    603
  • Rank 71,454 (Top 2 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 13 years ago
  • Updated about 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A thin Ruby wrapper to the Neo4j Rest API

Neography

  • Gem Version
  • Build Status
  • Code Climate
  • Coverage Status

Welcome to Neography

Neography is a thin Ruby wrapper to the Neo4j Rest API, for more information:

If you want to utilize the full power of Neo4j, you will want to use JRuby and the excellent Neo4j.rb gem at https://github.com/andreasronge/neo4j by Andreas Ronge

Installation

Gemfile

Add neography to your Gemfile:

gem 'neography'

And run Bundler:

$ bundle

Manually:

Or install neography manually:

$ gem install 'neography'

And require the gem in your Ruby code:

require 'rubygems'
require 'neography'

Read the wiki for information about dependencies.

Rake tasks are available for downloading, installing and running Neo4j.

Usage

Configuration and initialization

Configure Neography as follows:

# these are the default values:
Neography.configure do |config|
  config.protocol             = "http"
  config.server               = "localhost"
  config.port                 = 7474
  config.directory            = ""  # prefix this path with '/'
  config.cypher_path          = "/cypher"
  config.gremlin_path         = "/ext/GremlinPlugin/graphdb/execute_script"
  config.log_file             = "neography.log"
  config.log_enabled          = false
  config.slow_log_threshold   = 0    # time in ms for query logging
  config.max_threads          = 20
  config.authentication       = nil  # 'basic' or 'digest'
  config.username             = nil
  config.password             = nil
  config.parser               = MultiJsonParser
  config.http_send_timeout    = 1200
  config.http_receive_timeout = 1200
  config.persistent           = true
  end

Then initialize a Rest instance:

@neo = Neography::Rest.new
@neo = Neography::Rest.new({:authentication => 'basic', :username => "neo4j", :password => "swordfish"})
@neo = Neography::Rest.new("http://neo4j:swordfish@localhost:7474")

For overriding these default and other initialization methods, see the configuration and initialization page in the Wiki.

REST API

Neography supports the creation and retrieval of nodes and relationships through the Neo4j REST interface. It supports indexes, Gremlin scripts, Cypher queries and batch operations.

Some of this functionality is shown here, but all of it is explained in the following Wiki pages:

2.0 Only features:

1.8+ features:

Some example usage:

# Node creation:
node1 = @neo.create_node("age" => 31, "name" => "Max")
node2 = @neo.create_node("age" => 33, "name" => "Roel")

# Node properties:
@neo.set_node_properties(node1, {"weight" => 200})

# Relationships between nodes:
@neo.create_relationship("coding_buddies", node1, node2)

# Get node relationships:
@neo.get_node_relationships(node2, "in", "coding_buddies")

# Use indexes:
@neo.add_node_to_index("people", "name", "max", node1)
@neo.get_node_index("people", "name", "max")

# Batches:
@neo.batch [:create_node, {"name" => "Max"}],
           [:create_node, {"name" => "Marc"}]
           
# Cypher queries:
@neo.execute_query("start n=node(0) return n")
           

You can also use the cypher gem instead of writing cypher as text.

node(1).outgoing(rel(:friends).where{|r| r[:since] == 1994})

would become:

START me=node(1) 
MATCH (me)-[friend_rel:`friends`]->(friends) 
WHERE (friend_rel.since = 1994) 
RETURN friends

This is just a small sample of the full API, see the Wiki documentation for the full API.

Neography raises REST API errors as Ruby errors, see the wiki page about errors. (Note: older versions of Neography did not raise any errors!)

Phase 2

Trying to mimic the Neo4j.rb API.

Now we are returning full objects. The properties of the node or relationship can be accessed directly (node.name). The Neo4j ID is available by using node.neo_id.

Some of this functionality is shown here, but all of it is explained in the following Wiki pages:

# create two nodes:
n1 = Neography::Node.create("age" => 31, "name" => "Max")
n2 = Neography::Node.create("age" => 33, "name" => "Roel")

n1.exist? # => true

# get and change some properties:
n1[:age]         # => 31
n1.name          # => "Max"
n1[:age]  = 32   # change property
n1.weight = 190  # new property
n1.age    = nil  # remove property

# add a relationship between nodes:
new_rel = Neography::Relationship.create(:coding_buddies, n1, n2)

# remove a relationship:
new_rel.del

# add a relationship on nodes:
n1.outgoing(:coding_buddies) << n2

# more advanced relationship traversal:
n1.outgoing(:friends)                                                # Get nodes related by outgoing friends relationship
n1.outgoing(:friends).depth(2).include_start_node                    # Get n1 and nodes related by friends and friends of friends

n1.rel?(:outgoing, :friends)                                         # Has outgoing friends relationship
n1.rels(:friends,:work).outgoing                                     # Get outgoing friends and work relationships

n1.all_paths_to(n2).incoming(:friends).depth(4)                      # Gets all paths of a specified type
n1.shortest_path_to(n2).incoming(:friends).depth(4).nodes            # Gets just nodes in path

This is just a small sample of the full API, see the Wiki documentation for the full API.

More

Examples

Some example code.

Testing

Some tips about testing.

Related Neo4j projects

Complement to Neography are the:

An alternative to Neography is Architect4r by Maximilian Schulz

Neography in the Wild

Getting started with Neography

Contributing

Please create a new issue if you run into any bugs.

Contribute patches via pull requests.

Help

If you are just starting out, or need help send me an e-mail at [email protected].

Check you my blog at http://maxdemarzi.com where I have more Neography examples.

Licenses

More Repositories

1

neovigator

Demo visualization of Neo4j data
JavaScript
162
star
2

neo_graph_search

A POC at replicating Facebook Graph Search with Cypher and Neo4j
JavaScript
102
star
3

neoflix

JavaScript
44
star
4

graph_processing

Graph Processing Algorithms on top of Neo4j
Java
38
star
5

decision_trees_with_rules

POC Decision Tree traverser with rules
Java
38
star
6

d3_js_network

JavaScript
24
star
7

neosocial

Example application to connect to one of the social networks
JavaScript
23
star
8

neo_three

Ruby
22
star
9

madcodertv

Roku Channel for Development Videos
21
star
10

uranusdb

Uranus DB
Java
19
star
11

neo_crunch

Neo4j and the Crunchbase API mashup
JavaScript
19
star
12

d3_js_intro

JavaScript
19
star
13

neo_sigma

JavaScript
19
star
14

neo_visual_search

Neo4j POC to Integrate VisualSearch.js and Cypher
JavaScript
18
star
15

dating_site

Example Dating Site with Neo4j
Java
15
star
16

grittier_ext

A Neo4j Based Twitter Clone Backend
Java
15
star
17

neo_listens

Sample Event Listener / Triggers
Java
15
star
18

neoflights

Flight Search with Neo4j
Java
14
star
19

neo_news

A POC Neo4j Application about the News
Ruby
13
star
20

cypher_batch_writer

Let's try batching some cypher queries
Java
11
star
21

hive_plot

JavaScript
11
star
22

rule_matcher

Rule Matcher Stored Procedures
Java
11
star
23

neo_permissions

Permission Resolution with Neo4j
Java
11
star
24

neochat

Proof of Concept Chatbot
Java
10
star
25

neo_love

A POC Dating site with Neo4j
CSS
10
star
26

neo_concept

Import for Concept Net 5
Ruby
10
star
27

power_grid

Multi-Thread a Traversal to find the energization status of a power grid
Java
9
star
28

neo_airlines

Modeling and Querying Flight Data
Java
9
star
29

neo_pay

Online Payments Risk Management with Neo4j POC
Java
9
star
30

neomatch

A sample application matching jobs with candidates
CSS
9
star
31

BatchWriterService

A POC Batch Writer Service for scaling Neo4j Writes
Java
9
star
32

neotime

JavaScript
9
star
33

nomnomnom

Restaurant Recommendation
CSS
8
star
34

neo_generate

Generate a sample graph by creating nodes and relationship csv files as input to the Neo4j Batch Importer
Ruby
7
star
35

grittier_web

A Neo4j Based Twitter Clone Frontend
HTML
7
star
36

neo4j_cuckoo

Using a Cuckoo filter to speed up relationship creation
Java
7
star
37

kung_fu

Ruby
6
star
38

learn_neo4j

CoffeeScript
6
star
39

router

POC Network routing inside Neo4j
Java
5
star
40

neo_lua

Playing with Lua and Neo4j
Lua
5
star
41

choo_choo

Proof of Concept Weighted Shortest Path of Railroads
Java
5
star
42

neo_hubway

Hubway Challenge dataset into a Neo4j graph database
JavaScript
5
star
43

neo_warmup

Warm up Neo4j
Java
5
star
44

distinct_network

Stored Procedure to get the distinct network of a node 4 levels out
Java
5
star
45

neo_cc

Unmanaged Extension for Connected Components in Neo4j
Java
5
star
46

louvain

Cluster nodes by Louvain Method
Java
4
star
47

instacart

Instacart Market Basket Analysis
Java
4
star
48

triton

C++
4
star
49

neo_ivr

Sample Neo4j IVR with Twilio
JavaScript
4
star
50

archetype_api

Archetype API
Java
4
star
51

order_workflow

POC Order Workflow Management with Neo4j
Java
4
star
52

memgraph_benchmark

Reproducing the memgraph benchmark using Gatling
Scala
4
star
53

que_dicen

POC building subgraphs of documents
Java
4
star
54

Camel

Coming Soon page in Sinatra, using Campaign Monitor, hosted on Heroku
Ruby
4
star
55

neo_intro

A condensed list of examples using Neography with Neo4j
Ruby
4
star
56

nerdier

It is a ruby gem which provides an interface to NERD http://nerd.eurecom.fr
Ruby
3
star
57

boolean_filtering

Proof of Concept Boolean Logic Filtering in Neo4j
Java
3
star
58

branches

POC Decision Stream into Neo4j
Java
3
star
59

archetype_extension

High Performance Neo4j Sample Service
Java
3
star
60

finding_triplets

Finding triplets using Neo4j
Java
3
star
61

neowaza

Neo4j App for Waza
JavaScript
3
star
62

neo_hpce

Neo4j High Performance Compressed Edition Code
Java
3
star
63

parallel_khop

Parallelizing k-hop in Neo4j
Java
3
star
64

import_maxmind

Import the MaxMind Cities Database into Neo4j
Java
3
star
65

cypher_hip_hop

Cypher Stored Procedure for odd even traversal
Java
3
star
66

tucume_sprocs

Tucume Stored Procedures
Java
3
star
67

neo_doc

A Neo4j version of DocGraph, the doctor social graph
Ruby
3
star
68

conference_graph

POC for mapping the Social Graph of Conferences
Ruby
3
star
69

neo4j_kafka_poc

POC using Kakfa with Neo4j
2
star
70

benchmarks

Scala
2
star
71

neo_gatling

Sample Neo4j Gatling Performance Testing Files
Scala
2
star
72

GuancialeDB

POC mixing Guava and Chronicle to make a multi-model database
Java
2
star
73

linkedin_match

Ruby
2
star
74

neo_chronicle_index

Java
2
star
75

neo_spacecargo

Sample Bi-Directional Traversal Extension
Java
2
star
76

neo_accumulate_writes

POC performance improvement of accumulated writes
Scala
2
star
77

neo_recommends

Different algorithms for recommendations using Neo4j
Ruby
2
star
78

neo_grpc

POC gRPC Kernel Extension for Neo4j
Java
2
star
79

neo_loves

A Java Version of Neo_Love
Ruby
2
star
80

facebook_plugin

A Neo4j Facebook Plugin
Java
2
star
81

neo_max_flow

Max Flow in Neo4j
Java
2
star
82

stepwise_decision_trees

POC of stepping through a decision tree one
Java
2
star
83

pagerank_spi

Java
2
star
84

processing_js_intro

Ruby
2
star
85

neo_travis

Example Neo4j Extension Testing using Travis-CI
Java
2
star
86

neo4j_vs_neo4c

Simple Traversal Performance Test
Java
1
star
87

fofs_in_java_api

Unmanaged Extension for Friends of Friends Recommendations in Neo4j 2.0
Java
1
star
88

neo_similar

Example Match Making site for people who are similar to me.
CSS
1
star
89

knn

Stored Procedure to find the k-neighborhood of a node
Java
1
star
90

k2tree

POC k2tree relationship index
Java
1
star
91

wrong_address

Find likely wrong addresses by exploring known connected addresses
Java
1
star
92

related_documents

Example Stored Procedure
Java
1
star
93

one_direction

Stored Procedure in Neo4j 4.1.x
Java
1
star
94

unique_paths

Stored Procedure to find unique nodes.
Java
1
star
95

best_neighbors

POC for best neighbors
Java
1
star
96

ChronicleGraph

Messing around with Chronicle to see how it would handle small graphs
Java
1
star
97

neopinion

Ruby
1
star
98

dense

A way to mitigate the dense node problem
Java
1
star
99

medicare

Import Medicare Data into Neo4j
Java
1
star
100

property-level-permissions

Cypher Stored Procedures for Property Level Permissions
Java
1
star