At GrapheneDB, we are frequently approached by developers working on Neo4j-powered applications, with questions about graph modeling. In this post, we will walk through the process of generating a custom graph with sample data and then populating your GrapheneDB Neo4j instance with it.
If you have data, we usually recommend importing it into Neo4j as outlined in a previous blog post. At that point, you can model the problem, run sample queries and iterate until you get the results you want.
But what if you don’t have any real-world data available? Then generating a sample dataset is probably the best option.
To get started, we recommend Graphgen, a component of the Neoxygen set of tools developed by Christophe Willemsen. It’s a free, open-source, web-based graph generator that you can use to populate Neo4j graphs with sample data. It has following features:
- A wide range of sample data providers: people’s names, addresses, phone numbers, company names, email addresses, domain names, etc.
- It relies on a sort of pseudo-Cypher syntax, with the ability to create complex structures
- and… it’s also capable of populating GrapheneDB instances!
Let’s walk through a detailed example, focusing on people working at companies and the friendship relationship between them.
Step 1: Provision your Neo4j database on GrapheneDB
If you haven’t already, sign up for a free GrapheneDB account at www.graphenedb.com. Once logged in, create a new, sandbox database. It’s free!
Step 2: Generate the dataset
Let’s model a simple graph with people and companies:
- People will be stored as nodes with label
Personand a property
- Companies will be stored as nodes with label
Companyand a property
Personnode can have a
KNOWSrelationship to other
- Person nodes have a
WORKS_ATrelationship to a
In order to generate this in Graphgen, we will need to describe the pattern in pseudo-Cypher syntax:
This short snippet will generate:
- 35 nodes with the Person label and a randomized full name property
- 10 companies with random company names
- A relationship WORKS_AT connecting every person to a single random company (n..1)
- And relationships KNOWS between the Person nodes (many to many, n..n)
Notice the syntax is almost standard Cypher, but with some simple additions to specify properties using formatters, indicate the amount of nodes to create, define the relationships and their cardinality. For further details please read the project documentation.
Next, open graphgen.neoxygen.io, put your code snippet in the text area and hit the Generate button. The resulting dataset will be rendered as an interactive graph which you can navigate.
Step 3: Populate your GrapheneDB Neo4j instance with the generated dataset
Click on the Populate your database button. A modal dialog will pop up, with fields for the URL, username and password.
Fill out these fields with the connection details located in the Connection tab for your Neo4j instance in the GrapheneDB user interface: URL, username and password.
Step 4: Browse and query your generated dataset on GrapheneDB
Loading the generated graph into your GrapheneDB should take just a few seconds. After the process is completed, go back to GrapheneDB’s interface.
In the overview tab, use the Launch button fire up Neo4j’s web-based browser UI.
If you, like us, also find Graphgen a useful tool, make sure to say thanks to Christophe for putting it together and stay tuned to his Twitter account for some nice upcoming features.
Graphgen is open-source and you can also have a look at other great Neo4j related tools Christophe put together at neoxygen.io, like neoclient, a PHP client for Neo4j which is also supported by GrapheneDB.