[Python] How to Represent and Parse Complex University Course Prerequisites Programmatically?

Discussão em 'Python' iniciado por Stack, Agosto 27, 2025.

  1. Stack

    Stack Membro Participativo

    I’m working on a project where I want to build a tool that, given a student’s completed courses, GPA, program, and year standing, outputs which courses they are eligible to take in future semesters.

    So far, I’ve:

    Scraped course information from the university website using BeautifulSoup.

    Extracted the prerequisite string for each course (everything after the word “Prerequisite”).

    Saved all the course data into a file.

    The challenge I’m facing now is how to represent and parse complex prerequisite conditions programmatically. Some examples of prerequisites include:

    "ECON 101 or 30 units"

    "Any introductory-level Computing Science course or SCI 100, and any 200-level course"

    "STAT 151 and (MATH 114 or MATH 125)"

    As you can see, prerequisites can include:

    Direct courses

    Abstract requirements like “30 units” or “200-level course”

    Logical operators (AND / OR) that can be nested

    Combination of abstract and direct requirements

    I’m considering representing each course as an object, and each prerequisite as a separate object (or tree) that can handle these logical structures.

    My questions are:

    What are some good ways to represent nested AND/OR prerequisite conditions programmatically?

    How would you approach parsing raw prerequisite strings into such a structure? Should I rely on regex/rule-based parsing, or would an LLM help here?

    Any suggestions for handling abstract requirements like “any 200-level course” or “30 units” alongside direct courses?

    I’m looking for ideas, references, or best practices from others who might have tackled similar course eligibility or dependency problems.

    Continue reading...

Compartilhe esta Página