Explorar o código

Merge branch 'lhd'

natasha hai 1 semana
pai
achega
377083520c

+ 1 - 1
src/api/article.js

@@ -7,7 +7,7 @@ export function segSentences(data) {
 
 // 批量分词
 export function BatchSegContent(data) {
-  return http.post(`/OtherSysTool/GCLSHMToolsServer/api/nlp/chinese/text2word`, data);
+  return http.post(`${process.env.VUE_APP_EepServer}?MethodName=tool-TextFC`, data);
 }
 
 // 音频预处理

+ 147 - 114
src/views/book/courseware/create/components/question/article/Article.vue

@@ -194,40 +194,70 @@ export default {
             textList.push(str);
           }
         });
-        // 分句
-        let sentenceList = []; // 句子按段数组
-        let data = {
-          textList,
-        };
-        segSentences(data)
+        BatchSegContent({
+          text: this.data.content,
+          is_build_pinyin: 'true',
+          is_custom_fc: 'false',
+          is_vocabulary_pinyin_lt: 'true',
+          is_fill_punctuation_mark: 'true',
+        })
           .then((res) => {
-            let result = res.data.result;
-            sentenceList = JSON.parse(JSON.stringify(res.data.result));
-            result.forEach((item, index) => {
-              let sentenceListBase64 = [];
-              this.data.detail[index].sentences = item;
-              item.forEach((items) => {
-                sentenceListBase64.push(Base64.encode(items));
-              });
-              // 分词
-              BatchSegContent({ textList: sentenceListBase64 })
-                .then((res) => {
-                  let list = res.data.result.list;
-                  this.data.detail[index].segList = list;
-                  this.setWordsList(list, index);
-                  if (index === result.length - 1) {
-                    this.handleSenWord();
-                    this.loading = false;
-                  }
-                })
-                .catch(() => {
-                  this.loading = false;
+            this.loading = false;
+            if (res.status === 1) {
+              res.paragraph_list.forEach((item, index) => {
+                let sentenceList = []; // 句子按段数组
+                let segList = []; // 句子分词结果
+                item.forEach((items) => {
+                  let sentence = items.reduce((acc, itemss) => acc + itemss.text + '', '');
+                  let seg = items.map((itemss) => itemss.text);
+                  sentenceList.push(sentence);
+                  segList.push(seg);
                 });
-            });
+                this.data.detail[index].sentences = sentenceList;
+                this.data.detail[index].segList = segList;
+                this.setWordsList(item, index);
+              });
+              this.handleSenWord();
+            }
           })
           .catch(() => {
             this.loading = false;
           });
+
+        // 分句
+        // let sentenceList = []; // 句子按段数组
+        // let data = {
+        //   textList,
+        // };
+        // segSentences(data)
+        //   .then((res) => {
+        //     let result = res.data.result;
+        //     sentenceList = JSON.parse(JSON.stringify(res.data.result));
+        //     result.forEach((item, index) => {
+        //       let sentenceListBase64 = [];
+        //       this.data.detail[index].sentences = item;
+        //       item.forEach((items) => {
+        //         sentenceListBase64.push(Base64.encode(items));
+        //       });
+        //       // 分词
+        //       BatchSegContent({ textList: sentenceListBase64 })
+        //         .then((res) => {
+        //           let list = res.data.result.list;
+        //           this.data.detail[index].segList = list;
+        //           this.setWordsList(list, index);
+        //           if (index === result.length - 1) {
+        //             this.handleSenWord();
+        //             this.loading = false;
+        //           }
+        //         })
+        //         .catch(() => {
+        //           this.loading = false;
+        //         });
+        //     });
+        //   })
+        //   .catch(() => {
+        //     this.loading = false;
+        //   });
       }
     },
     // 处理句子和词的关系
