CrazyIter_Bin 1 年之前
父节点
当前提交
4f27d6b70c
共有 3 个文件被更改,包括 94 次插入15 次删除
  1. 1 0
      HTEXLib/DOCX/Models/LangConfig.cs
  2. 88 14
      HTEXLib/Translator/HTML2ITEMV3Translator.cs
  3. 5 1
      HTEXWeb/Config/LangConfigV3.json

+ 1 - 0
HTEXLib/DOCX/Models/LangConfig.cs

@@ -33,5 +33,6 @@ namespace HTEXLib.DOCX.Models
         public string Judge { get; set; }
         public string Level { get; set; }
         public string Count { get; set; }
+        public string Taxonomy { get; set; }
     }
 }

+ 88 - 14
HTEXLib/Translator/HTML2ITEMV3Translator.cs

@@ -32,9 +32,10 @@ namespace HTEXLib.Translator
         public const string Filed = "Filed";
         public const string Level = "Level";
         public const string Count = "Count";
+        public const string Taxonomy = "Taxonomy";
         //  public LangConfig langConfig { get; set; }
         //  public HtmlDocument doc { get; set; } = new HtmlDocument();
-        public string[] optionsKeys { get; set; }
+        public List<List<string>> optionsKeys { get; set; } = new List<List<string>>();
         public Dictionary<string, string[]> dict { get; set; }
        // public string[] Fileds { get; set; }
         public TagConfig _TagConfig { get; set; }
@@ -67,6 +68,8 @@ namespace HTEXLib.Translator
                 }
                 dict[_langConfig.Item.Answer] = new string[] { _langConfig.Lang, Answer };
                 dict[_langConfig.Item.Analysis] = new string[] { _langConfig.Lang, Analysis };
+                dict[_langConfig.Item.Taxonomy] = new string[] { _langConfig.Lang, Taxonomy };
+                
                 dict[_langConfig.Item.Ended] = new string[] { _langConfig.Lang, Ended };
                 dict[_langConfig.Item.Point] = new string[] { _langConfig.Lang, Point };
                 dict[_langConfig.Item.Score] = new string[] { _langConfig.Lang, Score };
@@ -77,7 +80,16 @@ namespace HTEXLib.Translator
                     dict[_langConfig.Item.Type[key]] = new string[] { _langConfig.Lang, Summary, key };
                 }
             }
-            optionsKeys = _TagConfig.Options.Select(s => s.ToString()).ToArray();
+            string [] ops=  _TagConfig.Options.Split('-');
+            foreach (string op in ops)
+            {
+                if (!string.IsNullOrWhiteSpace(op))
+                {
+                    var data = op.Select(z => z.ToString()).ToList();
+                    optionsKeys.Add(data);
+                }
+            }
+            // optionsKeys = .Select(s => s.ToString()).ToArray();
         }
 
         /// <summary>
@@ -91,6 +103,7 @@ namespace HTEXLib.Translator
             foreach (var _langConfig in _TagConfig.LangConfig) {
                 string ans = _TagConfig.Start + _langConfig.Item.Answer + _TagConfig.End;
                 string als = _TagConfig.Start + _langConfig.Item.Analysis + _TagConfig.End;
+                string tax = _TagConfig.Start + _langConfig.Item.Taxonomy + _TagConfig.End;
                 string end = _TagConfig.Start + _langConfig.Item.Ended + _TagConfig.End;
                 string pot = _TagConfig.Start + _langConfig.Item.Point + _TagConfig.End;
                 string scr = _TagConfig.Start + _langConfig.Item.Score + _TagConfig.End;
@@ -106,6 +119,7 @@ namespace HTEXLib.Translator
                 }
                 string[] ansarry = ans.Select(s => s.ToString()).ToArray();
                 string[] alsarry = als.Select(s => s.ToString()).ToArray();
+                string[] taxarry = tax.Select(s => s.ToString()).ToArray();
                 string[] endarry = end.Select(s => s.ToString()).ToArray();
                 string[] potarry = pot.Select(s => s.ToString()).ToArray();
                 string[] scrarry = scr.Select(s => s.ToString()).ToArray();
@@ -113,6 +127,7 @@ namespace HTEXLib.Translator
                 string[] cutarry = cut.Select(s => s.ToString()).ToArray();
                 string ansReg = string.Join("\\s*", ansarry);
                 string alsReg = string.Join("\\s*", alsarry);
+                string taxReg = string.Join("\\s*", taxarry);
                 string endReg = string.Join("\\s*", endarry);
                 string potReg = string.Join("\\s*", potarry);
                 string scrReg = string.Join("\\s*", scrarry);
