chengjie 2 months ago
parent
commit
3817614241
2 changed files with 17 additions and 15 deletions
  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
                 result=JSON.parse(literacyItem[0].JSONString);
94
                 result=JSON.parse(literacyItem[0].JSONString);
95
                 //console.log("3:"+moment().format("mm:ss"));
95
                 //console.log("3:"+moment().format("mm:ss"));
96
                 //查找英语词频
96
                 //查找英语词频
97
-                if (!stringUtils.IsChineseSentence(param.Word)){
97
+                if (!stringUtils.HasChinese(param.Word)){
98
                     param.Word=stringUtils.ReplaceAllString(param.Word,"'","ˈ");
98
                     param.Word=stringUtils.ReplaceAllString(param.Word,"'","ˈ");
99
                     let sql ="select FinallyNum from WordFrequency where Word='"+param.Word+"';";
99
                     let sql ="select FinallyNum from WordFrequency where Word='"+param.Word+"';";
100
                     //console.log(sql);
100
                     //console.log(sql);
@@ -120,7 +120,7 @@ export async function GetMiaoguoAISearch(ctx) {
120
                         result.ENG.Book=arrTemp;
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
                     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;";
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
                     //console.log(sql);
125
                     //console.log(sql);
126
                     let list=await commonModel.RunSql({},sql);
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
                 if (stringUtils.IsChinese(param.Word)){
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
             if (param.SearchType=="latex"){
294
             if (param.SearchType=="latex"){
295
                 let sql="SELECT * FROM kylx365_db.LatexTable where Name = '"+param.Word+"';";
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
         globalCache.set(cacheKey, result, config.BufferMemoryTimeHigh);
366
         globalCache.set(cacheKey, result, config.BufferMemoryTimeHigh);
367
         console.log("缓存");
367
         console.log("缓存");
368
     }
368
     }
@@ -391,6 +391,7 @@ function getWordFrequency(id){
391
         let num=Math.floor(id/1000)*1000;
391
         let num=Math.floor(id/1000)*1000;
392
         result={Min:num,Max:Number(num+1000)};
392
         result={Min:num,Max:Number(num+1000)};
393
     }
393
     }
394
+    
394
     return result;
395
     return result;
395
 }
396
 }
396
 
397
 

+ 11 - 10
src/util/stringClass.js

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