1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.core.statement.naturallanguage;
17
18 import java.util.ArrayList;
19 import java.util.Arrays;
20 import java.util.List;
21
22 import org.kuali.student.core.statement.config.context.lu.MockCluInfo;
23 import org.kuali.student.core.statement.config.context.lu.MockCluSetInfo;
24 import org.kuali.student.core.statement.config.context.lu.CourseListContextImpl;
25 import org.kuali.student.core.statement.config.context.lu.GradeCheckContextImpl;
26 import org.kuali.student.core.statement.config.context.lu.CreditContextImpl;
27 import org.kuali.student.core.statement.dto.ReqComponentInfo;
28 import org.kuali.student.core.statement.dto.StatementOperatorTypeKey;
29 import org.kuali.student.core.statement.entity.ReqComponent;
30 import org.kuali.student.core.statement.entity.ReqComponentField;
31 import org.kuali.student.core.statement.entity.ReqComponentType;
32 import org.kuali.student.core.statement.entity.ReqComponentTypeNLTemplate;
33 import org.kuali.student.core.statement.entity.Statement;
34 import org.kuali.student.core.statement.entity.StatementType;
35 import org.kuali.student.core.statement.naturallanguage.ReqComponentFieldTypes;
36
37
38
39
40 public class NaturalLanguageUtil {
41
42 private final static List<MockCluInfo> cluList = new ArrayList<MockCluInfo>();
43 private final static List<MockCluSetInfo> cluSetList = new ArrayList<MockCluSetInfo>();
44
45 public static void createData() {
46 MockCluInfo clu1 = new MockCluInfo();
47 clu1.setId("CLU-NL-1");
48 clu1.setCode("MATH152");
49 clu1.setShortName("MATH 152");
50 clu1.setLongName("MATH 152 Linear Systems");
51 cluList.add(clu1);
52
53 MockCluInfo clu2 = new MockCluInfo();
54 clu2.setId("CLU-NL-2");
55 clu2.setCode("MATH221");
56 clu2.setShortName("MATH 221");
57 clu2.setLongName("MATH 221 Matrix Algebra");
58 cluList.add(clu2);
59
60 MockCluInfo clu3 = new MockCluInfo();
61 clu3.setId("CLU-NL-3");
62 clu3.setCode("MATH180");
63 clu3.setShortName("MATH 180");
64 clu3.setLongName("MATH 180 Differential Calculus with Physical Applications");
65 cluList.add(clu3);
66
67 MockCluSetInfo cluSet1 = new MockCluSetInfo();
68 cluSet1.setId("CLUSET-NL-1");
69 cluSet1.setCluIds(Arrays.asList(new String[] {clu1.getId(), clu3.getId()}));
70 cluSet1.setCluList(Arrays.asList(new MockCluInfo[] {clu1, clu3}));
71 cluSetList.add(cluSet1);
72
73 MockCluSetInfo cluSet2 = new MockCluSetInfo();
74 cluSet2.setId("CLUSET-NL-2");
75 cluSet2.setCluIds(Arrays.asList(new String[] {clu1.getId(), clu2.getId(), clu3.getId()}));
76 cluSet2.setCluList(Arrays.asList(new MockCluInfo[] {clu1, clu2, clu3}));
77 cluSetList.add(cluSet2);
78
79 MockCluSetInfo cluSet3 = new MockCluSetInfo();
80 cluSet3.setId("CLUSET-NL-3");
81 cluSet3.setCluIds(Arrays.asList(new String[] {clu1.getId(), clu2.getId()}));
82 cluSet3.setCluList(Arrays.asList(new MockCluInfo[] {clu1, clu2}));
83 cluSetList.add(cluSet3);
84 }
85
86 public static ReqComponentType createReqComponentType(String reqComponentType) {
87 ReqComponentType reqCompType = new ReqComponentType();
88 reqCompType.setId(reqComponentType);
89 return reqCompType;
90 }
91
92 public static ReqComponentType createDefaultReqComponentType(String nlUsageTypeKey, String reqComponentType) {
93 ReqComponentType reqCompType = new ReqComponentType();
94 reqCompType.setId(reqComponentType);
95
96 List<ReqComponentTypeNLTemplate> templateList = new ArrayList<ReqComponentTypeNLTemplate>();
97 ReqComponentTypeNLTemplate templateEn = new ReqComponentTypeNLTemplate();
98 templateEn.setLanguage("en");
99 templateEn.setNlUsageTypeKey(nlUsageTypeKey);
100
101 ReqComponentTypeNLTemplate templateDe = new ReqComponentTypeNLTemplate();
102 templateDe.setLanguage("de");
103 templateDe.setNlUsageTypeKey(nlUsageTypeKey);
104
105 if(reqComponentType.equals("kuali.reqComponent.type.courseList.nof")) {
106 templateEn.setTemplate("Student must have completed $expectedValue of $cluSet.getCluSetAsShortName()");
107 templateDe.setTemplate("Student muss abgeschlossen $expectedValue von $cluSet.getCluSetAsShortName()");
108 } else if(reqComponentType.equals("kuali.reqComponent.type.courseList.all")) {
109 templateEn.setTemplate("Student must have completed all of $cluSet.getCluSetAsShortName()");
110 templateDe.setTemplate("Student must have completed all of $cluSet.getCluSetAsShortName()");
111 } else if(reqComponentType.equals("kuali.reqComponent.type.courseList.none")) {
112 templateEn.setTemplate("Student must have completed none of $cluSet.getCluSetAsShortName()");
113 templateDe.setTemplate("Student must have completed none of $cluSet.getCluSetAsShortName()");
114 } else if(reqComponentType.equals("kuali.reqComponent.type.courseList.1of2")) {
115 templateEn.setTemplate("Student must have completed $cluSet.getCluAsShortName(0) or $cluSet.getCluAsShortName(1)");
116 templateDe.setTemplate("Student must have completed $cluSet.getCluAsShortName(0) or $cluSet.getCluAsShortName(1)");
117 } else if(reqComponentType.equals("kuali.reqComponent.type.grdCondCourseList")) {
118 templateEn.setTemplate("Students must take $totalCredits credits from $cluSet.getCluSetAsShortName()");
119 templateDe.setTemplate("Students must take $totalCredits credits from $cluSet.getCluSetAsShortName()");
120 } else if(reqComponentType.equals("kuali.reqComponent.type.gradecheck")) {
121 templateEn.setTemplate("Student needs a minimum GPA of $gpa");
122 templateDe.setTemplate("Student needs a minimum GPA of $gpa");
123 }
124
125 templateList.add(templateEn);
126 templateList.add(templateDe);
127 reqCompType.setNlUsageTemplates(templateList);
128
129 return reqCompType;
130 }
131
132 public static ReqComponent createReqComponent(String nlUsageTypeKey, String reqComponentType) throws Exception {
133 ReqComponent reqComponent = new ReqComponent();
134 ReqComponentType reqCompType = createDefaultReqComponentType(nlUsageTypeKey, reqComponentType);
135 reqComponent.setRequiredComponentType(reqCompType);
136 return reqComponent;
137 }
138
139 public static ReqComponent createReqComponent(String reqComponentType, List<ReqComponentField> fieldList) {
140 ReqComponentType reqCompType = createDefaultReqComponentType("KUALI.RULE", reqComponentType);
141
142 ReqComponent reqComp = new ReqComponent();
143 reqComp.setReqComponentFields(fieldList);
144 reqComp.setRequiredComponentType(reqCompType);
145
146 return reqComp;
147 }
148
149 public static List<ReqComponentField> createReqComponentFieldsForCluSet(String expectedValue, String operator, String target) {
150 List<ReqComponentField> fieldList = new ArrayList<ReqComponentField>();
151 ReqComponentField field1 = new ReqComponentField();
152 field1.setId("1");
153 field1.setType(ReqComponentFieldTypes.REQUIRED_COUNT_KEY.getType());
154 field1.setValue(expectedValue);
155 fieldList.add(field1);
156
157 ReqComponentField field2 = new ReqComponentField();
158 field2.setId("2");
159 field2.setType(ReqComponentFieldTypes.OPERATOR_KEY.getType());
160 field2.setValue(operator);
161 fieldList.add(field2);
162
163 ReqComponentField field3 = new ReqComponentField();
164 field3.setId("3");
165 field3.setType(ReqComponentFieldTypes.CLUSET_KEY.getType());
166 field3.setValue(target);
167 fieldList.add(field3);
168
169 return fieldList;
170 }
171
172 public static List<ReqComponentField> createReqComponentFieldsForClu(String expectedValue, String operator, String cluIds) {
173 List<ReqComponentField> fieldList = new ArrayList<ReqComponentField>();
174 ReqComponentField field1 = new ReqComponentField();
175 field1.setId("4");
176 field1.setType(ReqComponentFieldTypes.REQUIRED_COUNT_KEY.getType());
177 field1.setValue(expectedValue);
178 fieldList.add(field1);
179
180 ReqComponentField field2 = new ReqComponentField();
181 field2.setId("5");
182 field2.setType(ReqComponentFieldTypes.OPERATOR_KEY.getType());
183 field2.setValue(operator);
184 fieldList.add(field2);
185
186 ReqComponentField field3 = new ReqComponentField();
187 field3.setId("6");
188 field3.setType(ReqComponentFieldTypes.CLU_KEY.getType());
189 field3.setValue(cluIds);
190 fieldList.add(field3);
191
192 return fieldList;
193 }
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218 public static Statement createStatement(StatementOperatorTypeKey operator) throws Exception {
219 Statement stmt = new Statement();
220 stmt.setOperator(operator);
221 StatementType type = new StatementType();
222 type.setId("kuali.statement.type.course.academicReadiness.prereq");
223
224 stmt.setStatementType(type);
225 return stmt;
226 }
227
228 public static Statement createLuStatementInfo(String id, StatementOperatorTypeKey operator) throws Exception {
229 Statement stmt = new Statement();
230 stmt.setId(id);
231 stmt.setOperator(operator);
232
233
234
235 StatementType type = createLuStatementTypeInfo("kuali.statement.type.course.academicReadiness.prereq");
236 stmt.setStatementType(type);
237 return stmt;
238 }
239
240 public static StatementType createLuStatementTypeInfo(String id) throws Exception {
241 StatementType type = new StatementType();
242 type.setId(id);
243
244 return type;
245 }
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263 public static ContextRegistry<Context<ReqComponentInfo>> getReqComponentContextRegistry() {
264 ContextRegistry<Context<ReqComponentInfo>> contextRegistry = new ContextRegistry<Context<ReqComponentInfo>>();
265
266 createData();
267 CourseListContextImpl.setCluInfo(cluList);
268 CourseListContextImpl.setCluSetInfo(cluSetList);
269 CourseListContextImpl courseListContext = new CourseListContextImpl();
270
271 contextRegistry.add("kuali.reqComponent.type.courseList.none", courseListContext);
272 contextRegistry.add("kuali.reqComponent.type.courseList.all", courseListContext);
273 contextRegistry.add("kuali.reqComponent.type.courseList.nof", courseListContext);
274 contextRegistry.add("kuali.reqComponent.type.courseList.1of2", courseListContext);
275
276 CreditContextImpl.setCluInfo(cluList);
277 CreditContextImpl.setCluSetInfo(cluSetList);
278 CreditContextImpl gradeConditionCourseListContext = new CreditContextImpl();
279 contextRegistry.add("kuali.reqComponent.type.grdCondCourseList", gradeConditionCourseListContext);
280 contextRegistry.add("kuali.reqComponent.type.grdCondCourseList", courseListContext);
281
282 GradeCheckContextImpl.setCluInfo(cluList);
283 GradeCheckContextImpl.setCluSetInfo(cluSetList);
284 GradeCheckContextImpl gradeCheckContext = new GradeCheckContextImpl();
285 contextRegistry.add("kuali.reqComponent.type.gradecheck", gradeCheckContext);
286
287 return contextRegistry;
288 }
289 }