feat: 新增文章常识性检测

This commit is contained in:
LittleBoy 2024-12-31 10:50:52 +08:00
parent b3b931e89f
commit f7f9fdf5d3
27 changed files with 646 additions and 39 deletions

Binary file not shown.

View File

@ -284,6 +284,12 @@
<Compile Include="Controls\BaseWinForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Controls\FormCommonsenseDetection.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Controls\FormCommonsenseDetection.Designer.cs">
<DependentUpon>FormCommonsenseDetection.cs</DependentUpon>
</Compile>
<Compile Include="Controls\FormContact.cs">
<SubType>Form</SubType>
</Compile>
@ -357,18 +363,21 @@
<DependentUpon>ProofreadMainControl.cs</DependentUpon>
</Compile>
<Compile Include="core\BridgeResult.cs" />
<Compile Include="core\CommonSenseDetection.cs" />
<Compile Include="core\CorrectionCharacter.cs" />
<Compile Include="core\CorrectionFragmentAbstract.cs" />
<Compile Include="core\CorrectionRangeAbstract.cs" />
<Compile Include="core\DocumentText.cs" />
<Compile Include="core\DocumentUtil.cs" />
<Compile Include="core\EventForwarder.cs" />
<Compile Include="core\JSONObject.cs" />
<Compile Include="core\StringUtil.cs" />
<Compile Include="core\Tools.cs" />
<Compile Include="core\MainPanelWebMessage.cs" />
<Compile Include="core\ExportConfig.cs" />
<Compile Include="Logger.cs" />
<Compile Include="Model\BridgeResult.cs" />
<Compile Include="Model\CommonsenseDetectionItem.cs" />
<Compile Include="Model\DocumentContent.cs" />
<Compile Include="Model\DocumentInfo.cs" />
<Compile Include="Model\DocumentList.cs" />
@ -382,6 +391,9 @@
<Compile Include="Util\HostHelper.cs" />
<Compile Include="Util\HttpUtil.cs" />
<Compile Include="Util\User32Util.cs" />
<EmbeddedResource Include="Controls\FormCommonsenseDetection.resx">
<DependentUpon>FormCommonsenseDetection.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Controls\FormContact.resx">
<DependentUpon>FormContact.cs</DependentUpon>
</EmbeddedResource>
@ -524,6 +536,12 @@
<ItemGroup>
<None Include="Resources\logo_no_text_wps.jpg" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\icon-ai-robot.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\icon-ai-robot-wps.jpg" />
</ItemGroup>
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>

View File

@ -345,14 +345,23 @@ namespace AIProofread
/// <summary>
/// 根据位置获取文档区域文本
/// </summary>
/// <param name="start"></param>
/// <param name="end"></param>
/// <param name="start">开始段落数</param>
/// <param name="end">数据段落书</param>
/// <returns></returns>
public string getParagraphTextByRange(int start, int end)
{
var list = Tools.GetTextListByParagraphRange(start, end);
return Tools.GetJSONString(list);
}
public string GetDocumentAllText()
{
return Globals.ThisAddIn.ActiveDocument.GetAllText();
}
public string GetTextByRange(int start, int end)
{
return Globals.ThisAddIn.ActiveDocument.GetRangeText(start, end);
}
/// <summary>
/// 获取文档所有段落文本
/// </summary>

View File

@ -110,7 +110,7 @@ namespace AIProofread.Controls
this.FormBorderStyle = FormBorderStyle.None;
}
protected async void InitWebView(WebView2 webView,String url,string name)
protected async void InitWebView(WebView2 webView,String url,string name,Action callaback = null)
{
//Bridge.InitWebEnvAsync(name, webView);
try
@ -124,6 +124,10 @@ namespace AIProofread.Controls
var eventForwarder = new EventForwarder(this);
webView.CoreWebView2.AddHostObjectToScript("event", eventForwarder);
webView.CoreWebView2.AddHostObjectToScript("bridge", Bridge.bridge);
if(callaback != null)
{
callaback();
}
webView.Source = new Uri(url);
}catch (Exception ex)

View File

