Prechádzať zdrojové kódy

课文生词匹配拆分的分词

natasha 1 týždeň pred
rodič
commit
a5e40d118e

+ 1 - 1
src/views/book/courseware/preview/components/article/PhraseModelChs.vue

@@ -2237,7 +2237,7 @@ export default {
             words = wItem.chs;
             endIndex = startIndex + 1;
           }
-        } else if (item[0] === wItem.chs && sentence.indexOf(item) > -1) {
+        } else if (item.substring(0, wItem.chs.length) === wItem.chs && sentence.indexOf(item) > -1) {
           let index = null;
           let chsStr = '';
           for (let i = startIndex; i < sItem.length + 1; i++) {

+ 66 - 0
src/views/book/courseware/preview/components/article/Practicechs.vue

@@ -1089,6 +1089,8 @@ export default {
       mathNum: Math.random().toString(36).substr(2),
       ed: undefined,
       refresh: true,
+      highWords: null,
+      newWordList: [],
       multilingualTextList: {},
     };
   },
@@ -1262,6 +1264,7 @@ export default {
       let wordTimeList = curQue.wordTime;
       let dhaspinyin = false; // 每段是否有拼音
       let dhaspinyinArr = [];
+      this.handleNewword();
       curQue.detail.forEach((dItem, dIndex) => {
         dhaspinyin = false;
         dItem.wordsList.forEach((sItem, sIndex) => {
@@ -1271,7 +1274,21 @@ export default {
             let startIndex = wIndex === 0 ? 0 : sentArr[wIndex - 1].startIndex + sentArr[wIndex - 1].chs.length;
             let endIndex = wIndex === 0 ? wItem.chs.length : sentArr[wIndex - 1].endIndex + wItem.chs.length;
             // this.judgePad(sItem, wItem, wIndex);
+            let sentence = dItem.sentences[sIndex];
             this.mergeWordSymbol(wItem);
+            let words = '';
+            if (this.newWordList.length > 0) {
+              if (!this.highWords) {
+                this.findLightWord(wItem, wIndex, sentence, sItem);
+                words = this.highWords ? this.highWords.words : '';
+              } else if (wIndex > this.highWords.endIndex - 1) {
+                this.highWords = null;
+                this.findLightWord(wItem, wIndex, sentence, sItem);
+                words = this.highWords ? this.highWords.words : '';
+              } else {
+                words = this.highWords ? this.highWords.words : '';
+              }
+            }
             let obj = {
               paraIndex: dIndex, // 段落索引
               sentIndex: sIndex, // 在段落中句子索引
@@ -1289,6 +1306,7 @@ export default {
               startIndex,
               endIndex,
               leg: wItem.chs.length,
+              words,
               timeList: [],
               config: {
                 fontFamily: wItem.fontFamily,
@@ -1352,6 +1370,54 @@ export default {
         wItem.isShow = true;
       }
     },
+    findLightWord(wItem, startIndex, sentence, sItem) {
+      let endIndex = 0;
+      let words = '';
+      this.newWordList.forEach((item) => {
+        if (item.length === 1) {
+          if (item === wItem.chs && !wItem.banLight) {
+            words = wItem.chs;
+            endIndex = startIndex + 1;
+          }
+        } else if (item.substring(0, wItem.chs.length) === wItem.chs && sentence.indexOf(item) > -1) {
+          let index = null;
+          let chsStr = '';
+          for (let i = startIndex; i < sItem.length + 1; i++) {
+            index = i;
+            if (chsStr.length === item.length) {
+              break;
+            } else {
+              chsStr += sItem[i] ? sItem[i].chs : '';
+            }
+          }
+          if (chsStr === item && !wItem.banLight) {
+            words = item;
+            endIndex = index;
+          }
+        } else if (wItem.new_word && wItem.new_word === item && !wItem.banLight) {
+          words = item;
+          endIndex = startIndex + 1;
+        }
+      });
+      if (words) {
+        this.highWords = { words, endIndex };
+      } else {
+        this.highWords = null;
+      }
+    },
+    handleNewword() {
+      let NewWordList = [];
+      this.NNPENewWordList.forEach((wItem) => {
+        // item.forEach((wItem) => {
+        if (wItem.new_word) {
+          NewWordList.push(wItem.new_word);
+        } else if (wItem.detail && wItem.detail.sentence) {
+          NewWordList.push(wItem.detail.sentence);
+        }
+        // });
+      });
+      this.newWordList = JSON.parse(JSON.stringify(NewWordList));
+    },
 
     // 判断是否有padding
     judgePad(sItem, wItem, curIndex) {

+ 1 - 1
src/views/book/courseware/preview/components/article/Voicefullscreen.vue

@@ -1604,7 +1604,7 @@ export default {
             }
           });
         }
-      } else if (this.newWordList.indexOf(item.chs) > -1) {
+      } else if (this.newWordList.indexOf(item.chs) > -1 || this.newWordList.indexOf(item.words) > -1) {
         if (this.oldHz !== item.chs) {
           this.isShow = false;
 

+ 1 - 1
src/views/book/courseware/preview/components/dialogue_article/PhraseModelChs.vue

@@ -1615,7 +1615,7 @@ export default {
             words = wItem.chs;
             endIndex = startIndex + 1;
           }
-        } else if (item[0] === wItem.chs && sentence.indexOf(item) > -1) {
+        } else if (item.substring(0, wItem.chs.length) === wItem.chs && sentence.indexOf(item) > -1) {
           let index = null;
           let chsStr = '';
           for (let i = startIndex; i < sItem.length + 1; i++) {

+ 2 - 1
src/views/book/courseware/preview/components/dialogue_article/Practicechs.vue

@@ -1255,6 +1255,7 @@ export default {
       let curQue = JSON.parse(JSON.stringify(this.curQue));
       let wordTimeList = curQue.wordTime;
       let dhaspinyin = false; // 每段是否有拼音
+      this.handleNewword();
       curQue.detail.forEach((dItem, dIndex) => {
         dhaspinyin = false;
         let roleDetail = this.getRole(dItem);
@@ -1382,7 +1383,7 @@ export default {
             words = wItem.chs;
             endIndex = startIndex + 1;
           }
-        } else if (item[0] === wItem.chs && sentence.indexOf(item) > -1) {
+        } else if (item.substring(0, wItem.chs.length) === wItem.chs && sentence.indexOf(item) > -1) {
           let index = null;
           let chsStr = '';
           for (let i = startIndex; i < sItem.length + 1; i++) {