Getting to Know You, Getting to Know All About You!

Brooke Cagle on Unsplash

Want to dabble in graphs with family and friends? Not quite sure where to start? How about a quick and dirty trick using Google Forms, Google Sheets and a Neo4j Sandbox?

Where Do I Start?

So you’ve heard about graphs, they sound like fun! Now, you’re wondering where to start. Maybe you’ve had a go with one use cases in the Neo4j Sandbox, but now you want to create some data. Perhaps you’re not feeling too confident about generating or importing large data sets just yet. Or are you seeking that graph-based ice breaker to show off your new skills?

I have a treat for you, my friend. I’m going to show you how to put together a super simple yet fun way to create some data, and find out fun and interesting things about your friends and family. All you’re going to need is a blank Neo4j Sandbox, and a Google account.

Let’s get started!

Riddle Me This

We are going to be using a Google Form as our data capturing device. For those of you who have not come across Google Forms before, they’re a quick and easy way to create a questionnaire. You can easily view the results afterwards in a Google Sheet. This is a neat way to easily generate data for your graph. If you’re completely new to Google Forms, check out this guide.

Some recommendations:

  • As we’ll not be handling nulls, do ensure all question answers are required.
  • Try to limit free-entry boxes and stick to drop-down lists, like that you won’t need to worry about any post-data processing.

In this example, I’m putting together a simple form to help that ‘getting to know you’ feeling, and I’m going to ask about favorite colors and activities.

Here’s what my form looks like:

And some of those activities!

And this is what it’s going to look like when you share your form (you can either share the preview link, or hit that share button):

Ok, now, share the form to your nearest and dearest. Do make sure you don’t have any sensitive data in there (such as email addresses, phone numbers, etc.)! We will be making the data from the form available publicly so that we can load it into Neo4j, so don’t have anything in there you wouldn’t want the world to see.

If you’re doing the same questions as above, and you like more than one color and/or activity, you can fill out the form more than once.

The Results Are In!

Ok, so we now have lots of results from our friends and family, we can have a quick look at them inside Google Sheets. To do this you will need to navigate to the Responses tab, and then press the Sheets icon (both circled in red below):

Click on create new spreadsheet and you’ll have the responses in a brand new sheet.

Spin Up a Sandbox

Before we load some data, let’s get a blank Neo4j Sandbox set up.

The sandbox is a great way to get some hands on experience with Neo4j. It is a completely free, no-download version of the database.

If you’re completely brand new and want a bit more help, check out this intro session we ran a few months ago.

Once the blank sandbox has been created, hit the Open button to start up the Neo4j Browser.

Loading the Data

Now we have sandbox set up, we need to do one more change to our Google Sheet. We need to make it available to anyone with a link (viewer only is fine). Click on the Share button and make the adjustments, clicking Done when you’re finished.

Once you’ve done that, use the follow Cypher query to load up the data. You will need to replace the <link to google sheet> bit of the URL to the one of your sheet, making sure the link is appended with /export?format=csv

LOAD CSV FROM "<link to google sheet>/export?format=csv" AS row
WITH row SKIP 1 //skip the headers
MERGE (f:Friend {name:row[1]})
MERGE (c:Colour {value:row[2]})
MERGE (a:Activity {value:row[3]})
MERGE (f)-[:ENJOYS]->(a)

Your data model will look like this:

Knowing Me, Knowing You

With all that data loaded in, now it’s time to find out more about our nearest and dearest!

Here are some example queries to explore your friends data. Don’t forget to share your sandbox details so that they can join in too! You’ll need to replace friend names as appropriate!

Who likes the same color as me?

MATCH (:Friend {name:'Lju'})-[:LIKES_COLOUR]->(c)<-[:LIKES_COLOUR]-(friends)

Most popular activities:

MATCH (a:Activity)
RETURN a.value, count(a) ORDER BY count(a) DESC

Shortest path between two friends:

MATCH path= shortestPath((f1:Friend {name:'Lju'})-[*]-(f2:Friend {name:'Jane'}))

Also, don’t forget to explore your data in Neo4j Bloom, also available in the Sandbox. What exciting discoveries do you find?

If you want to ask a question and don’t know how, leave a comment on this blog post.

Neo4j Online Developer Expo and Summit is back for 2021.

Register for NODES 2021 today and enjoy the talks from experienced graph developers.

Save My Spot

Getting to Know You, Getting to Know All about You! was originally published in Neo4j Developer Blog on Medium, where people are continuing the conversation by highlighting and responding to this story.