@@ -120,6 +135,7 @@ namespace HTEXLib.Translator
                 string cutReg = string.Join("\\s*", cutarry);
                 html = Regex.Replace(html, ansReg, ans);
                 html = Regex.Replace(html, alsReg, als);
+                html = Regex.Replace(html, taxReg, tax);
                 html = Regex.Replace(html, endReg, end);
                 html = Regex.Replace(html, potReg, pot);
                 html = Regex.Replace(html, scrReg, scr);
@@ -370,6 +386,18 @@ namespace HTEXLib.Translator
                                 openFlag = true;
                                 openTagLang = keyInfo[0];
                                 break;
+                            case Taxonomy:
+                                //下列代码不能调整顺序
+                                if (!string.IsNullOrEmpty(openTag) && openFlag)
+                                {
+                                    DoOpenTag(openTag, openTagVal, openFlag, openTagLang, content, test);
+                                    content = new StringBuilder();
+                                }
+                                openTag = Taxonomy;
+                                openTagVal = tagValue;
+                                openFlag = true;
+                                openTagLang = keyInfo[0];
+                                break;
                             case Ended: 
                                 break;
                             case Point:
@@ -465,25 +493,39 @@ namespace HTEXLib.Translator
                 question = question.Replace(aza[idx], azh[idx]);
             }
             List<CodeValue> options = new List<CodeValue>();
-            string optsRgex = optionsKeys[0] + "\\s*(\\.|\\.|\\、|\\:|\\:)([\\s\\S]*?).*"; ;
+            int index  = 0;
+            string optsRgex = optionsKeys[0][0] + "\\s*(\\.|\\.|\\、|\\:|\\:)([\\s\\S]*?).*";
             string optsHtml = Regex.Match(question, optsRgex).Value;
+            if (string.IsNullOrWhiteSpace(optsHtml) && optionsKeys.Count>1) {
+                optsRgex = optionsKeys[1][0] + "\\s*(\\.|\\.|\\、|\\:|\\:)([\\s\\S]*?).*";
+                index=1;
+                optsHtml = Regex.Match(question, optsRgex).Value;
+            }
           //  StringBuilder textImg = new StringBuilder();
-            for (int i = 0; i < optionsKeys.Length - 1; i++)
+            for (int i = 0; i < optionsKeys[index].Count - 1; i++)
             {
-                string optRgex = optionsKeys[i] + "\\s*(\\.|\\.|\\、|\\:|\\:)([\\s\\S]*?)" + optionsKeys[i + 1] + "\\s*(\\.|\\.|\\、|\\:|\\:)";
+                string optRgex = optionsKeys[index][i] + "\\s*(\\.|\\.|\\、|\\:|\\:)([\\s\\S]*?)" + optionsKeys[index][i + 1] + "\\s*(\\.|\\.|\\、|\\:|\\:)";
                 string optHtml = Regex.Match(optsHtml, optRgex).Value;
                 if (string.IsNullOrWhiteSpace(optHtml)) {
-                    optRgex = optionsKeys[i] + "\\s*(\\.|\\.|\\、|\\:|\\:).*";
+                    optRgex = optionsKeys[index][i] + "\\s*(\\.|\\.|\\、|\\:|\\:).*";
                     optHtml = Regex.Match(optsHtml, optRgex).Value;
                 }
                 if (!string.IsNullOrEmpty(optHtml))
                 {
-                    optHtml = Regex.Replace(optHtml, optionsKeys[i + 1] + "\\s*(\\.|\\.|\\、|\\:|\\:)", "");
+                    optHtml = Regex.Replace(optHtml, optionsKeys[index][i + 1] + "\\s*(\\.|\\.|\\、|\\:|\\:)", "");
                     optHtml = optHtml.Substring(2, optHtml.Length - 2);
                     optHtml = HtmlHelper.DoUselessTag(optHtml);
                     optHtml = optHtml.TrimStart().TrimEnd();
-                   // textImg.Append(HtmlHelper.DoTextImg(optHtml));
-                    options.Add(new CodeValue { code = optionsKeys[i], value = optHtml });
+                    // textImg.Append(HtmlHelper.DoTextImg(optHtml));
+                    if (index==1)
+                    {
+                        var code =  optionsKeys[0][int.Parse(optionsKeys[index][i])-1];
+                        options.Add(new CodeValue { code = code, value = optHtml });
+                    }
+                    else {
+                        options.Add(new CodeValue { code = optionsKeys[index][i], value = optHtml });
+                    }
+                   
                 }
             }
             if (!string.IsNullOrWhiteSpace(optsHtml))
