Skip to content

Instantly share code, notes, and snippets.

@luanne
Last active December 31, 2015 17:39
Show Gist options
  • Save luanne/8021580 to your computer and use it in GitHub Desktop.
Save luanne/8021580 to your computer and use it in GitHub Desktop.
Course GraphGist

Courses

A graph model for courses and their dependencies

Domain

Institutes conduct courses which are taught by instructors. A course can be taught in multiple languages and/or have subtitles in various languages. A course recommends a min and max amount of study hours per week. Subjects are taught by courses. A subject can have other subjects as prerequisites.

Goal

The model will help us answer the following questions:

  1. As a learner, what are the prerequisites for a course?

  2. As a learner, what are courses can I take to satisfy the prerequisites for another course?

  3. As a learner, based on the subjects I know, what courses am I eligible for?

Model

coursemodel

Entities

Language with attribute name Subject with attribute subject Course with attributes title, minHoursPerWeek, maxHoursPerWeek, category Institute with attribute name Instructor with attribute name

Each entity will be labeled according to its type. In addition, the category on a course is modeled as a label.

Relationships

A subject has other subjects as prerequisites. A subject has courses that teach the subject. An institute conducts a course. A instructor teaches a course. A course is taught in one or more languages. A course is subtitled in one or more languages.

Setup

CREATE (english:Language { name: "English" })
CREATE (portuguese:Language { name: "Portuguese" })
CREATE (german:Language { name: "German" })


//Create subject areas
CREATE (astronomySub:Subject {subject: "Astronomy"})

CREATE (cosmologySub:Subject {subject: "Cosmology"})

CREATE (algebraSub:Subject {subject: "Algebra"})

CREATE (probabilitySub:Subject {subject: "Probability"})

CREATE (physicsSub:Subject {subject: "Physics"})

CREATE (calculusSub:Subject {subject: "Calculus"})

CREATE (compSciSub:Subject {subject: "Computer Science"})

CREATE (algosSub:Subject {subject: "Algorithms"})

CREATE (trigSub:Subject {subject: "Trigonometry"})

CREATE (energymomentumSub:Subject {subject: "Energy and Momentum"})

CREATE (networksSub:Subject {subject: "Computer Networks"})

CREATE (gametheorySub:Subject { subject: "Game Theory"})

CREATE (nlpSub:Subject { subject: "Natural Language Processing"})

CREATE (basicCalculusSub:Subject { subject: "Basic Calculus"})


//Create prerequisites

CREATE (astronomySub)-[:REQUIRES]->(algebraSub)
CREATE (astronomySub)-[:REQUIRES]->(physicsSub)
CREATE (networksSub)-[:REQUIRES]->(probabilitySub)
CREATE (networksSub)-[:REQUIRES]->(compSciSub)
CREATE (gametheorySub)-[:REQUIRES]->(compSciSub)
CREATE (gametheorySub)-[:REQUIRES]->(calculusSub)
CREATE (nlpSub)-[:REQUIRES]->(probabilitySub)
CREATE (nlpSub)-[:REQUIRES]->(algosSub)
CREATE (nlpSub)-[:REQUIRES]->(calculusSub)
CREATE (basicCalculusSub)-[:REQUIRES]->(algebraSub)
CREATE (basicCalculusSub)-[:REQUIRES]->(trigSub)
CREATE (calculusSub)-[:REQUIRES]->(basicCalculusSub)
CREATE (probabilitySub)-[:REQUIRES]->(physicsSub)
CREATE (cosmologySub)-[:REQUIRES]->(astronomySub)
CREATE (cosmologySub)-[:REQUIRES]->(physicsSub)
CREATE (physicsSub)-[:REQUIRES]->(algebraSub)
CREATE (physicsSub)-[:REQUIRES]->(trigSub)

// Create courses
CREATE (astronomy:Course:Physics {
       		title: "Beginning Astronomy",
       		minHoursPerWeek: 4,
       		maxHoursPerWeek: 12})

CREATE (computerNetworks:Course:ComputerScience:Engineering {
		title: "Computer Networks",
       		minHoursPerWeek: 6,
       		maxHoursPerWeek: 10})

CREATE (gameTheory:Course:ComputerScience:Economics:AI {
		title: "Advanced Game Theory",
       		minHoursPerWeek: 8,
       		maxHoursPerWeek: 14})

CREATE (algorithms:Course:ComputerScience {
		title: "Introductory Algorithms",
       		minHoursPerWeek: 5,
       		maxHoursPerWeek: 10})

CREATE (nlp:Course:ComputerScience:AI {
		title: "Natural Language Processing",
       		minHoursPerWeek: 10,
       		maxHoursPerWeek: 14})

