Code Monkey home page Code Monkey logo

graffmaker's Introduction

##Graffmaker

Straighforward data generation tool for neo4J.
Creates simple graph structures for testing and playing around with ideas in Neo4J.

###Using Graffmaker

####Install

npm install graffmaker

####Include Library

Include the graffmaker library:

var gm = require('graffmaker');

Connect to Neo4J:

var model = gm.connect();       // connects to 'http://localhost:7474'

or

var model = gm.connect('http://host:port');

Now you have a model object to do stuff with

####Defines "Types" of Node

Define the node structures you want to use by calling model.define with all the fields you want to be available in the node:

var Car    = new model.define("make", "model", "engine", "seats");
var Person = new model.define("firstName", "lstName");
var Home   = new model.define("name");

This is so you can do this kind of OO thing later:

var myCar = new Car('Honda', 'CRV', '2.2', 5);

then:

model.createNode(myCar);

That's one node in the database. Sorted.

####Make Nodes and Relationships

Or actually populate Neo4J with some useful data:

model.createNode(new Person("John", "Smith"))
    .then(
        model.connectTo([
            { node: new Car('Honda', 'CRV', '2.2', 5), rel: 'drives' },
            { node: new type.Home("Flat 2B"), rel: 'lives-in' }
        ])
    );

(note: example code may be found in example-1.js, example-2.js, example-3.js)

Graph connections can be chained, with the last node created (the Home in the example above), being passed to the next 'then' clause.

Relationships work both ways so

model.connectTo()

joins the previously created node to the current one and

model.connectFrom()

joins the current node to the previous

Both model.connectTo and model.connectFrom take an array of objects of the form (node: …, rel: …} where node is the graph node data and rel is the relationship required between this one and the previous. It's therefore entirely acceptable to skip the pseudo OO step above and simply call:

model.createNode({name: 'Dr Who', type: 'timelord'})
    .then(model.connectTo([{node: {name: 'cybermen', type: 'cyborg' }, rel: 'enemy'}]))
    .then(model.connectTo([{node: {name: 'Mondas', type: 'planet' }, rel: 'originates'}]));

To actually do the population first make sure Neo4J is running (lib/models.js expects it to be local machine) and then simply run:

node {your_js_file}

graffmaker's People

Contributors

julianbrowne avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

graffmaker's Issues

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.