@ -0,0 +1,66 @@
namespace AIProofread.Controls
{
partial class FormCommonsenseDetection
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.MainWebView = new Microsoft.Web.WebView2.WinForms.WebView2();
((System.ComponentModel.ISupportInitialize)(this.MainWebView)).BeginInit();
this.SuspendLayout();
//
// MainWebView
//
this.MainWebView.AllowExternalDrop = false;
this.MainWebView.BackColor = System.Drawing.SystemColors.ControlDark;
this.MainWebView.CreationProperties = null;
this.MainWebView.DefaultBackgroundColor = System.Drawing.Color.White;
this.MainWebView.Dock = System.Windows.Forms.DockStyle.Fill;
this.MainWebView.Location = new System.Drawing.Point(0, 0);
this.MainWebView.Name = "MainWebView";
this.MainWebView.Size = new System.Drawing.Size(700, 600);
this.MainWebView.TabIndex = 0;
this.MainWebView.ZoomFactor = 1D;
//
// FormCommonsenseDetection
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(700, 600);
this.Controls.Add(this.MainWebView);
this.Name = "FormCommonsenseDetection";
this.Text = "FormCommonsenseDetection";
this.Load += new System.EventHandler(this.FormCommonsenseDetection_Load);
((System.ComponentModel.ISupportInitialize)(this.MainWebView)).EndInit();
this.ResumeLayout(false);
}
#endregion
private Microsoft.Web.WebView2.WinForms.WebView2 MainWebView;
}
}

View File

