Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Chapter 6 — Assignment Project: A Knowledge Graph for Course Advising

Open in Colab

Overview

A computer science department keeps its course catalogue and its students’ records in separate spreadsheets. Advisors spend hours answering the same questions: Which courses can this student take next? Who has already passed Machine Learning? Why would this course suit me? The department asks you to turn the spreadsheets into a knowledge graph, answer those questions with SPARQL, audit the data for errors, and propose explained course suggestions.

Data (generated in the notebook; the students are simulated):

  • CATALOGUE: 24 courses with title, department, prerequisites and topics;

  • RECORDS: 300 students and the courses they have passed.

The spreadsheets were typed by hand over many years: they contain mistakes, which Part C asks you to find.

PartTaskPoints
ABuild the knowledge graph20
BAnswer advising questions with SPARQL30
CAudit the data quality25
DExplained suggestions10
EReport for the department15

Part A — Build the Knowledge Graph (20 points)

A1 (checked). Complete build_graph(catalogue, records), returning an rdflib Graph with the namespace ex: <http://example.org/> and:

  • for each course: ex:CODE a ex:Course, rdfs:label "Title", ex:department ex:DEPT, one ex:prerequisite ex:OTHER per prerequisite, one ex:topic ex:TOPIC per topic;

  • for each student: ex:SID a ex:Student, and one ex:passed ex:CODE per course passed.

Use the title exactly as written (do not clean it yet: Part C is about finding such problems).


Part B — Advising Questions (30 points)

Write each query as a SPARQL string. The check cells compare your answers with a plain-Python computation.

B1 (checked). Every course with the number of students who passed it, most passed first (GROUP BY, COUNT, ORDER BY).

B2 (checked). For student S001: the courses they can take now, i.e. not yet passed and with every prerequisite passed. (Hint: FILTER NOT EXISTS { ?course ex:prerequisite ?p . FILTER NOT EXISTS { ex:S001 ex:passed ?p } }.)

B3 (checked). Every course that CS360 depends on, directly or indirectly (a property path).

B4. Which students have passed every course with the topic security? (Hint: a double FILTER NOT EXISTS again.)


Part C — Audit the Data Quality (25 points)

C1 (checked). A prerequisite cycle makes courses impossible to take. Complete find_cycles(prereqs) (a dict course → list of prerequisites), returning the set of courses that lie on a cycle (a course that is, directly or indirectly, its own prerequisite).

C2 (checked). Write a SPARQL query C2 listing every (student, course) pair where the student passed the course without having passed one of its prerequisites (DISTINCT).

C3. Find duplicate courses: different codes whose titles are the same after normalising (lower case, extra spaces removed). Then list the courses with no topic, and say whether that is an error under the open-world assumption.

C4. Summarise your audit in a table: each problem, how you found it, how many records it affects, and the fix you propose (which record should change, or who should be asked).

Your audit table:


Part D — Explained Suggestions (10 points)

Complete the cell below: for a student, rank the courses they can take now (B2) by how many of their passed electives share a topic with the course (ignore the common core: CS101, MA101, CS102, CS202, MA201, MA210, CS201), and print, for the top 3, an explanation path in the graph such as S001 —passed→ CS220 —topic→ data ←topic— CS320. Run it for S001 and S100.


Part E — Report for the Department (15 points)

Write 250–350 words for the head of department:

  1. What the knowledge graph contains and why it is more useful than the two spreadsheets.

  2. Three advising questions it now answers instantly (with an example answer each).

  3. The data problems your audit found, and what the department must decide or correct.

  4. How the explained suggestions could be used, and what they must not be used for.

Your report:


Grading Rubric

PartFull marks if…
A (20)the graph is built correctly (checked)
B (30)the three checked queries are correct; B4 answered
C (25)cycle detection and violations correct (checked); duplicates and missing topics found; a clear audit table with fixes
D (10)suggestions ranked as specified, each with a readable path explanation
E (15)clear for the department; accurate; problems and responsibilities stated