Bläddra i källkod

选择题智能识别增加细分模式识别

dusenyao 1 månad sedan
förälder
incheckning
9eaf274383

+ 2 - 1
src/views/exercise_questions/create/components/common/IntelligentRecognition.vue

@@ -26,7 +26,8 @@ export default {
     return {
       text: '',
       placeholderList: {
-        select: '题干:xxx\r\n提示:xxx\r\n选项 1\r\n选项 2\r\n选项 3',
+        select:
+          '题干:xxx\r\n提示:xxx\r\n选项 1\r\n选项 2\r\n选项 3\r\n-------------------\r\n选项细分模板\r\n题干:xxx\r\n提示:xxx\r\n小题干:xxx\r\n  选项1\r\n  选项2\r\n小题干:xxx\r\n  选项1\r\n  选项2\r\n小题干:xxx\r\n  选项1\r\n  选项2',
         listen_select: '题干:xxx\r\n提示:xxx\r\n选项 1\r\n选项 2\r\n选项 3',
         judge: '题干:xxx\r\n提示:xxx\r\n选项 1\r\n选项 2\r\n选项 3',
         listen_judage: '题干:xxx\r\n提示:xxx\r\n选项 1\r\n选项 2\r\n选项 3',

+ 1 - 1
src/views/exercise_questions/create/components/exercises/SelectQuestion.vue

@@ -222,7 +222,7 @@ export default {
       let arr = this.recognitionCommon(text);
       let obj = analysisRecognitionSelectData(arr);
       this.data.property.is_option_subdivision = 'false';
-      this.changeOptionSubdivision('false');
+      this.changeOptionSubdivision(obj['data.property.is_option_subdivision']);
       this.recognitionCommonSetObj(obj);
       this.data.answer.answer_list = [];
     },

+ 57 - 3
src/views/exercise_questions/data/select.js

@@ -35,9 +35,63 @@ export function getSubdivisionOption(number = 2, index) {
  * @returns object
  */
 export function analysisRecognitionSelectData(arr) {
-  return {
-    'data.option_list': arr.map(getOption),
-  };
+  let data = {};
+  if (/^小题干[::]/.test(arr[0])) {
+    const outputArray = [];
+    let currentStem = null;
+    let currentOptions = [];
+
+    // 遍历输入数组
+    arr.forEach((item) => {
+      // 去除前后空格
+      const trimmedItem = item.trim();
+
+      // 检查是否为题干
+      if (trimmedItem.startsWith('小题干:')) {
+        // 如果当前题干不为空,保存之前的题干和选项
+        if (currentStem !== null) {
+          outputArray.push({
+            stem: currentStem,
+            option: currentOptions,
+          });
+        }
+        // 更新当前题干和选项
+        currentStem = trimmedItem.replace('小题干:', '');
+        currentOptions = [];
+      } else {
+        // 如果是选项,添加到当前选项数组
+        currentOptions.push(trimmedItem);
+      }
+    });
+
+    // 添加最后一组题干和选项
+    if (currentStem !== null) {
+      outputArray.push({
+        stem: currentStem,
+        option: currentOptions,
+      });
+    }
+
+    let option_list = outputArray.map(({ stem, option }, i) => {
+      return {
+        stem,
+        custom_number: (i + 1).toString(),
+        mark: getRandomNumber('', false),
+        data_list: option.map((data) => getOption(data)),
+      };
+    });
+    data = {
+      'data.property.option_number': outputArray[0].option.length,
+      'data.option_list': option_list,
+      'data.property.is_option_subdivision': 'true',
+    };
+  } else {
+    data = {
+      'data.property.is_option_subdivision': 'false',
+      'data.option_list': arr.map(getOption),
+    };
+  }
+  return data;
 }
 
 /**