|
@@ -50,42 +50,42 @@ public class WordService {
|
|
|
topicTypes = Arrays.asList(topicType);
|
|
|
}
|
|
|
|
|
|
- public Question parseQuestion(Question question, byte[] data) {
|
|
|
- XWPFDocument document = WordUtil.open(data);
|
|
|
- Map<String, List<XWPFParagraph>> group = initMap(document.getParagraphs());
|
|
|
- List<XWPFPictureData> pictures = document.getAllPictures();
|
|
|
- pictures.forEach(d -> {
|
|
|
- logger.debug("check sum " + d.getChecksum());
|
|
|
- logger.debug("file name " + d.getFileName());
|
|
|
- });
|
|
|
- parseQuestion(question, group);
|
|
|
- WordUtil.close(document);
|
|
|
- return question;
|
|
|
- }
|
|
|
-
|
|
|
- public Question parseQuestion(Question q, List<XWPFParagraph> ps, Map<String, String> topic, PaperTemplate template, List<String> abilities) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public Question parseQuestion(Question q, List<XWPFParagraph> ps, Map<String, String> topic, PaperTemplate template, Boolean useAbility) {
|
|
|
logger.info("parsing question,pid={},section={},number={}", q.getPid(), q.getSection(), q.getNumber());
|
|
|
Map<String, List<XWPFParagraph>> group = initGroup(ps, topic, template);
|
|
|
|
|
|
parseQuestion(q, group.get(topic.get(Constants.TOPIC_QUESTION)), template.getOptionPattern(), template.getPicturePattern());
|
|
|
parseAnswer(q, group.get(topic.get(Constants.TOPIC_ANSWER)));
|
|
|
parseTag(q, group.get(topic.get(Constants.TOPIC_TAG)));
|
|
|
- parseAbility(q, group.get(topic.get(Constants.TOPIC_ABILITY)), abilities);
|
|
|
+ parseAbility(q, group.get(topic.get(Constants.TOPIC_ABILITY)), useAbility);
|
|
|
logger.info("parse question finish,pid={},section={},number={}", q.getPid(), q.getSection(), q.getNumber());
|
|
|
return q;
|
|
|
}
|
|
|
|
|
|
- private void parseQuestion(Question q, Map<String, List<XWPFParagraph>> group) {
|
|
|
- logger.info("parsing question,pid={},section={},number={}", q.getPid(), q.getSection(), q.getNumber());
|
|
|
- String[] a = {"A1", "A2", "A3", "A4", "A5"};
|
|
|
- parseQuestion(q, group.get(Constants.TOPIC_QUESTION), "^[A-Z]\\.(.*)", "^#(Small|Middle|Large)#");
|
|
|
- parseAnswer(q, group.get(Constants.TOPIC_ANSWER));
|
|
|
- parseTag(q, group.get(Constants.TOPIC_TAG));
|
|
|
- parseAbility(q, group.get(Constants.TOPIC_ABILITY), Arrays.asList(a));
|
|
|
- parseCollect(q, group.get(Constants.TOPIC_EVALUATE_CORRECT));
|
|
|
- parseWrong(q, group.get(Constants.TOPIC_EVALUATE_WRONG));
|
|
|
- logger.info("parse question finish,pid={},section={},number={}", q.getPid(), q.getSection(), q.getNumber());
|
|
|
- }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
private void parseQuestion(Question question, List<XWPFParagraph> ps, String optionPattern, String picturePattern) {
|
|
|
List<QuestionOption> options = new ArrayList<>();
|
|
@@ -100,7 +100,7 @@ public class WordService {
|
|
|
if (text.matches(optionPattern)) {
|
|
|
|
|
|
QuestionOption option = initOption(i++, text);
|
|
|
- String optionNoContent = String.format("parseQuestion,题号为%s的题目选项 %s 未检测到内容,题目内容为“%s”,请检查", question.getNumber(), text, content);
|
|
|
+ String optionNoContent = String.format("parseQuestion,题号为%s的题目选项 %s 未检测到内容,题目内容为“%s”,请检查选项结构", question.getNumber(), text, content);
|
|
|
Assert.hasText(option.getContent(), optionNoContent);
|
|
|
options.add(option);
|
|
|
} else {
|
|
@@ -109,7 +109,7 @@ public class WordService {
|
|
|
}
|
|
|
String noContent = String.format("parseQuestion,题号为 %s 的题目未检测到题干,题目内容为 “%s” ,请检查", question.getNumber(), content);
|
|
|
String noOptions = String.format("parseQuestion,题号为 %s 的题目未检测到选项,题目内容为 “%s” ,请检查", question.getNumber(), content);
|
|
|
- String lostOptions = String.format("parseQuestion,题号为 %s 的题目检测到选项数量为 %s ,题目内容为 “%s” ,请检查", question.getNumber(), options.size(), content);
|
|
|
+ String lostOptions = String.format("parseQuestion,题号为 %s 的题目检测到选项数量为 %s ,题目内容为 “%s” ,请检查选项换行情况", question.getNumber(), options.size(), content);
|
|
|
Assert.hasText(content.toString(), noContent);
|
|
|
Assert.notEmpty(options, noOptions);
|
|
|
|
|
@@ -143,7 +143,7 @@ public class WordService {
|
|
|
ps.stream().filter(p -> StringUtils.isNotBlank(p.getText())).forEach(p -> question.setTag(p.getText()));
|
|
|
}
|
|
|
|
|
|
- private void parseAbility(Question question, List<XWPFParagraph> ps, List<String> abilities) {
|
|
|
+ private void parseAbility(Question question, List<XWPFParagraph> ps, Boolean useAbility) {
|
|
|
List<AbilityScore> list = new ArrayList<>();
|
|
|
Map<String, Double> json = new HashMap<>();
|
|
|
|
|
@@ -175,7 +175,9 @@ public class WordService {
|
|
|
|
|
|
|
|
|
}
|
|
|
- question.setJsonScore(ObjectUtil.object2Json(json));
|
|
|
+ if (useAbility != null && useAbility) {
|
|
|
+ question.setJsonScore(ObjectUtil.object2Json(json));
|
|
|
+ }
|
|
|
question.setScores(list);
|
|
|
|
|
|
}
|