Skip to content

Instantly share code, notes, and snippets.

@imranansari
Forked from dgkris/C Graph
Created June 23, 2014 08:01
Show Gist options
  • Select an option

  • Save imranansari/8bca940b77c2243f81c9 to your computer and use it in GitHub Desktop.

Select an option

Save imranansari/8bca940b77c2243f81c9 to your computer and use it in GitHub Desktop.
= C Graph
:neo4j-version: 2.0.0-RC1
'''
//setup
//hide
== Initial Data Setup
//person1 WORKED_AT company1
//person1 WORKED_AT company2
//person2 WORKED_AT company2
//person1 ATTENDED school1
//person2 ATTENDED school2
//school1 ATTENDED_BY person1 for MBA from May 2006 to May 2010
//school2 ATTENDED_BY person2 for MS from May 2004 to May 2008
//person1 INTERESTED_IN interest1
//person1 INTERESTED_IN interest2
//person2 INTERESTED_IN interest3
//person2 INTERESTED_IN interest4
//person2 INTERESTED_IN interest5
//person3 IS_FRIEND_OF person1
//person3 IS_FRIEND_OF person2
//company1 IS_INTO_TECHNOLOGY technology1
//company2 IS_INTO_TECHNOLOGY technology2
//technology1 IS_ADOPTED_BY company1 as evident from "Crittericism is now into Embedded Systems "
//technology2 IS_ADOPTED_BY company2 as evident from "Apple have released the latest libraries in Network Programming"
//company1 BELONGS_TO_CATEGORY category1
//company2 BELONGS_TO_CATEGORY category2
//company1 IS_INTO_INDUSTRY is industry1
//company2 IS_INTO_INDUSTRY is industry2
//company1 EMPLOYED person1 as SSE from from June 2010 to May 2012
//company2 EMPLOYED person1 as LE from June 2012 to now
//company2 EMPLOYED person2 as LE from April 2008 to August 2010
//company2 EMPLOYED person2 as Architect from September 2010 to now
//company1 LOCATED_AT location1
//company1 LOCATED_AT location2
//company2 LOCATED_AT location3
//location1 HAS_COMPANY company1 located at {lat:'20.31',lon:'22.34'},
//location2 HAS_COMPANY company1 located at {lat:'23.21',lon:'22.94'},
//location3 HAS_COMPANY company2 located at {lat:'20.34',lon:'22.14'},
//person1 MENTIONED_IN news1
//person2 MENTIONED_IN news2
//person1 MENTIONED_IN news3
[source,cypher]
----
CREATE (person1:Person { name:'Jin Daikoku', aliasName:'Jin' }),
(person2:Person { name:'Alex Bower', aliasName:'Alex' }),
(person3:Person { name:'John Doe', aliasName:'John' }),
(company1:Company { name:'Crittercism', website:'', overview:'' }),
(company2:Company { name:'Apple', website:'', overview:'' }),
(school1:School { name:'College of Wooster' }),
(school2:School { name:'University of Arizona' }),
(interest1:Interest { name:'Social Media' }),
(interest2:Interest { name:'Politics' }),
(interest3:Interest { name:'Technology' }),
(interest4:Interest { name:'Health' }),
(interest5:Interest { name:'Sports' }),
(technology1:Technology { name:'Embedded Systems' }),
(technology2:Technology { name:'Network Programming' }),
(industry1:Industry{ name:'Software Services' }),
(industry2:Industry { name:'Product Development' }),
(category1:Category{ name:'Software' }),
(category2:Category { name:'Biomedical' }),
(location1:Location{ city:'Fairfax',state:'VA',zipcode:'22033',lat:'20.31',lon:'22.34' }),
(location2:Location{ city:'Arlington',state:'VA',zipcode:'22032',lat:'23.21',lon:'22.94' }),
(location3:Location{ city:'McLean',state:'VA',zipcode:'22031',lat:'20.34',lon:'22.14' }),
(person1)-[:WORKED_AT]->(company1),
(person1)-[:WORKED_AT]->(company2),
(person2)-[:WORKED_AT]->(company2),
(person1)-[:ATTENDED]->(school1),
(person2)-[:ATTENDED]->(school2),
(school1)-[:ATTENDED_BY{from:'May 2006', to:'May 2010', course:'MBA'}]->(person1),
(school2)-[:ATTENDED_BY{from:'May 2004', to:'May 2008', course:'MS'}]->(person2),
(person1)-[:INTERESTED_IN]->(interest1),
(person1)-[:INTERESTED_IN]->(interest2),
(person2)-[:INTERESTED_IN]->(interest3),
(person2)-[:INTERESTED_IN]->(interest4),
(person2)-[:INTERESTED_IN]->(interest5),
(person3)-[:INTERESTED_IN]->(interest5),
(person3)-[:INTERESTED_IN]->(interest1),
(person3)-[:FRIEND_OF{medium:'Twitter'}]->(person1),
(person3)-[:FRIEND_OF{medium:'Facebook'}]->(person2),
(company1)-[:INTO_TECHNOLOGY]->(technology1),
(company2)-[:INTO_TECHNOLOGY]->(technology2),
(technology1)-[:IS_ADOPTED_BY{evidence:'Crittericism is now into Embedded Systems'}]->(company1),
(technology2)-[:IS_ADOPTED_BY{evidence:'Apple have released the latest libraries in Network Programming'}]->(company2),
(company1)-[:BELONGS_TO_CATEGORY]->(category1),
(company2)-[:BELONGS_TO_CATEGORY]->(category2),
(category1)-[:CATEGORY_MEMBER{evidence:'Crittericism is into Sofrware development'}]->(company1),
(category2)-[:CATEGORY_MEMBER{evidence:'Apple has recently entered Biomedical domain'}]->(company2),
(company1)-[:LOCATED_AT]->(location1),
(company1)-[:LOCATED_AT]->(location2),
(company2)-[:LOCATED_AT]->(location3),
(location1)-[:HAS_COMPANY{lat:'20.31',lon:'22.34'}]->(company1),
(location2)-[:HAS_COMPANY{lat:'23.21',lon:'22.94'}]->(company1),
(location3)-[:HAS_COMPANY{lat:'20.34',lon:'22.14'}]->(company2),
(company1)-[:IS_INTO_INDUSTRY]->(industry1),
(company2)-[:IS_INTO_INDUSTRY]->(industry2),
(industry1)-[:INDUSTRY_MEMBER{evidence:'Crittericism is into Sofrware Services'}]->(company1),
(industry2)-[:INDUSTRY_MEMBER{evidence:'Apple is one of the best Product Development companies in the world'}]->(company2);
----
//graph
'''
== Queries
=== Find me all Persons who attended a given school
[source, cypher]
----
MATCH (person:Person)-[attended:ATTENDED]-(school:School { name:"University of Arizona" })
RETURN person;
----
//table
'''
=== Find me all Persons who worked at a given company
[source, cypher]
----
MATCH (person:Person)-[worked_at:WORKED_AT]-(company:Company { name:"Crittercism" })
RETURN person;
----
//table
'''
=== Find me all Persons who have a given interest
[source, cypher]
----
MATCH (person:Person)-[interested_in:INTERESTED_IN]-(Interest { name:'Social Media' })
RETURN person;
----
//table
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment