Implemented gen_main

parent 4f67f475
......@@ -4,6 +4,7 @@ main_writer.py and req_writer.py.
"""
import re
import csv
def get_courses():
with open('course.lp', 'r') as fil:
......@@ -16,5 +17,50 @@ def get_required_courses(degree, major, year):
req_courses = re.findall('[a-z]+[0-9][0-9V][0-9]{2}', contents)
return req_courses
def parse_transcript(transcript):
if type(transcript) is str:
transcript = trascript.splitlines()
csvr = list(csv.reader(transcript))
student = csvr[0][0]
(degree, major, year, spec) = csvr[1]
courses = csvr[2] # list of courses student has taken
return (student, degree, major, year, spec, courses)
def gen_main(student, degree, major, year, spec, courses):
pass
student_fact = "student({0},{0}).".format(student)
if spec != 'none':
spec_string = '_specialization({0},{1}).\n'.format(student,spec)
else:
spec_string = str()
taken_list = '_taken({},['.format(student) # the _taken(<student>,[c1,c2...cn]). atom
has_taken = str() # series of _hasTaken/2 atoms
try:
req = get_required_courses(degree, major, year)
except IOError:
print('requirements file not found', file=sys.stderr)
for course in courses:
# include only those courses that could possibly
# counted as electives i.e. those that are not required.
# in the 'taken list'
if not '_req(%s,required).' % course in req:
taken_list += course + ','
has_taken += '_hasTaken({0},{1}).\n'.format(student, course)
# strip trailing comma
taken_list = taken_list[:-1]
taken_list += ']).\n'
postamble = "#include 'counting.lp'.\n"\
"#include '{0}/{1}/{2}/{1}{2}rules.lp'.\n\n"\
'?- _main({3}).\n'.format(degree, major, year, student)
mainlp = '\n'.join([student_fact,spec_string,has_taken,taken_list,postamble])
return mainlp
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment