添加项目文件。
This commit is contained in:
113
TechHelper.Client/Pages/Editor/EditorMain.razor
Normal file
113
TechHelper.Client/Pages/Editor/EditorMain.razor
Normal file
@@ -0,0 +1,113 @@
|
||||
@page "/Edit"
|
||||
@using Blazored.TextEditor
|
||||
@using System.Text.RegularExpressions
|
||||
@using TechHelper.Client.Pages.Exam
|
||||
<MudPaper Class="d-flex flex-column flex-grow-1">
|
||||
<MudPaper class="d-flex flex-grow-0 flex-column">
|
||||
|
||||
@if (@lode == true)
|
||||
{
|
||||
<MudStack Row="true">
|
||||
<MudProgressLinear Color="Color.Primary" Indeterminate="true" />
|
||||
</MudStack>
|
||||
|
||||
}
|
||||
<MudButtonGroup Color="Color.Primary" Variant="Variant.Filled">
|
||||
<MudButton OnClick="GetHTML">One</MudButton>
|
||||
<MudButton OnClick="ParseQuestions">ParseQuestions</MudButton>
|
||||
<MudButton OnClick="ParseXML">ParseXML</MudButton>
|
||||
<MudButton OnClick="ParseWithAI">ParseWithAI</MudButton>
|
||||
<MudButton OnClick="ReCorrectXMLAsync">ReCorrectXML</MudButton>
|
||||
<MudButton OnClick="ReCorrectXMLAsync">AplyAIResult</MudButton>
|
||||
<MudButton OnClick="ReCorrectXMLAsync">Save</MudButton>
|
||||
<MudButton OnClick="ReCorrectXMLAsync">Public</MudButton>
|
||||
</MudButtonGroup>
|
||||
|
||||
</MudPaper>
|
||||
<MudPaper Class="d-flex flex-row flex-grow-1 overflow-hidden">
|
||||
|
||||
|
||||
|
||||
<MudPaper Width="33%" Class="d-flex flex-column flex-grow-1 overflow-auto">
|
||||
|
||||
|
||||
|
||||
|
||||
@if (QuestionS != null && QuestionS.Any())
|
||||
{
|
||||
@foreach (var item in QuestionS)
|
||||
{
|
||||
<QuestionGroupDisplay QuestionGroup="item" IsNested="false" />
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudText Typo="Typo.body1">暂无试题内容。</MudText>
|
||||
}
|
||||
|
||||
|
||||
|
||||
</MudPaper>
|
||||
|
||||
|
||||
|
||||
<MudPaper Width="33%" Class="d-flex flex-column flex-grow-1 justify-content-between overflow-auto">
|
||||
<MudText Typo="Typo.body1">@ProgStatues</MudText>
|
||||
|
||||
@for (int i = 0; i < ParseResult.Count; i++)
|
||||
{
|
||||
int index = i;
|
||||
|
||||
<MudTextField Class="ma-3" AutoGrow="true" @bind-Value="ParseResult[index]"></MudTextField>
|
||||
}
|
||||
<MudText>@Error</MudText>
|
||||
</MudPaper>
|
||||
|
||||
|
||||
|
||||
<MudPaper Width="33%" Class="d-flex flex-column flex-grow-1 overflow-auto">
|
||||
|
||||
|
||||
|
||||
<BlazoredTextEditor @ref="@QuillHtml">
|
||||
<ToolbarContent>
|
||||
<select class="ql-header">
|
||||
<option selected=""></option>
|
||||
<option value="1"></option>
|
||||
<option value="2"></option>
|
||||
<option value="3"></option>
|
||||
<option value="4"></option>
|
||||
<option value="5"></option>
|
||||
</select>
|
||||
<span class="ql-formats">
|
||||
<button class="ql-bold"></button>
|
||||
<button class="ql-italic"></button>
|
||||
<button class="ql-underline"></button>
|
||||
<button class="ql-strike"></button>
|
||||
</span>
|
||||
<span class="ql-formats">
|
||||
<select class="ql-color"></select>
|
||||
<select class="ql-background"></select>
|
||||
</span>
|
||||
<span class="ql-formats">
|
||||
<button class="ql-list" value="ordered"></button>
|
||||
<button class="ql-list" value="bullet"></button>
|
||||
</span>
|
||||
<span class="ql-formats">
|
||||
<button class="ql-link"></button>
|
||||
</span>
|
||||
</ToolbarContent>
|
||||
|
||||
<EditorContent>
|
||||
</EditorContent>
|
||||
</BlazoredTextEditor>
|
||||
|
||||
</MudPaper>
|
||||
|
||||
|
||||
|
||||
</MudPaper>
|
||||
|
||||
|
||||
|
||||
</MudPaper>
|
214
TechHelper.Client/Pages/Editor/EditorMain.razor.cs
Normal file
214
TechHelper.Client/Pages/Editor/EditorMain.razor.cs
Normal file
@@ -0,0 +1,214 @@
|
||||
using Blazored.TextEditor;
|
||||
using Entities.Contracts;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using MudBlazor;
|
||||
using System.Text.RegularExpressions;
|
||||
using TechHelper.Client.AI;
|
||||
using TechHelper.Client.Exam;
|
||||
using static Org.BouncyCastle.Crypto.Engines.SM2Engine;
|
||||
|
||||
namespace TechHelper.Client.Pages.Editor
|
||||
{
|
||||
public enum ProgEnum
|
||||
{
|
||||
AIPrase,
|
||||
AIRectify
|
||||
}
|
||||
public partial class EditorMain
|
||||
{
|
||||
private List<QuestionGroup> QuestionS = new List<QuestionGroup>();
|
||||
|
||||
private bool lode = false;
|
||||
BlazoredTextEditor QuillHtml;
|
||||
string QuillHTMLContent;
|
||||
string AIParseResult;
|
||||
string Error;
|
||||
string ProgStatues = string.Empty;
|
||||
List<string> ParseResult = new List<string>();
|
||||
|
||||
public async Task GetHTML()
|
||||
{
|
||||
QuillHTMLContent = await this.QuillHtml.GetHTML();
|
||||
}
|
||||
|
||||
public async Task GetText()
|
||||
{
|
||||
QuillHTMLContent = await this.QuillHtml.GetText();
|
||||
}
|
||||
|
||||
private string EditorHtmlContent { get; set; } = string.Empty;
|
||||
private List<ParsedQuestion>? ParsedQuestions { get; set; }
|
||||
private bool _parseAttempted = false;
|
||||
|
||||
public class ParsedQuestion
|
||||
{
|
||||
public int Id { get; set; } // <20><>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
public string? Content { get; set; } // <20><>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD> HTML <20><><EFBFBD><EFBFBD>
|
||||
public string? Title { get; set; } // <20><>Ŀ<EFBFBD>ı<EFBFBD><C4B1>ⲿ<EFBFBD>֣<EFBFBD><D6A3><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD> Content <20><><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1>
|
||||
}
|
||||
|
||||
[Inject]
|
||||
public IAIService aIService { get; set; }
|
||||
[Inject]
|
||||
public ISnackbar Snackbar { get; set; }
|
||||
private async void ParseWithAI()
|
||||
{
|
||||
QuestionS.Clear();
|
||||
ParseResult.Clear();
|
||||
|
||||
await GetText();
|
||||
lode = true;
|
||||
StateHasChanged();
|
||||
|
||||
ProgStatues = ProgEnum.AIPrase.ToString();
|
||||
ProgStatues = $"<22><><EFBFBD>ڽ<EFBFBD><DABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD>ȴ<EFBFBD>";
|
||||
Snackbar.Add("<22><><EFBFBD>ڽ<EFBFBD><DABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD>ȴ<EFBFBD>");
|
||||
StateHasChanged();
|
||||
string respon = await aIService.CallGLM(QuillHTMLContent, AIConfiguration.BreakQuestions);
|
||||
if (respon == null)
|
||||
{
|
||||
lode = false;
|
||||
Snackbar.Add("<22><><EFBFBD>˵<EFBFBD><CBB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>°<EFBFBD>");
|
||||
return;
|
||||
}
|
||||
|
||||
var ParRespon = ExamParser.ParseExamXml<StringsList>(respon);
|
||||
|
||||
|
||||
if (ParRespon != null)
|
||||
{
|
||||
int i = 1;
|
||||
foreach (var item in ParRespon.Items)
|
||||
{
|
||||
ProgStatues = $"<22><><EFBFBD>ڽ<EFBFBD><DABD><EFBFBD><EFBFBD><EFBFBD>{i}<7D><>, <20><><EFBFBD>ȴ<EFBFBD>";
|
||||
Snackbar.Add($"<22><><EFBFBD>ڽ<EFBFBD><DABD><EFBFBD><EFBFBD><EFBFBD>{i}<7D><>, <20><><EFBFBD>ȴ<EFBFBD>");
|
||||
StateHasChanged();
|
||||
i++;
|
||||
try
|
||||
{
|
||||
var parResult = await aIService.CallGLM(item, AIConfiguration.ParseSignelQuestion);
|
||||
ParseResult.Add(parResult);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>{i}<7D><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD>Ժ<EFBFBD><D4BA><EFBFBD><EFBFBD><EFBFBD>. <20><><EFBFBD><EFBFBD>Ϊ:{ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AIParseResult = respon;
|
||||
|
||||
ProgStatues = ProgEnum.AIRectify.ToString();
|
||||
//await ReCorrectXMLAsync();
|
||||
|
||||
|
||||
ProgStatues = string.Empty;
|
||||
lode = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
|
||||
private async Task ReCorrectXMLAsync()
|
||||
{
|
||||
string respon = string.Empty;
|
||||
try
|
||||
{
|
||||
foreach (var item in ParseResult)
|
||||
{
|
||||
//respon = await aIService.CallGLM(AIParseResult, AIConfiguration.ParseSignelQuestion);
|
||||
var xmlResult = ExamParser.ParseExamXml<QuestionGroup>(item);
|
||||
QuestionS.Add(xmlResult);
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add("<22><><EFBFBD>˵<EFBFBD><CBB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>°<EFBFBD>" + ex.Message);
|
||||
}
|
||||
if (string.IsNullOrEmpty(respon))
|
||||
{
|
||||
lode = false;
|
||||
Snackbar.Add("<22><><EFBFBD>˵<EFBFBD><CBB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>°<EFBFBD>");
|
||||
|
||||
}
|
||||
|
||||
AIParseResult = respon;
|
||||
}
|
||||
|
||||
private void ParseXML()
|
||||
{
|
||||
try
|
||||
{
|
||||
var paper = ExamParser.ParseExamXml<QuestionGroup>(AIParseResult);
|
||||
//QuestionS = paper.QuestionGroups;
|
||||
Error = string.Empty;
|
||||
}
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
Snackbar.Add("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" + ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" + ex.Message);
|
||||
Error = ex.Message;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void ParseQuestions()
|
||||
{
|
||||
ParsedQuestions = new List<ParsedQuestion>();
|
||||
_parseAttempted = true;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(QuillHTMLContent))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF>ʼ<EFBFBD>ͽ<EFBFBD><CDBD><EFBFBD><EFBFBD>ı<EFBFBD><C4B1><EFBFBD>
|
||||
string startTag = "[<5B><>Ŀ<EFBFBD><C4BF>ʼ]";
|
||||
string endTag = "[<5B><>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD>]";
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD>ƥ<EFBFBD><C6A5><EFBFBD>ӿ<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD>ǵ<EFBFBD><C7B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֮<EFBFBD><D6AE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD>
|
||||
// (?s) <20><><EFBFBD>õ<EFBFBD><C3B5><EFBFBD>ģʽ<C4A3><CABD><EFBFBD><EFBFBD> . ƥ<>任<EFBFBD>з<EFBFBD>
|
||||
string pattern = Regex.Escape(startTag) + "(.*?)" + Regex.Escape(endTag);
|
||||
var matches = Regex.Matches(QuillHTMLContent, pattern, RegexOptions.Singleline);
|
||||
|
||||
int questionId = 1;
|
||||
foreach (Match match in matches)
|
||||
{
|
||||
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֮<EFBFBD><D6AE><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>
|
||||
string rawQuestionHtml = match.Groups[1].Value;
|
||||
|
||||
// <20>Ƴ<EFBFBD><C6B3><EFBFBD><EFBFBD>ܲ<EFBFBD><DCB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>еı<D0B5><C4B1>ǣ<EFBFBD><C7A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD>Ѿ<EFBFBD><D1BE>ų<EFBFBD><C5B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǣ<EFBFBD><C7A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
string cleanedQuestionContent = rawQuestionHtml
|
||||
.Replace(startTag, "")
|
||||
.Replace(endTag, "")
|
||||
.Trim();
|
||||
|
||||
// <20><><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD>⣨<EFBFBD><E2A3A8><EFBFBD>磬ƥ<E7A3AC>䡰һ<E4A1B0><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD>У<EFBFBD>
|
||||
string? questionTitle = null;
|
||||
try
|
||||
{
|
||||
|
||||
var firstLineMatch = Regex.Match(cleanedQuestionContent, @"^(<p>)?\s*([һ<><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߰˾<DFB0>ʮ]+\s*[<5B><><EFBFBD><EFBFBD>]|\d+\s*[<5B><>\.]).*?</p>", RegexOptions.IgnoreCase | RegexOptions.Singleline);
|
||||
if (firstLineMatch.Success)
|
||||
{
|
||||
// <20><> HTML <20><><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD>ı<EFBFBD><C4B1><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>
|
||||
questionTitle = Regex.Replace(firstLineMatch.Value, "<[^>]*>", "").Trim();
|
||||
}
|
||||
}
|
||||
catch (Exception ex) { }
|
||||
|
||||
ParsedQuestions.Add(new ParsedQuestion
|
||||
{
|
||||
Id = questionId++,
|
||||
Content = cleanedQuestionContent,
|
||||
Title = questionTitle
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
50
TechHelper.Client/Pages/Editor/Test.razor
Normal file
50
TechHelper.Client/Pages/Editor/Test.razor
Normal file
@@ -0,0 +1,50 @@
|
||||
@page "/test"
|
||||
<MudPaper Class="d-flex flex-column justify-space-around flex-grow-1 overflow-scroll">
|
||||
<MudText>HELLO </MudText>
|
||||
<MudText>HELLO </MudText>
|
||||
<MudText>HELLO </MudText>
|
||||
<MudText>HELLO </MudText>
|
||||
<MudText>HELLO </MudText>
|
||||
<MudText>HELLO </MudText>
|
||||
<MudText>HELLO </MudText>
|
||||
<MudText>HELLO </MudText>
|
||||
<MudText>HELLO </MudText>
|
||||
<MudText>HELLO </MudText>
|
||||
<MudText>HELLO </MudText>
|
||||
<MudText>HELLO </MudText>
|
||||
<MudText>HELLO </MudText>
|
||||
<MudText>HELLO </MudText>
|
||||
<MudText>HELLO </MudText>
|
||||
<MudText>HELLO </MudText>
|
||||
<MudText>HELLO </MudText>
|
||||
<MudText>HELLO </MudText>
|
||||
<MudText>HELLO </MudText>
|
||||
<MudText>HELLO </MudText>
|
||||
<MudText>HELLO </MudText>
|
||||
<MudText>HELLO </MudText>
|
||||
<MudText>HELLO </MudText>
|
||||
<MudText>HELLO </MudText>
|
||||
<MudText>HELLO </MudText>
|
||||
<MudText>HELLO </MudText>
|
||||
<MudText>HELLO </MudText>
|
||||
<MudText>HELLO </MudText>
|
||||
<MudText>HELLO </MudText>
|
||||
<MudText>HELLO </MudText>
|
||||
<MudText>HELLO </MudText>
|
||||
<MudText>HELLO </MudText>
|
||||
<MudText>HELLO </MudText>
|
||||
<MudText>HELLO </MudText>
|
||||
<MudText>HELLO </MudText>
|
||||
<MudText>HELLO </MudText>
|
||||
<MudText>HELLO </MudText>
|
||||
<MudText>HELLO </MudText>
|
||||
<MudText>HELLO </MudText>
|
||||
<MudText>HELLO </MudText>
|
||||
<MudText>HELLO </MudText>
|
||||
<MudText>HELLO </MudText>
|
||||
<MudText>HELLO </MudText>
|
||||
</MudPaper>
|
||||
|
||||
@code {
|
||||
|
||||
}
|
Reference in New Issue
Block a user