Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarneeDear/cfce07f2bf482d74510ba630999ea878 to your computer and use it in GitHub Desktop.
Save MarneeDear/cfce07f2bf482d74510ba630999ea878 to your computer and use it in GitHub Desktop.

Data Science Meetup: The Github Graph

Introduction

Let’s graph Github. We will graph the relationships between organizations and their members, between users and their locations, between users and the projects they have starred, and between organizations and their projects. We can use this data to find out interesting things like, where do users cluster, what starred projects do they have in common, or what memberships do they have in common.

Table 1. Table Github Relationships
This To That

USER

STARRED

PROJECT

USER

BELONGS_TO

ORGANIZATION

USER

LOCATED_IN

LOCATION

ORGANIZATION

MAINTAINS

PROJECT

NLtKdfV

Setup Organization and Members

CREATE
  (o:ORGANIZATION {Login: 'demoorg', Id: 10001, Name: 'Demo Organization', Location: 'Tucson' }),
  (m1:USER {Id:20001, Login:'userlogin1', Name:'User 1' }),
  (m2:USER {Id:20002, Login:'userlogin2', Name:'User 2' }),
  (l:LOCATION {Name: 'Tucson'}),
  (p1:PROJECT {Id: 30001, Login:'projectlogin1', Name: 'Project 1' }),
  (p2:PROJECT {Id: 30002, Login:'projectlogin2', Name:'Project 2' }),
  (m1)-[:MEMBER_OF]->(o),
  (m2)-[:MEMBER_OF]->(o),
  (m1)-[:LOCATED_IN]->(l),
  (m2)-[:LOCATED_IN]->(l),
  (m1)-[:STARRED]->(p1),
  (m2)-[:STARRED]->(p2),
  (o)-[:MAINTAINS]->(p1),
  (o)-[:MAINTAINS]->(p2)

Who are the members of my organization?

Let’s find all the members in an organization as an example of a simple MATCH statement.

MATCH (u)-[r:MEMBER_OF]->(o:ORGANIZATION {Login:'demoorg'})
RETURN o, r, u
8dSkzbp

Are there other members in my location?

We can use a query like this to find others in your organization who might be near you. And then you get together for a nice coffee and a chat.

MATCH p=(o)<-[:MEMBER_OF]-(u:USER)-[:LOCATED_IN]->(l:LOCATION {Name: 'Tucson'})
RETURN p LIMIT 25
9lg4H18

Which projects have been starred and by whom?

MATCH path=(u:USER)-[r:STARRED]->(p:PROJECT)<-[:MAINTAINS]-(o:ORGANIZATION {Login: 'demoorg'})
RETURN path LIMIT 25
hYVowb1

Conclusions

Neo4j is easy to get started with. It makes graph analsysis simpler and more powerful at the same time.

Resources

Download Neo4j here

Use arrows to whiteboard your graphs and write queries to create the model

Use Neo4j online with GrapheneDB:


Created by Marnee Dearman - Twitter | Blog

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment