chengjie 2 月之前
父節點
當前提交
3817614241
共有 2 個文件被更改,包括 17 次插入15 次删除
  1. 6 5
      src/api/miaoguo/literacyController.js
  2. 11 10
      src/util/stringClass.js

+ 6 - 5
src/api/miaoguo/literacyController.js

@@ -94,7 +94,7 @@ export async function GetMiaoguoAISearch(ctx) {
94 94
                 result=JSON.parse(literacyItem[0].JSONString);
95 95
                 //console.log("3:"+moment().format("mm:ss"));
96 96
                 //查找英语词频
97
-                if (!stringUtils.IsChineseSentence(param.Word)){
97
+                if (!stringUtils.HasChinese(param.Word)){
98 98
                     param.Word=stringUtils.ReplaceAllString(param.Word,"'","ˈ");
99 99
                     let sql ="select FinallyNum from WordFrequency where Word='"+param.Word+"';";
100 100
                     //console.log(sql);
@@ -120,7 +120,7 @@ export async function GetMiaoguoAISearch(ctx) {
120 120
                         result.ENG.Book=arrTemp;
121 121
                 }
122 122
                 //单个汉字,查找是否在人教版中
123
-                if (stringUtils.IsChineseSentence(param.Word) && param.Word.length==1){
123
+                if (stringUtils.HasChinese(param.Word) && param.Word.length==1){
124 124
                     let sql = "select b.Name,u.Name as 'Name2' from HanziUnit u inner join HanziBook b on u.HanziBookID=b.ID where ((b.ID>=13 and b.ID<=24) or (b.ID>=61 and b.ID<=72)) and u.Example like '%"+param.Word+"%' order by b.Name;";
125 125
                     //console.log(sql);
126 126
                     let list=await commonModel.RunSql({},sql);
@@ -233,7 +233,7 @@ export async function GetMiaoguoAISearch(ctx) {
233 233
 
234 234
             }
235 235
             //整句中是否有中文
236
-            else if ((stringUtils.IsChineseSentence(param.Word)) && param.SearchType!="eng") {
236
+            else if ((stringUtils.HasChinese(param.Word)) && param.SearchType!="eng") {
237 237
             
238 238
                 //判断是否都是中文
239 239
                 if (stringUtils.IsChinese(param.Word)){
@@ -289,7 +289,7 @@ export async function GetMiaoguoAISearch(ctx) {
289 289
         }
290 290
 
291 291
         //判断是否有公式
292
-        if (stringUtils.IsChineseSentence(param.Word) && param.Word.length>=2 && param.SearchType!="zici") {
292
+        if (stringUtils.HasChinese(param.Word) && param.Word.length>=2 && param.SearchType!="zici") {
293 293
 
294 294
             if (param.SearchType=="latex"){
295 295
                 let sql="SELECT * FROM kylx365_db.LatexTable where Name = '"+param.Word+"';";
@@ -362,7 +362,7 @@ export async function GetMiaoguoAISearch(ctx) {
362 362
                 }
363 363
             }
364 364
         }
365
-
365
+        
366 366
         globalCache.set(cacheKey, result, config.BufferMemoryTimeHigh);
367 367
         console.log("缓存");
368 368
     }
@@ -391,6 +391,7 @@ function getWordFrequency(id){
391 391
         let num=Math.floor(id/1000)*1000;
392 392
         result={Min:num,Max:Number(num+1000)};
393 393
     }
394
+    
394 395
     return result;
395 396
 }
396 397
 

+ 11 - 10
src/util/stringClass.js

@@ -52,7 +52,7 @@ import os from 'os';
52 52
  * @property {Function} FormatMoney - 将金额转换为格式化字符串
53 53
  * @property {Function} FormatPercentageToFigure - 将百分比转换为数字
54 54
  * @property {Function} SortArrayByStringLength - 根据字符串长度排序数组
55
- * @property {Function} IsChineseSentence - 判断整句是否包含中文
55
+ * @property {Function} HasChinese - 判断整句是否包含中文
56 56
  * @property {Function} SentenceChinesePosition - 返回句中中文的位置
57 57
  * @property {Function} IsChinese - 判断是否是中文
58 58
  * @property {Function} IsEnglish - 判断是否是英文
@@ -756,32 +756,33 @@ export const stringUtils = {
756 756
         }
757 757
         return result;
758 758
     },
759
-    //判断整句是否有中文
760
-    IsChineseSentence: (temp) => {
761
-        let result = false;
759
+    
760
+    //返回句中中文的位置
761
+    SentenceChinesePosition: (temp) => {
762
+        let result = -1;
762 763
         const reg = /^[\u4e00-\u9fa5]|[\uFE30-\uFFA0]+$/;   /*定义验证表达式*/
763 764
 
764 765
         if (temp) {
765 766
             temp = temp.toString();
766 767
             for (let i = 0; i < temp.length; i++) {
767 768
                 if (reg.test(temp[i])) {
768
-                    result = true;
769
+                    result = i;
769 770
                     break;
770 771
                 }
771 772
             }
772 773
         }
773 774
         return result;
774 775
     },
775
-    //返回句中中文的位置
776
-    SentenceChinesePosition: (temp) => {
777
-        let result = -1;
776
+    //判断整句是否有中文
777
+    HasChinese: (temp) => {
778
+        let result = false;
778 779
         const reg = /^[\u4e00-\u9fa5]|[\uFE30-\uFFA0]+$/;   /*定义验证表达式*/
779 780
 
780 781
         if (temp) {
781 782
             temp = temp.toString();
782 783
             for (let i = 0; i < temp.length; i++) {
783 784
                 if (reg.test(temp[i])) {
784
-                    result = i;
785
+                    result = true;
785 786
                     break;
786 787
                 }
787 788
             }
@@ -790,7 +791,7 @@ export const stringUtils = {
790 791
     },
791 792
     //判断是否是中文
792 793
     IsChinese: (temp) => {
793
-        const reg = /^[\u4e00-\u9fa5]|[\uFE30-\uFFA0]+$/;   /*定义验证表达式*/
794
+        const reg = /^[\u4e00-\u9fa5\uFE30-\uFFA0]+$/;   /*定义验证表达式*/
794 795
         return reg.test(temp);     /*进行验证*/
795 796
     },
796 797
     //判断是否是英文