@@ -534,6 +576,15 @@ namespace HTEXLib.Translator
                                 var notin = ans.Except(codes).ToList();
                                 List<string> ansd=  ans.ToList();
                                 ansd.RemoveAll(x => notin.Contains(x));
+                                if (!ansd.IsNotEmpty()) {
+                                    ansd=new List<string>();
+                                    foreach (var an in ans) {
+                                        if (int.TryParse(an, out int op) && op>=1) {
+                                            ansd.Add(optionsKeys[0][op-1]);
+                                        }
+                                    }
+                                    ansd.RemoveAll(x => notin.Contains(x));
+                                }
                                 test.answer = ansd;
                             }
                             else {
@@ -573,6 +624,22 @@ namespace HTEXLib.Translator
                     case Analysis:
                         test.explain  = HtmlHelper.DoUselessTag(content.ToString());
                         break;
+                    case Taxonomy:
+                        {
+                            string taxonomy = HtmlHelper.DoUselessTag(content.ToString());
+                            taxonomy= BlankTag(taxonomy);
+                            if ( !string.IsNullOrWhiteSpace(taxonomy) &&  dict.TryGetValue(taxonomy, out string[] keyInfo))
+                            {
+                              
+                                var LangConfigfd = _TagConfig.LangConfig.Where(x => x.Lang ==keyInfo[0]).FirstOrDefault();
+                                var Fileds = LangConfigfd.Item.Filed.Split('|');
+                                int fld = Array.IndexOf(Fileds, taxonomy) + 1;
+                                if (fld>0) {
+                                    test.field =fld;
+                                }
+                            }
+                            break;
+                        }
                     case Ended: break;
                     case Point:
                         string Points = BlankPointTag(content.ToString());
@@ -604,12 +671,19 @@ namespace HTEXLib.Translator
                         test.level = lvl;
                         break;
                     case Filed:
-                        if (dict.TryGetValue(openTagVal, out string[] keyInfo)) {
-                            var LangConfigfd = _TagConfig.LangConfig.Where(x => x.Lang == keyInfo[0]).FirstOrDefault();
-                            var Fileds= LangConfigfd.Item.Filed.Split('|');
-                            test.field = Array.IndexOf(Fileds, openTagVal) + 1;
+                        {
+                            if (dict.TryGetValue(openTagVal, out string[] keyInfo))
+                            {
+                                var LangConfigfd = _TagConfig.LangConfig.Where(x => x.Lang == keyInfo[0]).FirstOrDefault();
+                                var Fileds = LangConfigfd.Item.Filed.Split('|');
+                                int fld = Array.IndexOf(Fileds, openTagVal) + 1;
+                                if (fld>0)
+                                {
+                                    test.field =fld;
+                                }
+                            }
+                            break;
                         }
-                        break;
                     case Count:
                         //只有填空题才配置填空数量
                         if (test.type.Equals("complete")) {

+ 5 - 1
HTEXWeb/Config/LangConfigV3.json

@@ -1,5 +1,5 @@
 {
-  "Options": "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
+  "Options": "ABCDEFGHIJKLMNOPQRSTUVWXYZ-123456789",
   "Start": "{",
   "End": "}",
   "LangConfig": [
@@ -23,6 +23,7 @@
         "Analysis": "解析",
         "Score": "配分",
         "Point": "知识点",
+        "Taxonomy": "认知层次",
         "Filed": "记忆|理解|应用|分析|评价|创造",
         "Judge": "对|错",
         "Ended": "结束",
@@ -50,6 +51,7 @@
         "Analysis": "解析",
         "Score": "配分",
         "Point": "知識點",
+        "Taxonomy": "認知層次",
         "Filed": "記憶|理解|應用|分析|評鑒|創造",
         "Judge": "對|錯",
         "Ended": "結束",
@@ -77,6 +79,7 @@
         "Analysis": "解析",
         "Score": "配分",
         "Point": "知識點",
+        "Taxonomy": "認知層次",
         "Filed": "記憶|理解|應用|分析|評鑒|創造",
         "Judge": "對|錯",
         "Ended": "結束",
@@ -104,6 +107,7 @@
         "Analysis": "Explain",
         "Score": "Score",
         "Point": "Point",
+        "Taxonomy": "Taxonomy",
         "Filed": "Remember|Understand|Apply|Analyze|Evaluate|Create",
         "Judge": "True|False",
         "Ended": "Ended",