@ -0,0 +1,63 @@
using AIProofread.core;
using Newtonsoft.Json;
using System;
using System.Runtime.InteropServices;
using System.Threading;
using UtilLib;
namespace AIProofread.Controls
{
[ClassInterface(ClassInterfaceType.AutoDual)]
[ComVisible(true)]
public partial class FormCommonsenseDetection : BaseWinForm
{
private bool initialized = false;
private string action;
private object data;
public FormCommonsenseDetection()
{
InitializeComponent();
}
private void FormCommonsenseDetection_Load(object sender, EventArgs e)
{
// 初始化
InitWebView(MainWebView, Config.WebPath("commonsense-detection"), "commonsense-detection", () =>
{
MainWebView.CoreWebView2.AddHostObjectToScript("detection", CommonSenseDetection.Instance(this));
});
}
private void SendToWeb(string action, object data)
{
var json = JsonConvert.SerializeObject(new WebMessage(action, data));
MainWebView.CoreWebView2.PostWebMessageAsJson(json);
}
public void SendMessageToWeb(string action, object data)
{
// 判断是否已经初始化完成
if (this.initialized)
{
SendToWeb(action, data);
return;
}
// 添加到队列
this.action = action;
this.data = data;
}
public void InitializationCompleted()
{
if (!this.initialized && !string.IsNullOrEmpty(this.action))
{
SendToWeb(this.action, this.data);
this.action = null;
this.data = null;
}
this.initialized = true;
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,27 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AIProofread.Model
{
public enum CommonsenseDetectionType
{
All = 1,
Paragraph = 2
}
public class CommonsenseDetectionItem
{
[JsonProperty("id")]
public int Id { get; set; }
[JsonProperty("type")]
public CommonsenseDetectionType Type { get; set; }
[JsonProperty("summary")]
public string Summary { get; set; }
[JsonProperty("result_content")]
public string ResultContent { get; set; }
}
}

View File

@ -115,10 +115,11 @@ namespace AIProofread.Model
FormMessage.ShowMessage(message, confirmText, confirmAction);
}));
}
public FormMessage ShowMessage(string message, int closeDelay,bool showCloseBtn = true)
public FormMessage ShowMessage(string message, int closeDelay, bool showCloseBtn = true)
{
var msgForm = FormMessage.ShowMessage(message, closeDelay);
if(closeDelay > 0){
if (closeDelay > 0)
{
if (!showCloseBtn)
{
@ -317,7 +318,7 @@ namespace AIProofread.Model
}
// 获取当前文档文本
public string GetText()
public string GetAllText()
{
return CurrentDocument.Range().Text;
}
@ -328,7 +329,9 @@ namespace AIProofread.Model
/// <returns></returns>
public string GetSelectedText()
{
return CurrentDocument.Range().Text;
// 获取当前文档的选区
var selection = Globals.ThisAddIn.Application.Selection;
return selection.Text;
}
/// <summary>
@ -341,6 +344,17 @@ namespace AIProofread.Model
string text = range?.Text;
return string.IsNullOrEmpty(text) ? "" : text;
}
/// <summary>
/// 获取指定选区的文本
/// </summary>
/// <param name="start"></param>
/// <param name="end"></param>
/// <returns></returns>
public string GetRangeText(int start, int end)
{
if (start >= end) return null;
return GetRangeText(CurrentDocument.Range(start, end));
}
/// <summary>
/// 保存校对缓存结果

View File

@ -100,6 +100,26 @@ namespace AIProofread.Properties {
}
}
/// <summary>
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
/// </summary>
internal static System.Drawing.Bitmap icon_ai_robot {
get {
object obj = ResourceManager.GetObject("icon-ai-robot", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
/// </summary>
internal static System.Drawing.Bitmap icon_ai_robot_wps {
get {
object obj = ResourceManager.GetObject("icon-ai-robot-wps", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
/// </summary>

View File

@ -118,6 +118,9 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="button" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\button.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="icon-setting-wps" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icon-setting-wps.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
@ -130,11 +133,8 @@
<data name="icon-proofread-wps" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icon-proofread-wps.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="button" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\button.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="icon-proofread" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icon-proofread.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
<data name="icon-history" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icon-history.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="icon-phone" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icon-phone.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
@ -181,11 +181,8 @@
<data name="icon-refresh-wps" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icon-refresh-wps.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="icon-export" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icon-export.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="icon-history" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icon-history.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
<data name="icon-clear" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icon-clear.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="button_default" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\button_default.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
@ -196,11 +193,14 @@
<data name="icon-refresh" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icon-refresh.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="logo_no_text" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\logo_no_text.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="logo_wps" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\logo_wps.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="icon-clear" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icon-clear.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
<data name="icon-export" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icon-export.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="icon-phone-wps" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icon-phone-wps.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
@ -208,19 +208,25 @@
<data name="icon-history-wps" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icon-history-wps.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="icon-panel" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icon-panel.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="logo_no_text_wps" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\logo_no_text_wps.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="icon-logout" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icon-logout.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="icon_close" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icon_close.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="icon-panel" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icon-panel.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
<data name="icon-proofread" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icon-proofread.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="logo_no_text" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\logo_no_text.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
<data name="icon-ai-robot" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icon-ai-robot.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="logo_no_text_wps" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\logo_no_text_wps.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
<data name="icon-ai-robot-wps" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icon-ai-robot-wps.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

View File

@ -45,6 +45,10 @@ namespace AIProofread
this.BtnExportProofreadResult = this.Factory.CreateRibbonButton();
this.btnClear = this.Factory.CreateRibbonButton();
this.btnOpenLexicon = this.Factory.CreateRibbonButton();
this.menuSencenDect = this.Factory.CreateRibbonMenu();
this.btnDetectionAll = this.Factory.CreateRibbonButton();
this.btnDetectionParagraph = this.Factory.CreateRibbonButton();
this.btnDetectionHistory = this.Factory.CreateRibbonButton();
this.btnSetting = this.Factory.CreateRibbonButton();
this.Group = this.Factory.CreateRibbonGroup();
this.ButtonSaveCache = this.Factory.CreateRibbonButton();
@ -93,6 +97,7 @@ namespace AIProofread
this.group1.Items.Add(this.BtnExportProofreadResult);
this.group1.Items.Add(this.btnClear);
this.group1.Items.Add(this.btnOpenLexicon);
this.group1.Items.Add(this.menuSencenDect);
this.group1.Items.Add(this.btnSetting);
this.group1.Name = "group1";
//
@ -132,6 +137,39 @@ namespace AIProofread
this.btnOpenLexicon.ShowImage = true;
this.btnOpenLexicon.Click += new Microsoft.Office.Tools.Ribbon.RibbonControlEventHandler(this.btnOpenLexicon_Click);
//
// menuSencenDect
//
this.menuSencenDect.ControlSize = Microsoft.Office.Core.RibbonControlSize.RibbonControlSizeLarge;
this.menuSencenDect.Image = global::AIProofread.Properties.Resources.icon_ai_robot;
this.menuSencenDect.Items.Add(this.btnDetectionAll);
this.menuSencenDect.Items.Add(this.btnDetectionParagraph);
this.menuSencenDect.Items.Add(this.btnDetectionHistory);
this.menuSencenDect.Label = "校对助手\r\n";
this.menuSencenDect.Name = "menuSencenDect";
this.menuSencenDect.ShowImage = true;
//
// btnDetectionAll
//
this.btnDetectionAll.Label = "全文常识检测\r\n";
this.btnDetectionAll.Name = "btnDetectionAll";
this.btnDetectionAll.ShowImage = true;
this.btnDetectionAll.Click += new Microsoft.Office.Tools.Ribbon.RibbonControlEventHandler(this.btnDetectionAll_Click);
//
// btnDetectionParagraph
//
this.btnDetectionParagraph.Enabled = false;
this.btnDetectionParagraph.Label = "段落常识检测\r\n";
this.btnDetectionParagraph.Name = "btnDetectionParagraph";
this.btnDetectionParagraph.ShowImage = true;
this.btnDetectionParagraph.Click += new Microsoft.Office.Tools.Ribbon.RibbonControlEventHandler(this.btnDetectionParagraph_Click);
//
// btnDetectionHistory
//
this.btnDetectionHistory.Label = "历史检测记录\r\n";
this.btnDetectionHistory.Name = "btnDetectionHistory";
this.btnDetectionHistory.ShowImage = true;
this.btnDetectionHistory.Click += new Microsoft.Office.Tools.Ribbon.RibbonControlEventHandler(this.btnDetectionHistory_Click);
//
// btnSetting
//
this.btnSetting.ControlSize = Microsoft.Office.Core.RibbonControlSize.RibbonControlSizeLarge;
@ -365,6 +403,10 @@ namespace AIProofread
internal Microsoft.Office.Tools.Ribbon.RibbonButton BtnShowVersion;
internal Microsoft.Office.Tools.Ribbon.RibbonDropDown dropDown1;
internal Microsoft.Office.Tools.Ribbon.RibbonGroup grpOther;
internal Microsoft.Office.Tools.Ribbon.RibbonMenu menuSencenDect;
internal Microsoft.Office.Tools.Ribbon.RibbonButton btnDetectionAll;
internal Microsoft.Office.Tools.Ribbon.RibbonButton btnDetectionParagraph;
internal Microsoft.Office.Tools.Ribbon.RibbonButton btnDetectionHistory;
}
partial class ThisRibbonCollection

View File

@ -51,6 +51,7 @@ namespace AIProofread
btnLogout.Enabled = status;
ButtonLoadCache.Enabled = status;
ButtonSaveCache.Enabled = status;
menuSencenDect.Enabled = status;
//BtnShowPanel.Enabled = status;
BtnExportProofreadResult.Enabled = status;
}
@ -85,6 +86,7 @@ namespace AIProofread
BtnGetContact.Image = AIProofread.Properties.Resources.icon_phone_wps;
BtnUpdate.Image = AIProofread.Properties.Resources.icon_update_wps;
btnLogin.Image = AIProofread.Properties.Resources.icon_user_wps;
menuSencenDect.Image = AIProofread.Properties.Resources.icon_ai_robot_wps;
btnLogout.Image = AIProofread.Properties.Resources.icon_logout_wps;
// 缓存相关
ButtonLoadCache.Image = AIProofread.Properties.Resources.icon_refresh_wps;
@ -480,21 +482,9 @@ namespace AIProofread
Logger.LoggerForm.Show();
}
private void BtnTest_Click(object sender, RibbonControlEventArgs e)
private int GetRangeParagraphNumber(Range range)
{
// 获取当前系统时间戳
//int time = (int)(DateTime.Now.Ticks / 10000000);
//BtnTest.Label = "测试按钮" + time;
//var result = MessageBox.Show("Test", "xxx");
//Globals.ThisAddIn.Application.
var app = Globals.ThisAddIn.Application;
var selection = app.Selection;
var range = selection.Range;
// 获取所在页
var pageNumber = GetIndexPageNumber(range);
// 获取所在行
var rowNumber = range.get_Information(WdInformation.wdFirstCharacterLineNumber);
int paragraphNumber = 0;
if (range.Paragraphs.Count > 0)
{
@ -517,6 +507,26 @@ namespace AIProofread
}
}
}
return paragraphNumber;
}
private void BtnTest_Click(object sender, RibbonControlEventArgs e)
{
// 获取当前系统时间戳
//int time = (int)(DateTime.Now.Ticks / 10000000);
//BtnTest.Label = "测试按钮" + time;
//var result = MessageBox.Show("Test", "xxx");
//Globals.ThisAddIn.Application.
var app = Globals.ThisAddIn.Application;
var selection = app.Selection;
var range = selection.Range;
// 获取所在页
var pageNumber = GetIndexPageNumber(range);
// 获取所在行
var rowNumber = range.get_Information(WdInformation.wdFirstCharacterLineNumber);
int paragraphNumber = GetRangeParagraphNumber(range);
MessageBox.Show($"当前页:{pageNumber}, 行:{rowNumber}, 段落:{paragraphNumber}");
}
@ -552,5 +562,46 @@ namespace AIProofread
{
Globals.ThisAddIn.SendMessageToWeb("show-version", "");
}
public Range currectSelectRange;
private void btnDetectionAll_Click(object sender, RibbonControlEventArgs e)
{
Globals.ThisAddIn.ShowDetection();
Globals.ThisAddIn.formCommonsenseDetection.SendMessageToWeb("detect-all", null);
}
private void btnDetectionParagraph_Click(object sender, RibbonControlEventArgs e)
{
Globals.ThisAddIn.ShowDetection();
// 获取当前选中的选区的首尾段落起始与结束位置
var start = currectSelectRange.Paragraphs.First.Range.Start;
var end = currectSelectRange.Paragraphs.Last.Range.End;
var data = JSONObject.Create().AddField("start",start).AddField("end",end).ToString();
Globals.ThisAddIn.formCommonsenseDetection.SendMessageToWeb("detect-range", data);
}
private void btnDetectionHistory_Click(object sender, RibbonControlEventArgs e)
{
Globals.ThisAddIn.ShowDetection();
Globals.ThisAddIn.formCommonsenseDetection.SendMessageToWeb("show-history", null);
}
/// <summary>
/// 存储当前选区
/// </summary>
/// <param name="s"></param>
public void ParseSelectionChange(Selection s)
{
var r = s.Range;
btnDetectionParagraph.Enabled = r.Start != r.End;
this.currectSelectRange = r;
}
public void SetDetectionBtnStatus(bool status)
{
btnDetectionAll.Enabled = status;
btnDetectionParagraph.Enabled = status;
}
}
}