@@ -256,22 +286,21 @@ export default {
         let sentArr = [];
 
         item.map((sItem) => {
-          let toneStr = [];
-          for (let i = 0; i < sItem.length; i++) {
-            const pattern = /[\u4e00-\u9fa5]/;
-            if (cnchar.isCnChar(sItem[i]) && !pattern.test(cnchar.spell(sItem[i], 'low', 'tone'))) {
-              toneStr.push(this.toneList[cnchar.spellInfo(cnchar.spell(sItem[i], 'low', 'tone')).tone]);
-            } else {
-              toneStr.push(' ');
-            }
-          }
+          // let toneStr = [];
+          // for (let i = 0; i < sItem.length; i++) {
+          //   const pattern = /[\u4e00-\u9fa5]/;
+          //   if (cnchar.isCnChar(sItem[i]) && !pattern.test(cnchar.spell(sItem[i], 'low', 'tone'))) {
+          //     toneStr.push(this.toneList[cnchar.spellInfo(cnchar.spell(sItem[i], 'low', 'tone')).tone]);
+          //   } else {
+          //     toneStr.push(' ');
+          //   }
+          // }
 
           let obj = {
-            chs: sItem,
-            pinyin: cnchar.spell(sItem, 'low', 'tone'),
-            pinyin_up:
-              cnchar.spell(sItem, 'low', 'tone').charAt(0).toUpperCase() + cnchar.spell(sItem, 'low', 'tone').slice(1),
-            pinyin_tone: toneStr.join(' '),
+            chs: sItem.text,
+            pinyin: sItem.pinyin,
+            pinyin_up: sItem.pinyin_up,
+            pinyin_tone: sItem.pinyin_tone,
             fontFamily: '楷体',
             textDecoration: '',
             fontWeight: '',
@@ -320,80 +349,84 @@ export default {
       }
     },
     saveWord(saveArr) {
-      saveArr.forEach((item, index) => {
-        let para = '';
-        let sentenceStr = [];
-        let sentences = [];
-        let wordsList = [];
-        item.forEach((items) => {
-          para += items.join('');
-          sentenceStr.push(items.join('&nbsp;&nbsp;'));
-          sentences.push(items.join(''));
-          let sentArr = [];
-          items.forEach((sItem) => {
-            let toneStr = [];
-            for (let i = 0; i < sItem.length; i++) {
-              const pattern = /[\u4e00-\u9fa5]/;
-              if (cnchar.isCnChar(sItem[i]) && !pattern.test(cnchar.spell(sItem[i], 'low', 'tone'))) {
-                toneStr.push(this.toneList[cnchar.spellInfo(cnchar.spell(sItem[i], 'low', 'tone')).tone]);
-              } else {
-                toneStr.push(' ');
-              }
+      BatchSegContent({
+        text: this.data.content,
+        is_build_pinyin: 'true',
+        is_custom_fc: 'true',
+        is_vocabulary_pinyin_lt: 'true',
+        is_fill_punctuation_mark: 'true',
+        fc_paragraph_list: saveArr,
+      }).then((res) => {
+        if (res.status === 1) {
+          res.paragraph_list.forEach((item, index) => {
+            let sentenceList = []; // 句子按段数组
+            let segList = []; // 句子分词结果
+            let sentenceStr = [];
+            let para = '';
+            let wordsList = [];
+            item.forEach((items) => {
+              let sentence = items.reduce((acc, itemss) => acc + itemss.text + '', '');
+              let sentenceS = items.reduce((acc, itemss) => acc + itemss.text + '&nbsp;&nbsp;', '');
+              let seg = items.map((itemss) => itemss.text);
+              para += items.map((itemss) => itemss.text);
+              sentenceList.push(sentence);
+              sentenceStr.push(sentenceS);
+              segList.push(seg);
+              let sentArr = [];
+              items.forEach((sItem) => {
+                let obj = {
+                  chs: sItem.text,
+                  pinyin: sItem.pinyin,
+                  pinyin_up: sItem.pinyin_up,
+                  pinyin_tone: sItem.pinyin_tone,
+                  fontFamily: '楷体',
+                  textDecoration: '',
+                  fontWeight: '',
+                  border: '',
+                  color: '',
+                  matchWords: '',
+                  matchNotes: '',
+                  img: [],
+                  imgPosition: 'after',
+                };
+                sentArr.push(obj);
+              });
+              wordsList.push(sentArr);
+            });
+            if (this.data.detail[index]) {
+              this.data.detail[index].segList = segList;
+              this.data.detail[index].para = para;
+              this.data.detail[index].sentenceStr = sentenceStr;
+              this.data.detail[index].sentences = sentenceList;
+              this.data.detail[index].wordsList = wordsList;
+            } else {
+              let obj = {
+                paraIndex: index,
+                para,
+                sentences: sentenceList,
+                segList: item,
+                seg_words: [],
+                wordsList,
+                timeList: [],
+                isTitle: false,
+                sentencesEn: [],
+                sentenceStr,
+                paraAlign: 'left',
+                remark: {
+                  chs: '',
+                  en: '',
+                  heightNumber: null,
+                  img_list: [],
+                  widthNumber: null,
+                },
+                sourceList: [],
+                sourcePosition: 'after',
+                heightNumber: null,
+                widthNumber: null,
+              };
+              this.data.detail.push(obj);
             }
-
-            let obj = {
-              chs: sItem,
-              pinyin: cnchar.spell(sItem, 'low', 'tone'),
-              pinyin_up:
-                cnchar.spell(sItem, 'low', 'tone').charAt(0).toUpperCase() +
-                cnchar.spell(sItem, 'low', 'tone').slice(1),
-              pinyin_tone: toneStr.join(' '),
-              fontFamily: '楷体',
-              textDecoration: '',
-              fontWeight: '',
-              border: '',
-              color: '',
-              matchWords: '',
-              matchNotes: '',
-              img: [],
-              imgPosition: 'after',
-            };
-            sentArr.push(obj);
           });
-          wordsList.push(sentArr);
-        });
-        if (this.data.detail[index]) {
-          this.data.detail[index].segList = item;
-          this.data.detail[index].para = para;
-          this.data.detail[index].sentenceStr = sentenceStr;
-          this.data.detail[index].sentences = sentences;
-          this.data.detail[index].wordsList = wordsList;
-        } else {
-          let obj = {
-            paraIndex: index,
-            para,
-            sentences,
-            segList: item,
-            seg_words: [],
-            wordsList,
-            timeList: [],
-            isTitle: false,
-            sentencesEn: [],
-            sentenceStr,
-            paraAlign: 'left',
-            remark: {
-              chs: '',
-              en: '',
-              heightNumber: null,
-              img_list: [],
-              widthNumber: null,
-            },
-            sourceList: [],
-            sourcePosition: 'after',
-            heightNumber: null,
-            widthNumber: null,
-          };
-          this.data.detail.push(obj);
         }
       });
       this.$message.success('保存成功,请校对拼音');

+ 165 - 109
src/views/book/courseware/create/components/question/dialogue_article/Article.vue

@@ -513,52 +513,98 @@ export default {
     // 解析输入内容
     handleChangeContent() {
       this.loading = true;
-      let textList = [];
+      let textList = '';
       this.data.detail.forEach((item, index) => {
         item.paraIndex = index;
         if (item.type === 'text') {
-          let str = Base64.encode(item.para);
-          textList.push(str);
+          textList += item.para + '\n';
         }
       });
-      let sentenceList = []; // 句子按段数组
-      let data = {
-        textList,
-      };
-      segSentences(data)
+      BatchSegContent({
+        text: textList,
+        is_build_pinyin: 'true',
+        is_custom_fc: 'false',
+        is_vocabulary_pinyin_lt: 'true',
+        is_fill_punctuation_mark: 'true',
+      })
         .then((res) => {
-          let result = res.data.result;
-          sentenceList = JSON.parse(JSON.stringify(res.data.result));
-          let i = 0;
-
-          this.data.detail.forEach((items, indexs) => {
-            let sentenceListBase64 = [];
-            if (items.type === 'text') {
-              items.sentences = sentenceList[i];
-              sentenceList[i].forEach((itemI) => {
-                sentenceListBase64.push(Base64.encode(itemI));
-              });
-              i++;
-              // 分词
-              BatchSegContent({ textList: sentenceListBase64 })
-                .then((res) => {
-                  let list = res.data.result.list;
-                  items.segList = list;
-                  this.setWordsList(list, indexs);
-                  this.handleSenWord();
-                })
-                .catch(() => {
-                  this.loading = false;
+          this.loading = false;
+          if (res.status === 1) {
+            let i = 0;
+            this.data.detail.forEach((item, index) => {
+              item.paraIndex = index;
+              if (item.type === 'text') {
+                let sentenceList = []; // 句子按段数组
+                let segList = []; // 句子分词结果
+                res.paragraph_list[i].forEach((items) => {
+                  let sentence = items.reduce((acc, itemss) => acc + itemss.text + '', '');
+                  let seg = items.map((itemss) => itemss.text);
+                  sentenceList.push(sentence);
+                  segList.push(seg);
                 });
-            }
-            if (indexs === result.length - 1) {
-              this.loading = false;
-            }
-          });
+                this.data.detail[index].sentences = sentenceList;
+                this.data.detail[index].segList = segList;
+                this.setWordsList(res.paragraph_list[i], index);
+                i++;
+              }
+            });
+            // res.paragraph_list.forEach((item, index) => {
+            //   let sentenceList = []; // 句子按段数组
+            //   let segList = []; // 句子分词结果
+            //   item.forEach((items) => {
+            //     let sentence = items.reduce((acc, itemss) => acc + itemss.text + '', '');
+            //     let seg = items.map((itemss) => itemss.text);
+            //     sentenceList.push(sentence);
+            //     segList.push(seg);
+            //   });
+            //   this.data.detail[index].sentences = sentenceList;
+            //   this.data.detail[index].segList = segList;
+            //   this.setWordsList(item, index);
+            // });
+            this.handleSenWord();
+          }
         })
         .catch(() => {
           this.loading = false;
         });
+      // let sentenceList = []; // 句子按段数组
+      // let data = {
+      //   textList,
+      // };
+      // segSentences(data)
+      //   .then((res) => {
+      //     let result = res.data.result;
+      //     sentenceList = JSON.parse(JSON.stringify(res.data.result));
+      //     let i = 0;
+
+      //     this.data.detail.forEach((items, indexs) => {
+      //       let sentenceListBase64 = [];
+      //       if (items.type === 'text') {
+      //         items.sentences = sentenceList[i];
+      //         sentenceList[i].forEach((itemI) => {
+      //           sentenceListBase64.push(Base64.encode(itemI));
+      //         });
+      //         i++;
+      //         // 分词
+      //         BatchSegContent({ textList: sentenceListBase64 })
+      //           .then((res) => {
+      //             let list = res.data.result.list;
+      //             items.segList = list;
+      //             this.setWordsList(list, indexs);
+      //             this.handleSenWord();
+      //           })
+      //           .catch(() => {
+      //             this.loading = false;
+      //           });
+      //       }
+      //       if (indexs === result.length - 1) {
+      //         this.loading = false;
+      //       }
+      //     });
+      //   })
+      //   .catch(() => {
+      //     this.loading = false;
+      //   });
     },
     // 处理句子和词的关系
     handleSenWord() {
@@ -586,22 +632,21 @@ export default {
         let sentArr = [];
 
         item.map((sItem) => {
-          let toneStr = [];
-          for (let i = 0; i < sItem.length; i++) {
-            const pattern = /[\u4e00-\u9fa5]/;
-            if (cnchar.isCnChar(sItem[i]) && !pattern.test(cnchar.spell(sItem[i], 'low', 'tone'))) {
-              toneStr.push(this.toneList[cnchar.spellInfo(cnchar.spell(sItem[i], 'low', 'tone')).tone]);
-            } else {
-              toneStr.push(' ');
-            }
-          }
+          // let toneStr = [];
+          // for (let i = 0; i < sItem.length; i++) {
+          //   const pattern = /[\u4e00-\u9fa5]/;
+          //   if (cnchar.isCnChar(sItem[i]) && !pattern.test(cnchar.spell(sItem[i], 'low', 'tone'))) {
+          //     toneStr.push(this.toneList[cnchar.spellInfo(cnchar.spell(sItem[i], 'low', 'tone')).tone]);
+          //   } else {
+          //     toneStr.push(' ');
+          //   }
+          // }
 
           let obj = {
-            chs: sItem,
-            pinyin: cnchar.spell(sItem, 'low', 'tone'),
-            pinyin_up:
-              cnchar.spell(sItem, 'low', 'tone').charAt(0).toUpperCase() + cnchar.spell(sItem, 'low', 'tone').slice(1),
-            pinyin_tone: toneStr.join(' '),
+            chs: sItem.text,
+            pinyin: sItem.pinyin,
+            pinyin_up: sItem.pinyin_up,
+            pinyin_tone: sItem.pinyin_tone,
             fontFamily: '楷体',
             textDecoration: '',
             fontWeight: '',
@@ -640,68 +685,79 @@ export default {
       this.showArticleFlag = true;
     },
     saveWord(saveArr) {
-      saveArr.forEach((item, index) => {
-        let para = '';
-        let sentenceStr = [];
-        let sentences = [];
-        let wordsList = [];
-        item.forEach((items) => {
-          para += items.join('');
-          sentenceStr.push(items.join('&nbsp;&nbsp;'));
-          sentences.push(items.join(''));
-          let sentArr = [];
-          items.forEach((sItem) => {
-            let toneStr = [];
-            for (let i = 0; i < sItem.length; i++) {
-              const pattern = /[\u4e00-\u9fa5]/;
-              if (cnchar.isCnChar(sItem[i]) && !pattern.test(cnchar.spell(sItem[i], 'low', 'tone'))) {
-                toneStr.push(this.toneList[cnchar.spellInfo(cnchar.spell(sItem[i], 'low', 'tone')).tone]);
-              } else {
-                toneStr.push(' ');
-              }
+      let textList = '';
+      this.data.detail.forEach((item, index) => {
+        item.paraIndex = index;
+        if (item.type === 'text') {
+          textList += item.para + '\n';
+        }
+      });
+      BatchSegContent({
+        text: textList,
+        is_build_pinyin: 'true',
+        is_custom_fc: 'true',
+        is_vocabulary_pinyin_lt: 'true',
+        is_fill_punctuation_mark: 'true',
+        fc_paragraph_list: saveArr,
+      }).then((res) => {
+        if (res.status === 1) {
+          res.paragraph_list.forEach((item, index) => {
+            let sentenceList = []; // 句子按段数组
+            let segList = []; // 句子分词结果
+            let sentenceStr = [];
+            let para = '';
+            let wordsList = [];
+            item.forEach((items) => {
+              let sentence = items.reduce((acc, itemss) => acc + itemss.text + '', '');
+              let sentenceS = items.reduce((acc, itemss) => acc + itemss.text + '&nbsp;&nbsp;', '');
+              let seg = items.map((itemss) => itemss.text);
+              para += items.map((itemss) => itemss.text);
+              sentenceList.push(sentence);
+              sentenceStr.push(sentenceS);
+              segList.push(seg);
+              let sentArr = [];
+              items.forEach((sItem) => {
+                let obj = {
+                  chs: sItem.text,
+                  pinyin: sItem.pinyin,
+                  pinyin_up: sItem.pinyin_up,
+                  pinyin_tone: sItem.pinyin_tone,
+                  fontFamily: '楷体',
+                  textDecoration: '',
+                  fontWeight: '',
+                  border: '',
+                  color: '',
+                  matchWords: '',
+                  matchNotes: '',
+                  img: [],
+                  imgPosition: 'after',
+                };
+                sentArr.push(obj);
+              });
+              wordsList.push(sentArr);
+            });
+            if (this.data.detail[index]) {
+              this.data.detail[index].segList = segList;
+              this.data.detail[index].para = para;
+              this.data.detail[index].sentenceStr = sentenceStr;
+              this.data.detail[index].sentences = sentenceList;
+              this.data.detail[index].wordsList = wordsList;
+            } else {
+              let obj = {
+                paraIndex: index,
+                para,
+                sentences: sentenceList,
+                segList: item,
+                seg_words: [],
+                wordsList,
+                timeList: [],
+                isTitle: false,
+                sentencesEn: [],
+                sentenceStr,
+              };
+              this.data.detail.push(obj);
             }
-
-            let obj = {
-              chs: sItem,
-              pinyin: cnchar.spell(sItem, 'low', 'tone'),
-              pinyin_up:
-                cnchar.spell(sItem, 'low', 'tone').charAt(0).toUpperCase() +
-                cnchar.spell(sItem, 'low', 'tone').slice(1),
-              pinyin_tone: toneStr.join(' '),
-              fontFamily: '楷体',
-              textDecoration: '',
-              fontWeight: '',
-              border: '',
-              color: '',
-              matchWords: '',
-              matchNotes: '',
-              img: [],
-              imgPosition: 'after',
-            };
-            sentArr.push(obj);
           });
-          wordsList.push(sentArr);
-        });
-        if (this.data.detail[index]) {
-          this.data.detail[index].segList = item;
-          this.data.detail[index].para = para;
-          this.data.detail[index].sentenceStr = sentenceStr;
-          this.data.detail[index].sentences = sentences;
-          this.data.detail[index].wordsList = wordsList;
-        } else {
-          let obj = {
-            paraIndex: index,
-            para,
-            sentences,
-            segList: item,
-            seg_words: [],
-            wordsList,
-            timeList: [],
-            isTitle: false,
-            sentencesEn: [],
-            sentenceStr,
-          };
-          this.data.detail.push(obj);
         }
       });
       this.$message.success('保存成功,请校对拼音');