CREATE (algebratrig:Course:Mathematics {
		title: "Algebra & Trignometry",
       		minHoursPerWeek: 8,
       		maxHoursPerWeek: 10})

CREATE (basicCalculus:Course:Mathematics {
		title: "Basic Calculus",
       		minHoursPerWeek: 8,
       		maxHoursPerWeek: 10})

CREATE (calculus:Course:Mathematics {
		title:  "Calculus",
       		minHoursPerWeek: 12,
       		maxHoursPerWeek: 16})

CREATE (probability:Course:Mathematics {
		title:  "Introductory Probability",
       		minHoursPerWeek: 8,
       		maxHoursPerWeek: 12})

CREATE (cosmology:Course:Physics {
		title:  "Cosmology",
       		minHoursPerWeek: 5,
       		maxHoursPerWeek: 8})

CREATE (physics:Course:Physics {
		title:  "Introduction to Physics",
       		minHoursPerWeek: 12,
       		maxHoursPerWeek: 16})

CREATE (cs:Course:ComputerScience {
		title:  "CS 101",
       		minHoursPerWeek: 14,
       		maxHoursPerWeek: 18})

// Create Institutes
CREATE (uni1:Institute {name: "University of A"})

CREATE (uni2:Institute {name: "University of B"})

CREATE (uni3:Institute {name: "University of C"})

// Create Instructors
CREATE (ins1:Instructor {name: "Hilda Matthews"})
CREATE (ins2:Instructor {name: "Donald Norton"})
CREATE (ins3:Instructor {name: "Jake Harvey"})
CREATE (ins4:Instructor {name: "Judy Torres "})
CREATE (ins5:Instructor {name: "Gary Elliott"})
CREATE (ins6:Instructor {name: "Velma Davidson"})
CREATE (ins7:Instructor {name: "Jasmine White"})
CREATE (ins8:Instructor {name: "Laurie Saunders"})
CREATE (ins9:Instructor {name: "Al Richards"})
CREATE (ins10:Instructor {name: "Erika Cobb"})

// university and instructor relations to courses
CREATE (uni1)-[:CONDUCTS]->(astronomy),
       (ins1)-[:TEACHES]->(astronomy),
	   (astronomy)-[:TAUGHT_IN]->(english),
	   (astronomy)-[:SUBTITLED_IN]->(english),
	   (astronomy)-[:SUBTITLED_IN]->(german),
	   (astronomy)<-[:HAS_COURSE]-(astronomySub)


CREATE (uni1)-[:CONDUCTS]->(cosmology),
       (ins2)-[:TEACHES]->(cosmology),
	   (cosmology)-[:TAUGHT_IN]->(german),
	   (cosmology)-[:TAUGHT_IN]->(german),
	   (cosmology)-[:SUBTITLED_IN]->(english),
	   (cosmology)-[:SUBTITLED_IN]->(german),
	   (cosmology)<-[:HAS_COURSE]-(cosmologySub)

CREATE (uni2)-[:CONDUCTS]->(physics),
       (ins3)-[:TEACHES]->(physics),
	   (physics)-[:TAUGHT_IN]->(english),
	   (physics)-[:SUBTITLED_IN]->(english),
	   (physics)<-[:HAS_COURSE]-(physicsSub)

CREATE (uni2)-[:CONDUCTS]->(computerNetworks),
       (ins4)-[:TEACHES]->(computerNetworks),
	   (computerNetworks)-[:TAUGHT_IN]->(portuguese),
	   (computerNetworks)-[:SUBTITLED_IN]->(english),
	   (computerNetworks)<-[:HAS_COURSE]-(networksSub)

CREATE (uni3)-[:CONDUCTS]->(gameTheory),
       (ins5)-[:TEACHES]->(gameTheory),
	   (gameTheory)-[:TAUGHT_IN]->(english),
	   (gameTheory)-[:SUBTITLED_IN]->(english),
	   (gameTheory)-[:SUBTITLED_IN]->(portuguese),
	   (gameTheory)<-[:HAS_COURSE]-(gametheorySub)

CREATE (uni1)-[:CONDUCTS]->(nlp),
       (ins6)-[:TEACHES]->(nlp),
		(nlp)-[:TAUGHT_IN]->(english),
	   (nlp)-[:SUBTITLED_IN]->(english),
	   (nlp)<-[:HAS_COURSE]-(nlpSub)

CREATE (uni2)-[:CONDUCTS]->(algebratrig),
       (ins7)-[:TEACHES]->(algebratrig),
	    (algebratrig)-[:TAUGHT_IN]->(english),
	   (algebratrig)-[:SUBTITLED_IN]->(english),
	   (algebratrig)<-[:HAS_COURSE]-(algebraSub),
	   (algebratrig)<-[:HAS_COURSE]-(trigSub)


