Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
A Clojure library to query Neo4J databases using Graph-Zip syntax
Clojure
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
src/neo_zip
.gitignore
README.md
project.clj

README.md

Neo-Zip

Neo-Zip provides an easier-to-use syntax for traversing Neo4J graphs using the syntax of Graph-Zip.

It is built atop Graph-Zip and Borneo (a Clojure Neo4J wrapper).

Lein dependency:

[neo-zip "0.3"]

Usage

There is only one function in Neo-Zip - neo-zip, which is used to get a zipper that is compatible with Graph-Zip.

It must be used inside a with-db! or with-local-db! block:

(use 'neo-zip.core :only [neo-zip])
(require '[borneo.core :as neo]
         '[graph-zip.core :as g])


(neo/with-local-db! "db/testNeo"
                    (g/zip-> (neo-zip)
                             ... ))

An example graph:

For these examples, we use the Matrix social graph as per the Neo4J documentation. To set this up, run the following Clojure expression (changing the database path if required):

;; Code from Borneo project home-page.
(neo/with-local-db! "db/testNeo"
 (neo/purge!)
  (let [humans (neo/create-child! :humans nil)
        programs (neo/create-child! :programs nil)

        ;; add programs
        smith (neo/create-child! programs :program
                                 {:name "Agent Smith"
                                  :language "C++"
                                  :age 40})
        architect (neo/create-child! programs :program
                                     {:name "Architect"
                                      :language "Clojure"
                                      :age 600})

        ;; add humans
        the-one (neo/create-child! humans :human
                                   {:name "Thomas Anderson"
                                    :age 29})
        trinity (neo/create-child! humans :human
                                   {:name "Trinity"
                                    :age 27})
        morpheus (neo/create-child! humans :human
                                    {:name "Morpheus"
                                     :rank "Captain"
                                     :age 35})
        cypher (neo/create-child! humans :human
                                  {:name "Cypher"})]

        ;; add relationships

        (neo/create-rel! the-one :knows trinity)
        (neo/create-rel! the-one :knows morpheus)
        (neo/create-rel! morpheus :knows trinity)
        (neo/create-rel! morpheus :knows cypher)
        (neo/set-props! (neo/create-rel! cypher :knows smith)
                        {:disclosure "secret"
                         :age 6})
        (neo/create-rel! smith :knows architect)
        (neo/create-rel! trinity :loves the-one)))

Notice that mutations to the graph are made using the Borneo library - Neo-Zip is a read-only syntax.

We can then query the graph using Neo-Zip's graph-zip syntax:

(neo/with-local-db! "db/testNeo"
 (g/zip-> (neo-zip)
          :humans
          :human
          :name
          g/node))

;; -> ("Cypher" "Morpheus" "Trinity" "Thomas Anderson")

We can also use the 'incoming' function of graph-zip to find out the name of everyone that knows Trinity :-

(neo/with-local-db! "db/testNeo"
 (g/zip-> (neo-zip)
          :humans
          :human
          (g/prop= :name "Trinity")
          (g/incoming :knows)
          :name
          g/node))
;; -> ("Morpheus" "Thomas Anderson")

For more examples of how to use Graph-Zip and Borneo, please refer to their relevant projects:

License

Copyright (C) 2012 James Henderson

Distributed under the Eclipse Public License, the same as Clojure.

Something went wrong with that request. Please try again.