소스 검색

文章只生成分词

natasha 2 년 전
부모
커밋
d8ecb90b75

+ 54 - 5
src/components/Adult/inputModules/ArticleTemChs/components/SegbywordChs.vue

@@ -79,6 +79,9 @@
             show-word-limit
           ></el-input>
           <div class="NPC-gPinyin">
+            <el-button type="danger" size="small" @click="_sureSegWord"
+              >确定分词结果</el-button
+            >
             <el-button type="danger" size="small" @click="_createPinyin"
               >确定生成拼音</el-button
             >
@@ -94,6 +97,15 @@
                 style="width: 400px"
               >
                 <el-table-column prop="chs" label="词" width="180">
+                    <template slot-scope="scope">
+                    <el-input
+                      v-model="scope.row.chs"
+                      placeholder="请输入内容"
+                      @blur="onBlur(scope.row, 'chs')"
+                      maxlength="200"
+                      show-word-limit
+                    ></el-input>
+                  </template>
                 </el-table-column>
                 <el-table-column label="拼音" width="220">
                   <template slot-scope="scope">
@@ -237,6 +249,44 @@ export default {
       var RegExp = /^[a-zA-Z]+$/;
       return RegExp.test(str);
     },
+    //确定分词结果
+    _sureSegWord() {
+      let sentIndex = this.sentIndex;
+      let sent_arr = this.paraCon.seg_words[sentIndex].sent_str.split(/\s+/);
+      let res_str = "";
+      sent_arr.forEach((item) => {
+        if (item) {
+          let bool = this.checkEn(item);
+        //   if (bool) {
+        //     res_str += item.trim() + " ";
+        //   } else 
+          if (item == "(") {
+            res_str += " " + item.trim() + " ";
+          } else if (item == ")") {
+            res_str += " " + item.trim() + " ";
+          } else {
+            res_str += item.trim();
+          }
+        }
+      });
+      res_str = res_str.replace(/\s+/g, " ");
+      let org_sent = this.paraCon.sentences[sentIndex];
+      if (res_str.trim() != org_sent.trim()) {
+        this.$message.warning("跟原句不一致,请检查是否误删除或新增其他内容");
+        return;
+      }
+      let arr = this.paraCon.seg_words[sentIndex].sent_str.split(/\s+/);
+      this.$set(this.paraCon.segList, sentIndex, arr);
+      let wordsList = [];
+      arr.forEach((sItem) => {
+        let obj = {
+          chs: sItem,
+          pinyin: "",
+        };
+        wordsList.push(obj);
+      });
+      this.$set(this.paraCon.wordsList, sentIndex, wordsList);
+    },
     //生成拼音
     _createPinyin() {
       let sentIndex = this.sentIndex;
@@ -245,9 +295,10 @@ export default {
       sent_arr.forEach((item) => {
         if (item) {
           let bool = this.checkEn(item);
-          if (bool) {
-            res_str += item.trim() + " ";
-          } else if (item == "(") {
+        //   if (bool) {
+        //     res_str += item.trim() + " ";
+        //   } else 
+          if (item == "(") {
             res_str += " " + item.trim() + " ";
           } else if (item == ")") {
             res_str += " " + item.trim() + " ";
@@ -332,8 +383,6 @@ export default {
   created() {},
   //生命周期 - 挂载完成(可以访问DOM元素)
   mounted() {
-    console.log("====分词结果====");
-    console.log(this.curQue.detail);
     this.getParaSegWordsResult();
   },
   beforeCreate() {}, //生命周期 - 创建之前

+ 40 - 0
src/components/Adult/inputModules/DialogueArticleChs/components/SegbywordChs.vue

@@ -90,6 +90,9 @@
             show-word-limit
           ></el-input>
           <div class="NPC-gPinyin">
+            <el-button type="danger" size="small" @click="_sureSegWord"
+              >确定分词结果</el-button
+            >
             <el-button type="danger" size="small" @click="_createPinyin"
               >确定生成拼音</el-button
             >
@@ -247,6 +250,43 @@ export default {
       var RegExp = /^[a-zA-Z]+$/;
       return RegExp.test(str);
     },
+    //确定分词结果
+    _sureSegWord() {
+      let sentIndex = this.sentIndex;
+      let sent_arr = this.paraCon.seg_words[sentIndex].sent_str.split(/\s+/);
+      let res_str = "";
+      sent_arr.forEach((item) => {
+        if (item) {
+          let bool = this.checkEn(item);
+          if (bool) {
+            res_str += item.trim() + " ";
+          } else if (item == "(") {
+            res_str += " " + item.trim() + " ";
+          } else if (item == ")") {
+            res_str += " " + item.trim() + " ";
+          } else {
+            res_str += item.trim();
+          }
+        }
+      });
+      res_str = res_str.replace(/\s+/g, " ");
+      let org_sent = this.paraCon.sentences[sentIndex];
+      if (res_str.trim() != org_sent.trim()) {
+        this.$message.warning("跟原句不一致,请检查是否误删除或新增其他内容");
+        return;
+      }
+      let arr = this.paraCon.seg_words[sentIndex].sent_str.split(/\s+/);
+      this.$set(this.paraCon.segList, sentIndex, arr);
+      let wordsList = [];
+      arr.forEach((sItem) => {
+        let obj = {
+          chs: sItem,
+          pinyin: "",
+        };
+        wordsList.push(obj);
+      });
+      this.$set(this.paraCon.wordsList, sentIndex, wordsList);
+    },
     //生成拼音
     _createPinyin() {
       let sentIndex = this.sentIndex;

+ 12 - 8
src/components/Adult/preview/ArticleViewChs/NormalModelChs.vue

@@ -79,7 +79,7 @@
                     >
                       <span class="NNPE-words-box">
                         <span
-                          v-if="curQue.pyPosition == 'top' && config.isShowPY"
+                          v-if="curQue.pyPosition == 'top' && config.isShowPY && item.dhaspinyin"
                           :class="[
                             'NNPE-pinyin',
                             pItem.className ? pItem.className : '',
@@ -121,7 +121,7 @@
                         </span>
                         <span
                           v-if="
-                            curQue.pyPosition == 'bottom' && config.isShowPY
+                            curQue.pyPosition == 'bottom' && config.isShowPY && item.dhaspinyin
                           "
                           :class="[
                             'NNPE-pinyin',
@@ -133,7 +133,7 @@
                       </span>
                       <span class="NNPE-words-box">
                         <span
-                          v-if="curQue.pyPosition == 'top' && config.isShowPY"
+                          v-if="curQue.pyPosition == 'top' && config.isShowPY && item.dhaspinyin"
                           :class="[
                             'NNPE-pinyin',
                             noFont.indexOf(item.wordsList[pIndex + 1].pinyin) >
@@ -172,7 +172,7 @@
                         >
                         <span
                           v-if="
-                            curQue.pyPosition == 'bottom' && config.isShowPY
+                            curQue.pyPosition == 'bottom' && config.isShowPY && item.dhaspinyin
                           "
                           :class="[
                             'NNPE-pinyin',
@@ -194,7 +194,7 @@
                         "
                       >
                         <span
-                          v-if="curQue.pyPosition == 'top' && config.isShowPY"
+                          v-if="curQue.pyPosition == 'top' && config.isShowPY && item.dhaspinyin"
                           :class="[
                             'NNPE-pinyin',
                             noFont.indexOf(item.wordsList[pIndex + 2].pinyin) >
@@ -233,7 +233,7 @@
                         >
                         <span
                           v-if="
-                            curQue.pyPosition == 'bottom' && config.isShowPY
+                            curQue.pyPosition == 'bottom' && config.isShowPY && item.dhaspinyin
                           "
                           :class="[
                             'NNPE-pinyin',
@@ -249,7 +249,7 @@
                     </template>
                     <template v-else>
                       <span
-                        v-if="curQue.pyPosition == 'top' && config.isShowPY"
+                        v-if="curQue.pyPosition == 'top' && config.isShowPY && item.dhaspinyin"
                         class="NNPE-pinyin"
                         :class="[
                           pItem.chs != '“' && pItem.padding ? 'padding' : '',
@@ -292,7 +292,7 @@
                         </template>
                       </span>
                       <span
-                        v-if="curQue.pyPosition == 'bottom' && config.isShowPY"
+                        v-if="curQue.pyPosition == 'bottom' && config.isShowPY && item.dhaspinyin"
                         class="NNPE-pinyin"
                         :class="[
                           pItem.chs != '“' && pItem.padding ? 'padding' : '',
@@ -381,7 +381,9 @@ export default {
       let curQue = JSON.parse(JSON.stringify(this.curQue));
       let wordTimeList = curQue.wordTime;
       let asIndex = 0;
+      let dhaspinyin = false; // 每段是否有拼音
       curQue.detail.forEach((dItem, dIndex) => {
+        dhaspinyin = false
         let paraArr = [
           {
             pinyin: "",
@@ -435,6 +437,7 @@ export default {
             if (wIndex == sItem.length - 1) {
               asIndex++;
             }
+            if(wItem.pinyin) dhaspinyin=true
           });
         });
         let curSentencesLeg = dItem.sentences.length;
@@ -446,6 +449,7 @@ export default {
           wordsList: paraArr,
           timeList: timeList,
           isTitle: dItem.isTitle,
+          dhaspinyin:dhaspinyin
         };
         resArr.push(paraObj);
       });

+ 11 - 8
src/components/Adult/preview/ArticleViewChs/PhraseModelChs.vue

@@ -64,7 +64,7 @@
                     >
                       <span class="NNPE-words-box">
                         <span
-                          v-if="curQue.pyPosition == 'top' && config.isShowPY"
+                          v-if="curQue.pyPosition == 'top' && config.isShowPY && item.dhaspinyin"
                           :class="[
                             'NNPE-pinyin',
                             pItem.className ? pItem.className : '',
@@ -81,7 +81,7 @@
                         >
                         <span
                           v-if="
-                            curQue.pyPosition == 'bottom' && config.isShowPY
+                            curQue.pyPosition == 'bottom' && config.isShowPY && item.dhaspinyin
                           "
                           :class="[
                             'NNPE-pinyin',
@@ -93,7 +93,7 @@
                       </span>
                       <span class="NNPE-words-box">
                         <span
-                          v-if="curQue.pyPosition == 'top' && config.isShowPY"
+                          v-if="curQue.pyPosition == 'top' && config.isShowPY && item.dhaspinyin"
                           :class="[
                             'NNPE-pinyin',
                             noFont.indexOf(item.wordsList[pIndex + 1].pinyin) >
@@ -109,7 +109,7 @@
                         }}</span>
                         <span
                           v-if="
-                            curQue.pyPosition == 'bottom' && config.isShowPY
+                            curQue.pyPosition == 'bottom' && config.isShowPY && item.dhaspinyin
                           "
                           :class="[
                             'NNPE-pinyin',
@@ -132,7 +132,7 @@
                         "
                       >
                         <span
-                          v-if="curQue.pyPosition == 'top' && config.isShowPY"
+                          v-if="curQue.pyPosition == 'top' && config.isShowPY && item.dhaspinyin"
                           :class="[
                             'NNPE-pinyin',
                             noFont.indexOf(item.wordsList[pIndex + 1].pinyin) >
@@ -148,7 +148,7 @@
                         }}</span>
                         <span
                           v-if="
-                            curQue.pyPosition == 'bottom' && config.isShowPY
+                            curQue.pyPosition == 'bottom' && config.isShowPY && item.dhaspinyin
                           "
                           :class="[
                             'NNPE-pinyin',
@@ -164,7 +164,7 @@
                     </template>
                     <template v-else>
                       <span
-                        v-if="curQue.pyPosition == 'top' && config.isShowPY"
+                        v-if="curQue.pyPosition == 'top' && config.isShowPY && item.dhaspinyin"
                         class="NNPE-pinyin"
                         :class="[
                           pItem.chs != '“' && pItem.padding ? 'padding' : '',
@@ -182,7 +182,7 @@
                         >{{ pItem.chs }}</span
                       >
                       <span
-                        v-if="curQue.pyPosition == 'bottom' && config.isShowPY"
+                        v-if="curQue.pyPosition == 'bottom' && config.isShowPY && item.dhaspinyin"
                         class="NNPE-pinyin"
                         :class="[
                           pItem.chs != '“' && pItem.padding ? 'padding' : '',
@@ -321,6 +321,7 @@ export default {
       let resArr = [];
       let leg = this.curQue.detail.length;
       let curQue = JSON.parse(JSON.stringify(this.curQue));
+      let dhaspinyin = false; // 每段是否有拼音
       curQue.detail.forEach((dItem, dIndex) => {
         let paraArr = [
           {
@@ -352,11 +353,13 @@ export default {
               isNewWord: this.newWords.indexOf(wItem.chs) > -1 ? true : false,
             };
             paraArr.push(obj);
+            if(wItem.pinyin) dhaspinyin=true
           });
         });
 
         let paraObj = {
           wordsList: paraArr,
+          dhaspinyin:dhaspinyin
         };
         resArr.push(paraObj);
       });

+ 11 - 8
src/components/Adult/preview/ArticleViewChs/WordModelChs.vue

@@ -63,7 +63,7 @@
                     >
                       <span class="NNPE-words-box">
                         <span
-                          v-if="curQue.pyPosition == 'top' && config.isShowPY"
+                          v-if="curQue.pyPosition == 'top' && config.isShowPY && item.dhaspinyin"
                           class="NNPE-pinyin"
                           :class="[pItem.className ? pItem.className : '']"
                           >{{ pItem.pinyin }}</span
@@ -87,7 +87,7 @@
                         >
                         <span
                           v-if="
-                            curQue.pyPosition == 'bottom' && config.isShowPY
+                            curQue.pyPosition == 'bottom' && config.isShowPY && item.dhaspinyin
                           "
                           class="NNPE-pinyin"
                           :class="[pItem.className ? pItem.className : '']"
@@ -96,7 +96,7 @@
                       </span>
                       <span class="NNPE-words-box">
                         <span
-                          v-if="curQue.pyPosition == 'top' && config.isShowPY"
+                          v-if="curQue.pyPosition == 'top' && config.isShowPY && item.dhaspinyin"
                           class="NNPE-pinyin"
                           style="text-align: left"
                           >{{ item.wordsList[pIndex + 1].pinyin }}</span
@@ -116,7 +116,7 @@
                         >
                         <span
                           v-if="
-                            curQue.pyPosition == 'bottom' && config.isShowPY
+                            curQue.pyPosition == 'bottom' && config.isShowPY && item.dhaspinyin
                           "
                           class="NNPE-pinyin"
                           style="text-align: left"
@@ -132,7 +132,7 @@
                         "
                       >
                         <span
-                          v-if="curQue.pyPosition == 'top' && config.isShowPY"
+                          v-if="curQue.pyPosition == 'top' && config.isShowPY && item.dhaspinyin"
                           :class="[
                             'NNPE-pinyin',
                             noFont.indexOf(item.wordsList[pIndex + 2].pinyin) >
@@ -171,7 +171,7 @@
                         >
                         <span
                           v-if="
-                            curQue.pyPosition == 'bottom' && config.isShowPY
+                            curQue.pyPosition == 'bottom' && config.isShowPY && item.dhaspinyin
                           "
                           :class="[
                             'NNPE-pinyin',
@@ -187,7 +187,7 @@
                     </template>
                     <template v-else>
                       <span
-                        v-if="curQue.pyPosition == 'top' && config.isShowPY"
+                        v-if="curQue.pyPosition == 'top' && config.isShowPY && item.dhaspinyin"
                         class="NNPE-pinyin"
                         :class="[
                           pItem.chs != '“' && pItem.padding ? 'padding' : '',
@@ -209,7 +209,7 @@
                         >{{ pItem.chs }}</span
                       >
                       <span
-                        v-if="curQue.pyPosition == 'bottom' && config.isShowPY"
+                        v-if="curQue.pyPosition == 'bottom' && config.isShowPY && item.dhaspinyin"
                         class="NNPE-pinyin"
                         :class="[
                           pItem.chs != '“' && pItem.padding ? 'padding' : '',
@@ -349,6 +349,7 @@ export default {
       let resArr = [];
       let leg = this.curQue.detail.length;
       let curQue = JSON.parse(JSON.stringify(this.curQue));
+      let dhaspinyin = false; // 每段是否有拼音
       curQue.detail.forEach((dItem, dIndex) => {
         let paraArr = [
           {
@@ -380,6 +381,7 @@ export default {
               isNewWord: this.newWords.indexOf(wItem.chs) > -1 ? true : false,
             };
             paraArr.push(obj);
+            if(wItem.pinyin) dhaspinyin=true
           });
         });
 
@@ -391,6 +393,7 @@ export default {
         let paraObj = {
           wordsList: paraArr,
           timeList: timeList,
+          dhaspinyin:dhaspinyin
         };
         resArr.push(paraObj);
       });