CREATE (uni2)-[:CONDUCTS]->(basicCalculus),
       (ins8)-[:TEACHES]->(basicCalculus),
	   (basicCalculus)-[:TAUGHT_IN]->(english),
	   (basicCalculus)-[:SUBTITLED_IN]->(english),
	      (basicCalculus)<-[:HAS_COURSE]-(basicCalculusSub)

CREATE (uni3)-[:CONDUCTS]->(probability),
       (ins9)-[:TEACHES]->(probability),
	   (probability)-[:TAUGHT_IN]->(english),
	   (probability)-[:SUBTITLED_IN]->(english),
	    (probability)<-[:HAS_COURSE]-(probabilitySub)

CREATE (uni3)-[:CONDUCTS]->(algorithms),
       (ins10)-[:TEACHES]->(algorithms),
	    (algorithms)-[:TAUGHT_IN]->(english),
	   (algorithms)-[:SUBTITLED_IN]->(english),
	   (algorithms)<-[:HAS_COURSE]-(algosSub)


CREATE (uni2)-[:CONDUCTS]->(calculus),
       (ins8)-[:TEACHES]->(calculus),
	    (calculus)-[:TAUGHT_IN]->(english),
	   (calculus)-[:SUBTITLED_IN]->(english),
	   (calculus)<-[:HAS_COURSE]-(calculusSub)

CREATE (uni2)-[:CONDUCTS]->(cs),
       (ins4)-[:TEACHES]->(cs),
	   (cs)-[:TAUGHT_IN]->(english),
	   (cs)-[:SUBTITLED_IN]->(english),
	   (cs)<-[:HAS_COURSE]-(compSciSub)

The graph

match n return n

Queries:

I want to take the Advanced Game Theory course. What are the prerequisites?

MATCH (c:Course {title: "Advanced Game Theory"})<-[:HAS_COURSE]-(subject)-[:REQUIRES]->(prereq)
RETURN prereq.subject as prerequisiteName

What courses can I take to satisfy the prerequisites for Advanced Game Theory

MATCH (c:Course {title: "Advanced Game Theory"})<-[:HAS_COURSE]-(subject)-[:REQUIRES]->(prereq)-[:HAS_COURSE]->(anotherCourse:Course)<-[:CONDUCTS]-(institute)
RETURN distinct anotherCourse.title as course, institute.name as institute

What Computer Science courses are either taught or have subtitles in Portuguese?

MATCH (portuguese:Language { name: "Portuguese"})<-[:TAUGHT_IN|SUBTITLED_IN]-(c:ComputerScience)
RETURN distinct c.title as course

I know only Computer Science and Calculus. What courses can I take knowing only these two?

MATCH (sub:Subject)<-[:REQUIRES]-(otherSubject:Subject)
WHERE sub.subject IN ["Computer Science","Calculus"]
WITH distinct otherSubject as otherSubject
MATCH (otherSubject)-[:REQUIRES]->(prereq)
WITH collect(prereq.subject) as otherPrereqs, otherSubject
WHERE ALL(pr in otherPrereqs where pr in ["Computer Science","Calculus"])
MATCH (otherSubject)-[:HAS_COURSE]->(course:Course)
RETURN course.title as courseTitle

I know only Computer Science and Calculus. What courses can I take and how many new subjects do I need to learn to take them?

MATCH (sub:Subject)<-[:REQUIRES]-(otherSubject:Subject)
WHERE sub.subject IN ["Computer Science","Calculus"]
WITH distinct otherSubject as otherSubject
MATCH (otherSubject)-[:REQUIRES]->(prereq)
WITH collect(prereq.subject) as otherPrereqs, otherSubject
WITH filter(x in otherPrereqs WHERE not(x in ["Computer Science","Calculus"])) as missingKnowledge,otherSubject
MATCH (otherSubject)-[:HAS_COURSE]->(course:Course)
RETURN course.title,missingKnowledge

I am taking the Introduction to Probability course. What other Mathematics course can I take along with it that requires not more than 24 hours per week of my time totally?

MATCH (probabilityCourse:Course {title: "Introductory Probability"}),(otherCourse:Course:Mathematics)
WHERE otherCourse<>probabilityCourse AND (probabilityCourse.maxHoursPerWeek + otherCourse.maxHoursPerWeek)<=24
RETURN otherCourse.title as course, (probabilityCourse.maxHoursPerWeek + otherCourse.maxHoursPerWeek) as totalTimeRequired
ORDER BY totalTimeRequired

The top three subjects you should have paid more attention to in college, but never did :-(

MATCH (s:Subject)-[:REQUIRES]->(prereq)
RETURN prereq.subject as subject,count(prereq) as countPrereq
ORDER BY countPrereq DESC LIMIT 3

Created by Luanne Misquitta:

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