perf: 📜️强化常识性检测数据结构优化

This commit is contained in:
LittleBoy 2025-03-28 09:34:03 +08:00
parent 342e32f49f
commit e8c18e6eb8
10 changed files with 116 additions and 32 deletions

5
.gitignore vendored
View File

@ -6,4 +6,7 @@ TestConsoleApp
obj obj
**/obj/Debug/** **/obj/Debug/**
**/obj/Release/** **/obj/Release/**
**/obj/Test/** **/obj/Test/**
**/**/obj/Debug/**
**/**/obj/Release/**
**/**/obj/Test/**

Binary file not shown.

View File

@ -3,23 +3,16 @@ using AIProofread.core;
using AIProofread.Model; using AIProofread.Model;
using AIProofread.Util; using AIProofread.Util;
using Microsoft.Office.Interop.Word; using Microsoft.Office.Interop.Word;
using Microsoft.Office.Tools.Word;
using Microsoft.Web.WebView2.Core; using Microsoft.Web.WebView2.Core;
using Microsoft.Web.WebView2.WinForms; using Microsoft.Web.WebView2.WinForms;
using Newtonsoft.Json; using Newtonsoft.Json;
using NPOI; using NPOI;
using NPOI.SS.Formula;
using NPOI.XSSF.UserModel;
using NPOI.XWPF.UserModel;
using Org.BouncyCastle.Asn1.Crmf;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Drawing;
using System.IO; using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading;
using System.Windows.Forms; using System.Windows.Forms;
using UtilLib; using UtilLib;
using Document = Microsoft.Office.Interop.Word.Document; using Document = Microsoft.Office.Interop.Word.Document;
@ -336,6 +329,17 @@ namespace AIProofread
var documentInfo = documentId > 0 ? Globals.ThisAddIn.GetDocumentById(documentId) : Globals.ThisAddIn.ActiveDocument; var documentInfo = documentId > 0 ? Globals.ThisAddIn.GetDocumentById(documentId) : Globals.ThisAddIn.ActiveDocument;
var doc = documentInfo.CurrentDocument; var doc = documentInfo.CurrentDocument;
// 判断是否处理修订模式
if (doc.TrackRevisions)
{
//data.Add("code", 1);
//data.Add("message", "文档存在未处理的修订,请处理后再进行校对");
var ret = MessageBox.Show("文档当前处于修订模式,是否关闭此模式?","提示",MessageBoxButtons.YesNo);
if(ret == DialogResult.Yes)
{
doc.TrackRevisions = false;
}
}
if (ShouldUpgradeForced()) if (ShouldUpgradeForced())
{ {
data.Add("code", 2); data.Add("code", 2);

View File

@ -9,6 +9,30 @@ namespace AIProofread
Test, Test,
Prod Prod
} }
public class AppServer
{
/// <summary>
/// 开发环境
/// </summary>
public const string DEV = "http://localhost:5173/";
/// <summary>
/// 测试环境
/// </summary>
public const string TEST = "http://gm2-plugin.zverse.group/";
/// <summary>
/// 果麦预发布-灰度
/// </summary>
public const string PRE = "https://pre-gm-plugin.gachafun.com/";
/// <summary>
/// 果麦生产
/// </summary>
public const string PROD = "https://gm-plugin.gachafun.com/";
/// <summary>
/// 果麦金融
/// </summary>
public const string GM_FN = "https://gm-plugin-fn.gachafun.com/";
}
public class Config public class Config
{ {
public static readonly string APP_NAME = "AI校对王"; public static readonly string APP_NAME = "AI校对王";
@ -23,15 +47,16 @@ namespace AIProofread
/// </summary> /// </summary>
public static readonly string TextBackgroundColor = "#E9DABB"; // e9dabb D6AA69 public static readonly string TextBackgroundColor = "#E9DABB"; // e9dabb D6AA69
public static string DeviceId = ""; public static string DeviceId = "";
#if DEBUG #if DEBUG
/// <summary> /// <summary>
/// 网页访问地址 /// 网页访问地址
/// </summary> /// </summary>
public static string WEB_PATH = "http://localhost:5173/"; //pre-gm-plugin.gachafun.com localhost:5173 gm2-plugin.zverse.group public static string WEB_PATH = AppServer.DEV; //pre-gm-plugin.gachafun.com localhost:5173 gm2-plugin.zverse.group
public static bool RUN_IN_DEBUG = true; public static bool RUN_IN_DEBUG = true;
public static AppEnvironment APP_ENV = AppEnvironment.Dev; public static AppEnvironment APP_ENV = AppEnvironment.Dev;
#else #else
public static string WEB_PATH = "https://gm-plugin.gachafun.com/"; // gm-plugin.gachafun.com pre-gm-plugin.gachafun.com public static string WEB_PATH = AppServer.PROD; // gm-plugin.gachafun.com pre-gm-plugin.gachafun.com
public static bool RUN_IN_DEBUG = false; public static bool RUN_IN_DEBUG = false;
public static AppEnvironment APP_ENV = AppEnvironment.Prod; public static AppEnvironment APP_ENV = AppEnvironment.Prod;
#endif #endif

View File

@ -55,6 +55,7 @@
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "FormCommonsenseDetection"; this.Name = "FormCommonsenseDetection";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "常识性检测";
this.Load += new System.EventHandler(this.FormCommonsenseDetection_Load); this.Load += new System.EventHandler(this.FormCommonsenseDetection_Load);
((System.ComponentModel.ISupportInitialize)(this.MainWebView)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.MainWebView)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);

View File

@ -1,8 +1,8 @@
using AIProofread.core; using AIProofread.core;
using Newtonsoft.Json; using Newtonsoft.Json;
using System; using System;
using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Threading;
using UtilLib; using UtilLib;
namespace AIProofread.Controls namespace AIProofread.Controls
@ -13,8 +13,7 @@ namespace AIProofread.Controls
{ {
private bool initialized = false; private bool initialized = false;
private string action; private List<WebMessage> actions = new List<WebMessage>();
private object data;
public FormCommonsenseDetection() public FormCommonsenseDetection()
{ {
@ -45,17 +44,24 @@ namespace AIProofread.Controls
return; return;
} }
// 添加到队列 // 添加到队列
this.action = action; actions.Add(new WebMessage(action, data));
this.data = data; //this.action = action;
//this.data = data;
} }
public void InitializationCompleted() public void InitializationCompleted()
{ {
if (!this.initialized && !string.IsNullOrEmpty(this.action)) if (!this.initialized && actions.Count > 0) // !string.IsNullOrEmpty(this.action)
{ {
SendToWeb(this.action, this.data); actions.ForEach(item =>
this.action = null; {
this.data = null; SendToWeb(item.Message, item.Data);
});
// clear
actions.Clear();
//SendToWeb(this.action, this.data);
//this.action = null;
//this.data = null;
} }
this.initialized = true; this.initialized = true;
} }

View File

@ -348,6 +348,9 @@ namespace AIProofread
ActiveDocument = documentList.SetActiveDocument(CurrentWordApplication.ActiveDocument); ActiveDocument = documentList.SetActiveDocument(CurrentWordApplication.ActiveDocument);
ActiveDocument.CheckBtnStatus(); ActiveDocument.CheckBtnStatus();
CheckDocumentClosed(null, null); CheckDocumentClosed(null, null);
if (formCommonsenseDetection != null) {
formCommonsenseDetection.SendMessageToWeb("document-change", null);
}
Logger.Log("Application_DocumentChange -- " + ActiveDocument.fileName); Logger.Log("Application_DocumentChange -- " + ActiveDocument.fileName);
} }

View File

@ -57,7 +57,6 @@ namespace AIProofread
// DocumentReader.ReadByVSTO(doc, Globals.ThisAddIn.Application, list); // DocumentReader.ReadByVSTO(doc, Globals.ThisAddIn.Application, list);
//} //}
} }
var map = new Dictionary<string, object> var map = new Dictionary<string, object>
{ {
{ "list", list }, { "list", list },
@ -79,7 +78,11 @@ namespace AIProofread
if (bodyElement is XWPFParagraph p) if (bodyElement is XWPFParagraph p)
{ {
// 处理普通段落 // 处理普通段落
list.Add(new DocumentText(p.ParagraphText.Replace("\u0002", ""), paragraphNumber)); var text = p.ParagraphText.Replace("\u0002", "");
if(text.Trim().Length > 0)
{
list.Add(new DocumentText(text, paragraphNumber));
}
paragraphNumber++; paragraphNumber++;
} }
// table -- vsto对于每个单元格的分段也会有 // table -- vsto对于每个单元格的分段也会有

View File

@ -35,24 +35,29 @@
this.panel1 = new System.Windows.Forms.Panel(); this.panel1 = new System.Windows.Forms.Panel();
this.IconClose = new System.Windows.Forms.PictureBox(); this.IconClose = new System.Windows.Forms.PictureBox();
this.label1 = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label();
this.panelLog = new System.Windows.Forms.Panel();
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.panel1.SuspendLayout(); this.panel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.IconClose)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.IconClose)).BeginInit();
this.panelLog.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
// LabelLog // LabelLog
// //
this.LabelLog.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.LabelLog.Font = new System.Drawing.Font("微软雅黑", 10F);
this.LabelLog.Location = new System.Drawing.Point(40, 57); this.LabelLog.Location = new System.Drawing.Point(2, 2);
this.LabelLog.MaximumSize = new System.Drawing.Size(296, 0);
this.LabelLog.MinimumSize = new System.Drawing.Size(296, 0);
this.LabelLog.Name = "LabelLog"; this.LabelLog.Name = "LabelLog";
this.LabelLog.Size = new System.Drawing.Size(300, 71); this.LabelLog.Size = new System.Drawing.Size(296, 21);
this.LabelLog.TabIndex = 0; this.LabelLog.TabIndex = 0;
this.LabelLog.Text = "正在检测。。。"; this.LabelLog.Text = "版本检测中 ...";
this.LabelLog.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.LabelLog.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.LabelLog.Click += new System.EventHandler(this.LabelLog_Click); this.LabelLog.Click += new System.EventHandler(this.LabelLog_Click);
// //
// progressBar1 // progressBar1
// //
this.progressBar1.Location = new System.Drawing.Point(40, 136); this.progressBar1.Location = new System.Drawing.Point(40, 180);
this.progressBar1.Name = "progressBar1"; this.progressBar1.Name = "progressBar1";
this.progressBar1.Size = new System.Drawing.Size(300, 14); this.progressBar1.Size = new System.Drawing.Size(300, 14);
this.progressBar1.TabIndex = 3; this.progressBar1.TabIndex = 3;
@ -64,7 +69,7 @@
this.ButtonProcess.DefaultBack = System.Drawing.Color.FromArgb(((int)(((byte)(201)))), ((int)(((byte)(160)))), ((int)(((byte)(99))))); this.ButtonProcess.DefaultBack = System.Drawing.Color.FromArgb(((int)(((byte)(201)))), ((int)(((byte)(160)))), ((int)(((byte)(99)))));
this.ButtonProcess.Font = new System.Drawing.Font("微软雅黑", 10F); this.ButtonProcess.Font = new System.Drawing.Font("微软雅黑", 10F);
this.ButtonProcess.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(255))))); this.ButtonProcess.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
this.ButtonProcess.Location = new System.Drawing.Point(122, 158); this.ButtonProcess.Location = new System.Drawing.Point(122, 202);
this.ButtonProcess.Name = "ButtonProcess"; this.ButtonProcess.Name = "ButtonProcess";
this.ButtonProcess.Radius = 4; this.ButtonProcess.Radius = 4;
this.ButtonProcess.Size = new System.Drawing.Size(136, 44); this.ButtonProcess.Size = new System.Drawing.Size(136, 44);
@ -107,19 +112,40 @@
this.label1.TabIndex = 0; this.label1.TabIndex = 0;
this.label1.Text = "温馨提示"; this.label1.Text = "温馨提示";
// //
// panelLog
//
this.panelLog.AutoScroll = true;
this.panelLog.Controls.Add(this.LabelLog);
this.panelLog.Location = new System.Drawing.Point(40, 58);
this.panelLog.Name = "panelLog";
this.panelLog.Size = new System.Drawing.Size(300, 114);
this.panelLog.TabIndex = 8;
//
// richTextBox1
//
this.richTextBox1.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.richTextBox1.Location = new System.Drawing.Point(237, 149);
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.ReadOnly = true;
this.richTextBox1.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.Vertical;
this.richTextBox1.Size = new System.Drawing.Size(100, 96);
this.richTextBox1.TabIndex = 9;
this.richTextBox1.Text = "";
//
// Form1 // Form1
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.White; this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(380, 216); this.ClientSize = new System.Drawing.Size(380, 260);
this.Controls.Add(this.richTextBox1);
this.Controls.Add(this.panelLog);
this.Controls.Add(this.panel1); this.Controls.Add(this.panel1);
this.Controls.Add(this.ButtonProcess); this.Controls.Add(this.ButtonProcess);
this.Controls.Add(this.progressBar1); this.Controls.Add(this.progressBar1);
this.Controls.Add(this.LabelLog);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false; this.MaximizeBox = false;
this.MaximumSize = new System.Drawing.Size(380, 216); this.MaximumSize = new System.Drawing.Size(380, 260);
this.MinimizeBox = false; this.MinimizeBox = false;
this.MinimumSize = new System.Drawing.Size(380, 216); this.MinimumSize = new System.Drawing.Size(380, 216);
this.Name = "Form1"; this.Name = "Form1";
@ -129,6 +155,7 @@
this.panel1.ResumeLayout(false); this.panel1.ResumeLayout(false);
this.panel1.PerformLayout(); this.panel1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.IconClose)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.IconClose)).EndInit();
this.panelLog.ResumeLayout(false);
this.ResumeLayout(false); this.ResumeLayout(false);
} }
@ -141,6 +168,8 @@
private System.Windows.Forms.PictureBox IconClose; private System.Windows.Forms.PictureBox IconClose;
private System.Windows.Forms.Panel panel1; private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label1;
private System.Windows.Forms.Panel panelLog;
private System.Windows.Forms.RichTextBox richTextBox1;
} }
} }

View File

@ -159,6 +159,7 @@ namespace updater
| SecurityProtocolType.Tls11 | SecurityProtocolType.Tls11
| SecurityProtocolType.Tls12; | SecurityProtocolType.Tls12;
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(UpgradeInfoURI + "api/v1/common/download/version"); HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(UpgradeInfoURI + "api/v1/common/download/version");
httpWebRequest.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true;
HttpWebResponse resp = (HttpWebResponse)httpWebRequest.GetResponse(); HttpWebResponse resp = (HttpWebResponse)httpWebRequest.GetResponse();
// 获取响应内容 // 获取响应内容
if (resp.StatusCode == HttpStatusCode.OK) if (resp.StatusCode == HttpStatusCode.OK)
@ -174,18 +175,27 @@ namespace updater
resp.Close(); resp.Close();
UpgradeModel update = JsonConvert.DeserializeObject<UpgradeModel>(updateSource); UpgradeModel update = JsonConvert.DeserializeObject<UpgradeModel>(updateSource);
ProcessUpdate(update); ProcessUpdate(update);
return;
} }
} }
catch (Exception) catch (Exception)
{ {
LabelLog.Text = "获取更新信息失败,请稍后重试";
} }
LabelLog.Text = "获取更新信息失败,请稍后重试";
} }
private void ProcessUpdate(UpgradeModel update) private void ProcessUpdate(UpgradeModel update)
{ {
this.upgradeInfo = update.Info; this.upgradeInfo = update.Info;
LabelLog.Text = update.Info.Message; //richTextBox1.Text
richTextBox1.Text = update.Info.Message
+ @"Com加载项勾选
office或wps的版本
Com加载项勾选
windowS10或11wps在安装插件";
if (localVersion == null || update.Info.NeedUpgrade(localVersion.Version)) if (localVersion == null || update.Info.NeedUpgrade(localVersion.Version))
{ {