View File

@ -58,6 +58,10 @@ namespace AIProofread
/// 当前文档信息
/// </summary>
public DocumentInfo ActiveDocument { get; set; }
/// <summary>
/// 智能常识检测对话框 = new FormCommonsenseDetection()
/// </summary>
public FormCommonsenseDetection formCommonsenseDetection;
public bool IsWPS { get; set; }
public List<FormLogin> LoginFormList = new List<FormLogin>();
@ -71,6 +75,23 @@ namespace AIProofread
// CurrentWordApplication.DocumentChange += CurrentWordApplication_DocumentChange;
//}
public void ShowDetection()
{
if (formCommonsenseDetection == null)
{
formCommonsenseDetection = new FormCommonsenseDetection();
}
//formCommonsenseDetection.ShowInTaskbar = true;
formCommonsenseDetection.Show();
}
public void HideDetection()
{
formCommonsenseDetection.Close();
formCommonsenseDetection = null;
}
private void ProcessApplicationException(object sender,UnhandledExceptionEventArgs e)
{
Logger.Log("UnhandledException",e.ExceptionObject as Exception);
@ -86,6 +107,9 @@ namespace AIProofread
try
{
AppInitialize();
//formCommonsenseDetection.ShowInTaskbar = false;
//formCommonsenseDetection.Show();
Logger.Log("ThisAddIn_Startup IS_WPS --> " + IsWPS);
// 捕获全局异常
AppDomain.CurrentDomain.UnhandledException += ProcessApplicationException;
@ -381,6 +405,8 @@ namespace AIProofread
private void Application_WindowSelectionChange(Selection s)
{
ribbon.ParseSelectionChange(s);
if (s.Bookmarks != null)
{
if (s.Range.Start == s.Range.End) // 说明是点击呀

View File

@ -0,0 +1,100 @@
using AIProofread.Controls;
using AIProofread.Model;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace AIProofread.core
{
/// <summary>
/// 常识性检测数据
/// </summary>
[ClassInterface(ClassInterfaceType.AutoDual)]
[ComVisible(true)]
public class CommonSenseDetection
{
/// <summary>
/// 检测历史
/// </summary>
//public static readonly Dictionary<int, List<CommonsenseDetectionItem>> histories = new Dictionary<int, List<CommonsenseDetectionItem>>();
// 暂时改成全局
private List<CommonsenseDetectionItem> history = new List<CommonsenseDetectionItem>();
// 生成单例
private static readonly CommonSenseDetection instance = new CommonSenseDetection();
private FormCommonsenseDetection formCommonsenseDetection;
private CommonSenseDetection() { }
public static CommonSenseDetection Instance(FormCommonsenseDetection handler)
{
instance.formCommonsenseDetection = handler;
return instance;
}
public void WebInitializationCompleted()
{
if (formCommonsenseDetection != null && !formCommonsenseDetection.IsDisposed)
{
formCommonsenseDetection.InitializationCompleted();
}
}
// 检测状态
public bool isChecking = false;
public string checkingSummary;
public string checkingKey;
public string GetCheckStatus()
{
return JSONObject.Create()
.AddField("isChecking", isChecking)
.AddField("checkingKey", checkingKey)
.AddField("checkingSummary", checkingSummary)
.ToString();
}
public void SetCheckingData(bool isChecking, string checkingKey, string checkingSummary)
{
if (isChecking)
{
this.isChecking = isChecking;
this.checkingKey = checkingKey;
this.checkingSummary = checkingSummary;
Globals.ThisAddIn.ribbon.SetDetectionBtnStatus(false);
}
else
{
this.isChecking = false;
this.checkingKey = null;
this.checkingSummary = null;
Globals.ThisAddIn.ribbon.SetDetectionBtnStatus(true);
}
}
public string GetHistory()
{
//int id = Globals.ThisAddIn.ActiveDocument.Id;
return JsonConvert.SerializeObject(history);// histories.ContainsKey(id) ? JsonConvert.SerializeObject(histories[id]) : "[]";
}
public void SetHistory(string json)
{
var item = JsonConvert.DeserializeObject<CommonsenseDetectionItem>(json);
history.Add(item);
//int id = Globals.ThisAddIn.ActiveDocument.Id;
//if (histories.ContainsKey(id))
//{
// histories.Add(id, new List<CommonsenseDetectionItem>() { item });
//}
//else
//{
// histories[id].Add(item);
//}
}
public void Close()
{
Globals.ThisAddIn.HideDetection();
}
}
}

View File

@ -0,0 +1,40 @@
using Microsoft.Office.Interop.Word;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
namespace AIProofread.core
{
[Serializable]
public class JSONObject
{
private Dictionary<string, object> m_Dict = new Dictionary<string, object>();
private JSONObject()
{
}
public static JSONObject Create()
{
JSONObject obj = new JSONObject();
return obj;
}
public JSONObject AddField(string key, object value)
{
m_Dict.Add(key, value);
return this;
}
public override string ToString()
{
return ToJSONString();
}
public string ToJSONString()
{
return Tools.GetJSONString(m_Dict);
}
}
}

View File

@ -1 +1 @@
0ffc09f3eb798c1989429f7c2b6c0220e93f9976a035c03b8478b5bf94f1b55c
80a1b62e50022f6927ea33d64c401a80d068064724a07da1ca8562102f036978

View File

@ -215,3 +215,4 @@ C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread.
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\AIProofread.dll.config
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\AntdUI.dll
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\bin\Debug\AntdUI.xml
C:\Users\yaclt\source\repos\repos\AIProofread\AIProofread\obj\Debug\AIProofread.Controls.FormCommonsenseDetection.resources