-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcompetency-questions.py
173 lines (162 loc) · 6.59 KB
/
competency-questions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import rdflib
import pyparsing
import re
if __name__ == '__main__':
g = rdflib.Graph() # placeholder graph
user_input = None
# What is course [COURSE NAME][COURSE NUMBER] about?
# noinspection PyTypeChecker
if re.search("^What is course.", user_input):
# noinspection PyTypeChecker
trimmed = re.sub("[.,?!]", "", user_input)
courseName = re.split(r"\s", trimmed)[3]
courseNumber = re.split(r"\s", trimmed)[4]
qres1 = g.query(f"""
SELECT ?courseDesc
WHERE{{
?x vivo:hasSubjectArea '{courseName}'
?x vivo:Catalog '{courseNumber}'
?x vivo:shortDescription ?courseDesc
}}
""")
# Which topics is [STUDENT FIRSTNAME] [STUDENT LASTNAME] competent in?
# noinspection PyTypeChecker
if re.search("^Which topics is.", user_input):
# noinspection PyTypeChecker
trimmed = re.sub("[.,?!]", "", user_input)
givenName = re.split(r"\s", trimmed)[3]
familyName = re.split(r"\s", trimmed)[4]
qres2 = g.query(f"""
SELECT ?competency
WHERE{{
?x foaf:givenName '{givenName}'
?x foaf:familyName '{familyName}'
?x docu:expertise ?y
?y vivo:contains ?competency
}}
""")
# Which courses at [UNIVERSITY] teaches [TOPIC]
# noinspection PyTypeChecker
if re.search("^Which courses at.", user_input):
# noinspection PyTypeChecker
trimmed = re.sub("[.,?!]", "", user_input)
university = re.split(r"\s", trimmed)[3]
topic = re.split(r"\s", trimmed)[len(re.split(r"\s", trimmed)) - 1]
qres3 = g.query(f"""
SELECT ?course
WHERE {{
?x rdfs:label '{university}'
?x vivo:offers ?course
?course vivo:Title '{topic}'
}}
""")
# What are all the courses for [COURSE NAME]
# noinspection PyTypeChecker
if re.search("^What are all the courses for.", user_input):
# noinspection PyTypeChecker
trimmed = re.sub("[.,?!]", "", user_input)
courseName = re.split(r"\s", trimmed)[len(re.split(r"\s", trimmed)) - 1]
qres4 = g.query(f"""
SELECT DISTINCT ?course ?courseNumber
WHERE {{
?course vivo:hasSubjectArea '{courseName}'
?course vivo:catalog ?courseNumber
}}
""")
# How many students are registered for [COURSE NAME][COURSE NUMBER]
# noinspection PyTypeChecker
if re.search("^How many students are registered for.", user_input):
# noinspection PyTypeChecker
trimmed = re.sub("[.,?!]", "", user_input)
courseName = re.split(r"\s", trimmed)[len(re.split(r"\s", trimmed)) - 2]
courseNumber = re.split(r"\s", trimmed)[len(re.split(r"\s", trimmed)) - 1]
qres5 = g.query(f"""
SELECT (COUNT(?student) as ?numberOfStudents)
WHERE {{
?student docu:HasTaken ?x
?x vivo:hasSubjectArea '{courseName}'
?x vivo:Catalog '{courseNumber}'
}}
""")
# Is [COURSE NAME][COURSE NUMBER] offered by [UNIVERSITY]
# noinspection PyTypeChecker
if re.search("^Is.*offered by.", user_input): # Need to better differentiate from Q7 below
# noinspection PyTypeChecker
trimmed = re.sub("[.,?!]", "", user_input)
university = re.split(r"\s", trimmed)[len(re.split(r"\s", trimmed)) - 1]
courseName = re.split(r"\s", trimmed)[1]
courseNumber = re.split(r"\s", trimmed)[2]
qres6 = g.query(f"""
ASK {{
?y rdfs:label '{university}'
?y vivo:offers ?x
?x vivo:hasSubjectArea '{courseName}'
?x vivo:catalog '{courseNumber}'
}}
""")
# Is [STUDENT FIRSTNAME][STUDENT LASTNAME] enrolled at [UNIVERSITY]
# noinspection PyTypeChecker
if re.search("^Is.*enrolled at.", user_input):
# noinspection PyTypeChecker
trimmed = re.sub("[.,?!]", "", user_input)
givenName = re.split(r"\s", trimmed)[1]
familyName = re.split(r"\s", trimmed)[2]
university = re.split(r"\s", trimmed)[len(re.split(r"\s", trimmed)) - 1]
qres7 = g.query(f"""
ASK {{
?x foaf:givenName '{givenName}'
?x foaf:familyName '{familyName}'
?x vivo:Student ?y
?y rdfs:label '{university}'
}}
""")
# Which universities offer [COURSE NAME][COURSE NUMBER]
# noinspection PyTypeChecker
if re.search("^Which universities offer.", user_input):
# noinspection PyTypeChecker
trimmed = re.sub("[.,?!]", "", user_input)
courseName = re.split(r"\s", trimmed)[len(re.split(r"\s", trimmed)) - 2]
courseNumber = re.split(r"\s", trimmed)[len(re.split(r"\s", trimmed)) - 1]
qres8 = g.query(f"""
SELECT ?university
WHERE{{
?university vivo:offers ?x
?x vivo:hasSubjectArea '{courseName}'
?x vivo:Catalog '{courseNumber}'
}}
""")
# What courses has [STUDENT FIRSTNAME][STUDENT LASTNAME] completed
# noinspection PyTypeChecker
if re.search("^What courses has.*completed$", user_input):
# noinspection PyTypeChecker
trimmed = re.sub("[.,?!]", "", user_input)
givenName = re.split(r"\s", trimmed)[3]
familyName = re.split(r"\s", trimmed)[4]
qres9 = g.query(f"""
SELECT DISTINCT ?course
WHERE{{
?x foaf:givenName '{givenName}'
?x foaf:familyName '{familyName}'
?x docu:HasTaken ?taken
?taken docu:grade ?grade
FILTER regex(?grade, "^") #Figure out how to REGEX to ignore anything that contains "F"
?taken docu:refersTo ?course
}}
""")
# What courses has [STUDENT FIRSTNAME][STUDENT LASTNAME] failed
# noinspection PyTypeChecker
if re.search("^What courses has.*failed$", user_input):
# noinspection PyTypeChecker
trimmed = re.sub("[.,?!]", "", user_input)
givenName = re.split(r"\s", trimmed)[3]
familyName = re.split(r"\s", trimmed)[4]
qres10 = g.query(f"""
SELECT DISTINCT ?course
WHERE{{
?x foaf:givenName '{givenName}'
?x foaf:familyName '{familyName}'
?x docu:HasTaken ?taken
?taken docu:grade 'F'
?taken docu:refersTo ?course
}}
""")