Commit fc19e487 authored by 黄奎's avatar 黄奎

word解析修改

parent d73c981c
...@@ -394,6 +394,7 @@ namespace Edu.Common.Data ...@@ -394,6 +394,7 @@ namespace Edu.Common.Data
{ {
model.QuestionTypeName = "单选题(数字)"; model.QuestionTypeName = "单选题(数字)";
} }
int index = 0; int index = 0;
int chooseCount = 0; int chooseCount = 0;
foreach (var item in tempArray) foreach (var item in tempArray)
...@@ -448,6 +449,67 @@ namespace Edu.Common.Data ...@@ -448,6 +449,67 @@ namespace Edu.Common.Data
model.ChooseOptionCount = chooseCount.ToString(); model.ChooseOptionCount = chooseCount.ToString();
model.QuestionAnswer = model.QuestionAnswer.Replace(Common.Config.NumberQuestionChar, ""); model.QuestionAnswer = model.QuestionAnswer.Replace(Common.Config.NumberQuestionChar, "");
} }
//数字选择题
else if (Common.Plugin.StringHelper.IsNumber(model.QuestionAnswer.Trim()))
{
if (model.QuestionAnswer.Trim().Length == 1)
{
model.QuestionTypeName = "单选题(数字)";
}
int index = 0;
int chooseCount = 0;
foreach (var item in tempArray)
{
string pattern = @"[123456789][.]";
var tempArray2 = Regex.Split(item, pattern);
if (tempArray2 != null && tempArray2.Length == 2)
{
var tempStr = tempArray2[1].Replace(". ", "").Replace("、", "").Trim();
if (!string.IsNullOrEmpty(tempStr))
{
chooseCount++;
}
if (index == 0)
{
model.OptionA = tempStr;
}
if (index == 1)
{
model.OptionB = tempStr;
}
if (index == 2)
{
model.OptionC = tempStr;
}
if (index == 3)
{
model.OptionD = tempStr;
}
if (index == 4)
{
model.OptionE = tempStr;
}
if (index == 5)
{
model.OptionF = tempStr;
}
if (index == 6)
{
model.OptionG = tempStr;
}
if (index == 7)
{
model.OptionH = tempStr;
}
if (!string.IsNullOrEmpty(tempStr))
{
index++;
}
}
}
model.ChooseOptionCount = chooseCount.ToString();
model.QuestionAnswer = model.QuestionAnswer.Trim();
}
//简答题 //简答题
else else
{ {
...@@ -465,7 +527,7 @@ namespace Edu.Common.Data ...@@ -465,7 +527,7 @@ namespace Edu.Common.Data
{ {
string[] tempArray = null; string[] tempArray = null;
//“\r\n”开始+“1234567890”出现1次到多次+“、或.”结尾 //“\r\n”开始+“1234567890”出现1次到多次+“、或.”结尾
string pattern1 = @"\r\n[1234567890]*[、.]"; string pattern1 = @"\r\n[12345678901234567890]*[、]";
Regex reg1 = new Regex(pattern1); Regex reg1 = new Regex(pattern1);
tempArray = Regex.Split(questionStr, pattern1); tempArray = Regex.Split(questionStr, pattern1);
if (tempArray != null && tempArray.Length > 0) if (tempArray != null && tempArray.Length > 0)
......
...@@ -113,7 +113,7 @@ namespace Edu.Common.Plugin ...@@ -113,7 +113,7 @@ namespace Edu.Common.Plugin
{ {
string[] str = new string[] { "日", "月", "火", "水", "木", "金", "土" }; string[] str = new string[] { "日", "月", "火", "水", "木", "金", "土" };
int week = int.Parse(day.DayOfWeek.ToString("D")); int week = int.Parse(day.DayOfWeek.ToString("D"));
return str[week]; return str[week];
} }
...@@ -1418,5 +1418,61 @@ namespace Edu.Common.Plugin ...@@ -1418,5 +1418,61 @@ namespace Edu.Common.Plugin
} }
return flag; return flag;
} }
/// <summary>
/// 判断是不是数字
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static bool IsNumber(string str)
{
if (IsSBC(str))
{
str = ToDBC(str);
}
bool flag = Regex.IsMatch(str, @"^[+-]?\d*[.]?\d*$");
return flag;
}
/// <summary>
/// 判断是不是全角
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static bool IsSBC(string str)
{
if (2 * str.Length == Encoding.Default.GetByteCount(str))
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 全角半角
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public static string ToDBC(string input)
{
char[] array = input.ToCharArray();
for (int i = 0; i < array.Length; i++)
{
if (array[i] == 12288)
{
array[i] = (char)32;
continue;
}
if (array[i] > 65280 && array[i] < 65375)
{
array[i] = (char)(array[i] - 65248);
}
}
return new string(array);
}
} }
} }
...@@ -39,17 +39,14 @@ namespace Edu.Common.Plugin ...@@ -39,17 +39,14 @@ namespace Edu.Common.Plugin
string para = paragraph.Text; string para = paragraph.Text;
foreach (DocumentObject docObject in paragraph.ChildObjects) foreach (DocumentObject docObject in paragraph.ChildObjects)
{ {
var pic = docObject as DocPicture; if (docObject is DocPicture pic)
if (pic != null)
{ {
string imageName = string.Format(@"WordImage_{0}.png", DateTime.Now.Ticks); string imageName = string.Format(@"WordImage_{0}.png", DateTime.Now.Ticks);
using (MemoryStream ms = new MemoryStream(pic.ImageBytes)) using MemoryStream ms = new MemoryStream(pic.ImageBytes);
{ Image outputImg = Image.FromStream(ms);
Image outputImg = Image.FromStream(ms); string tempImagePath = tempPath + imageName;
string tempImagePath = tempPath + imageName; imageList.Add(tempImagePath);
imageList.Add(tempImagePath); outputImg.Save(tempImagePath, System.Drawing.Imaging.ImageFormat.Png);
outputImg.Save(tempImagePath, System.Drawing.Imaging.ImageFormat.Png);
}
} }
} }
} }
...@@ -127,12 +124,12 @@ namespace Edu.Common.Plugin ...@@ -127,12 +124,12 @@ namespace Edu.Common.Plugin
} }
string[] tempArray = null; string[] tempArray = null;
//“\r\n”开始+“1234567890”出现1次到多次+“、或.”结尾 //“\r\n”开始+“1234567890”出现1次到多次+“、或.”结尾 (\r\n[1234567890]*[、.])
string pattern1 = @"\r\n[1234567890]*[、.]"; string pattern1 = @"\r\n[12345678901234567890]*[、]";
Regex reg1 = new Regex(pattern1); Regex reg1 = new Regex(pattern1);
if (isBigType) if (isBigType)
{ {
string pattern2 = @"\r\n[(][一二三四五六七八九十]*[)]"; string pattern2 = @"[\r\n][(][一二三四五六七八九十]*[)]";
Regex reg2 = new Regex(pattern2); Regex reg2 = new Regex(pattern2);
if (reg2.IsMatch(questionStr)) if (reg2.IsMatch(questionStr))
{ {
......
...@@ -109,6 +109,10 @@ namespace Edu.Module.Question ...@@ -109,6 +109,10 @@ namespace Edu.Module.Question
case "short-answer": case "short-answer":
item.SubAnwser = Common.Plugin.JsonHelper.DeserializeObject<List<fillInItem>>(item.SubAnwser.ToString()); item.SubAnwser = Common.Plugin.JsonHelper.DeserializeObject<List<fillInItem>>(item.SubAnwser.ToString());
break; break;
//单选题(数字)
case "single-number":
item.SubAnwser = Common.Plugin.JsonHelper.DeserializeObject<List<optionItem>>(item.SubAnwser.ToString());
break;
} }
} }
} }
......
...@@ -7,7 +7,7 @@ namespace Edu.Test ...@@ -7,7 +7,7 @@ namespace Edu.Test
static void Main(string[] args) static void Main(string[] args)
{ {
string filePath = ""; string filePath = "";
filePath = @"C:/Users/qiaoyajun/Desktop/数字选项测试.docx"; filePath = @"C:/Users/qiaoyajun/Desktop/10年7月N3题库-朱俊贤 - 副本.docx";
//filePath = @"C:/Users/qiaoyajun/Desktop/EduWordTemplate.doc"; //filePath = @"C:/Users/qiaoyajun/Desktop/EduWordTemplate.doc";
var data = Common.Data.QuestionHelper.GetWordQuestionData(filePath); var data = Common.Data.QuestionHelper.GetWordQuestionData(filePath);
Console.WriteLine(Common.Plugin.JsonHelper.Serialize(data)); Console.WriteLine(Common.Plugin.JsonHelper.Serialize(data));
......
...@@ -1069,7 +1069,9 @@ namespace Edu.WebApi.Controllers.Course ...@@ -1069,7 +1069,9 @@ namespace Edu.WebApi.Controllers.Course
List<readingComprehensioItem> readingList = new List<readingComprehensioItem>(); List<readingComprehensioItem> readingList = new List<readingComprehensioItem>();
foreach (var subItem in item.SubQuestionList) foreach (var subItem in item.SubQuestionList)
{ {
switch (subItem.QuestionTypeName) Int32.TryParse(subItem.ChooseOptionCount, out int subChooseCount);
List<optionItem> singleList = new List<optionItem>();
switch (subItem.QuestionTypeName)
{ {
//单选题 //单选题
case "单选题": case "单选题":
...@@ -1081,8 +1083,7 @@ namespace Edu.WebApi.Controllers.Course ...@@ -1081,8 +1083,7 @@ namespace Edu.WebApi.Controllers.Course
SubTitle = subItem.QuestionTitle, SubTitle = subItem.QuestionTitle,
SubAnwser=new object() SubAnwser=new object()
}; };
Int32.TryParse(subItem.ChooseOptionCount, out int subChooseCount);
List<optionItem> singleList = new List<optionItem>();
for (var i = 0; i < subChooseCount; i++) for (var i = 0; i < subChooseCount; i++)
{ {
var singleModel = new optionItem() var singleModel = new optionItem()
...@@ -1116,6 +1117,49 @@ namespace Edu.WebApi.Controllers.Course ...@@ -1116,6 +1117,49 @@ namespace Edu.WebApi.Controllers.Course
readingModel.SubAnwser = singleList; readingModel.SubAnwser = singleList;
readingList.Add(readingModel); readingList.Add(readingModel);
break; break;
case "单选题(数字)":
readingComprehensioItem readingModel2 = new readingComprehensioItem()
{
QuestionKey = "single-number",
QuestionName = "单选题(数字)",
QuestionType = 19,
SubTitle = subItem.QuestionTitle,
SubAnwser = new object()
};
for (var i = 0; i < subChooseCount; i++)
{
var singleModel = new optionItem()
{
Name = (i+1).ToString(),
Content = "",
IsAnswer = subItem.QuestionAnswer.Trim()==(i+1).ToString()
};
if (i == 0)
{
singleModel.Content = subItem.OptionA;
}
if (i == 1)
{
singleModel.Content = subItem.OptionB;
}
if (i == 2)
{
singleModel.Content = subItem.OptionC;
}
if (i == 3)
{
singleModel.Content = subItem.OptionD;
}
if (singleModel.IsAnswer)
{
model.Answer += singleModel.Name + ",";
}
singleList.Add(singleModel);
}
readingModel2.SubAnwser = singleList;
readingList.Add(readingModel2);
break;
} }
} }
model.QuestionContent = Common.Plugin.JsonHelper.Serialize(readingList); model.QuestionContent = Common.Plugin.JsonHelper.Serialize(readingList);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment