Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
Education
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
黄奎
Education
Commits
fc19e487
Commit
fc19e487
authored
Jan 22, 2021
by
黄奎
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
word解析修改
parent
d73c981c
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
181 additions
and
18 deletions
+181
-18
QuestionHelper.cs
Edu.Common/Data/QuestionHelper.cs
+63
-1
StringHelper.cs
Edu.Common/Plugin/StringHelper.cs
+57
-1
WordHelper.cs
Edu.Common/Plugin/WordHelper.cs
+9
-12
AnalysisQuestionTypeModule.cs
Edu.Module.Question/AnalysisQuestionTypeModule.cs
+4
-0
Program.cs
Edu.Test/Program.cs
+1
-1
QuestionController.cs
Edu.WebApi/Controllers/Course/QuestionController.cs
+47
-3
No files found.
Edu.Common/Data/QuestionHelper.cs
View file @
fc19e487
...
...
@@ -394,6 +394,7 @@ namespace Edu.Common.Data
{
model
.
QuestionTypeName
=
"单选题(数字)"
;
}
int
index
=
0
;
int
chooseCount
=
0
;
foreach
(
var
item
in
tempArray
)
...
...
@@ -448,6 +449,67 @@ namespace Edu.Common.Data
model
.
ChooseOptionCount
=
chooseCount
.
ToString
();
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
{
...
...
@@ -465,7 +527,7 @@ namespace Edu.Common.Data
{
string
[]
tempArray
=
null
;
//“\r\n”开始+“1234567890”出现1次到多次+“、或.”结尾
string
pattern1
=
@"\r\n[1234567890
]*[、.
]"
;
string
pattern1
=
@"\r\n[1234567890
1234567890]*[、
]"
;
Regex
reg1
=
new
Regex
(
pattern1
);
tempArray
=
Regex
.
Split
(
questionStr
,
pattern1
);
if
(
tempArray
!=
null
&&
tempArray
.
Length
>
0
)
...
...
Edu.Common/Plugin/StringHelper.cs
View file @
fc19e487
...
...
@@ -113,7 +113,7 @@ namespace Edu.Common.Plugin
{
string
[]
str
=
new
string
[]
{
"日"
,
"月"
,
"火"
,
"水"
,
"木"
,
"金"
,
"土"
};
int
week
=
int
.
Parse
(
day
.
DayOfWeek
.
ToString
(
"D"
));
return
str
[
week
];
return
str
[
week
];
}
...
...
@@ -1418,5 +1418,61 @@ namespace Edu.Common.Plugin
}
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
);
}
}
}
Edu.Common/Plugin/WordHelper.cs
View file @
fc19e487
...
...
@@ -39,17 +39,14 @@ namespace Edu.Common.Plugin
string
para
=
paragraph
.
Text
;
foreach
(
DocumentObject
docObject
in
paragraph
.
ChildObjects
)
{
var
pic
=
docObject
as
DocPicture
;
if
(
pic
!=
null
)
if
(
docObject
is
DocPicture
pic
)
{
string
imageName
=
string
.
Format
(
@"WordImage_{0}.png"
,
DateTime
.
Now
.
Ticks
);
using
(
MemoryStream
ms
=
new
MemoryStream
(
pic
.
ImageBytes
))
{
Image
outputImg
=
Image
.
FromStream
(
ms
);
string
tempImagePath
=
tempPath
+
imageName
;
imageList
.
Add
(
tempImagePath
);
outputImg
.
Save
(
tempImagePath
,
System
.
Drawing
.
Imaging
.
ImageFormat
.
Png
);
}
using
MemoryStream
ms
=
new
MemoryStream
(
pic
.
ImageBytes
);
Image
outputImg
=
Image
.
FromStream
(
ms
);
string
tempImagePath
=
tempPath
+
imageName
;
imageList
.
Add
(
tempImagePath
);
outputImg
.
Save
(
tempImagePath
,
System
.
Drawing
.
Imaging
.
ImageFormat
.
Png
);
}
}
}
...
...
@@ -127,12 +124,12 @@ namespace Edu.Common.Plugin
}
string
[]
tempArray
=
null
;
//“\r\n”开始+“1234567890”出现1次到多次+“、或.”结尾
string
pattern1
=
@"\r\n[1234567890
]*[、.
]"
;
//“\r\n”开始+“1234567890”出现1次到多次+“、或.”结尾
(\r\n[1234567890]*[、.])
string
pattern1
=
@"\r\n[1234567890
1234567890]*[、
]"
;
Regex
reg1
=
new
Regex
(
pattern1
);
if
(
isBigType
)
{
string
pattern2
=
@"
\r\n
[(][一二三四五六七八九十]*[)]"
;
string
pattern2
=
@"
[\r\n]
[(][一二三四五六七八九十]*[)]"
;
Regex
reg2
=
new
Regex
(
pattern2
);
if
(
reg2
.
IsMatch
(
questionStr
))
{
...
...
Edu.Module.Question/AnalysisQuestionTypeModule.cs
View file @
fc19e487
...
...
@@ -109,6 +109,10 @@ namespace Edu.Module.Question
case
"short-answer"
:
item
.
SubAnwser
=
Common
.
Plugin
.
JsonHelper
.
DeserializeObject
<
List
<
fillInItem
>>(
item
.
SubAnwser
.
ToString
());
break
;
//单选题(数字)
case
"single-number"
:
item
.
SubAnwser
=
Common
.
Plugin
.
JsonHelper
.
DeserializeObject
<
List
<
optionItem
>>(
item
.
SubAnwser
.
ToString
());
break
;
}
}
}
...
...
Edu.Test/Program.cs
View file @
fc19e487
...
...
@@ -7,7 +7,7 @@ namespace Edu.Test
static
void
Main
(
string
[]
args
)
{
string
filePath
=
""
;
filePath
=
@"C:/Users/qiaoyajun/Desktop/
数字选项测试
.docx"
;
filePath
=
@"C:/Users/qiaoyajun/Desktop/
10年7月N3题库-朱俊贤 - 副本
.docx"
;
//filePath = @"C:/Users/qiaoyajun/Desktop/EduWordTemplate.doc";
var
data
=
Common
.
Data
.
QuestionHelper
.
GetWordQuestionData
(
filePath
);
Console
.
WriteLine
(
Common
.
Plugin
.
JsonHelper
.
Serialize
(
data
));
...
...
Edu.WebApi/Controllers/Course/QuestionController.cs
View file @
fc19e487
...
...
@@ -1069,7 +1069,9 @@ namespace Edu.WebApi.Controllers.Course
List
<
readingComprehensioItem
>
readingList
=
new
List
<
readingComprehensioItem
>();
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
"单选题"
:
...
...
@@ -1081,8 +1083,7 @@ namespace Edu.WebApi.Controllers.Course
SubTitle
=
subItem
.
QuestionTitle
,
SubAnwser
=
new
object
()
};
Int32
.
TryParse
(
subItem
.
ChooseOptionCount
,
out
int
subChooseCount
);
List
<
optionItem
>
singleList
=
new
List
<
optionItem
>();
for
(
var
i
=
0
;
i
<
subChooseCount
;
i
++)
{
var
singleModel
=
new
optionItem
()
...
...
@@ -1116,6 +1117,49 @@ namespace Edu.WebApi.Controllers.Course
readingModel
.
SubAnwser
=
singleList
;
readingList
.
Add
(
readingModel
);
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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment