更新常识检测

This commit is contained in:
LittleBoy 2025-01-02 17:07:50 +08:00
parent f1ddfa3d65
commit 41bfe9c5a3
8 changed files with 47 additions and 11 deletions

Binary file not shown.

View File

@ -103,7 +103,7 @@ namespace AIProofread
start = currectSelectRange.Paragraphs.First.Range.Start;
end = currectSelectRange.Paragraphs.Last.Range.End;
}
var data = JSONObject.Create().AddField("start", start).AddField("end", end).ToString();
var data = JSONObject.Create().Put("start", start).Put("end", end).ToString();
Globals.ThisAddIn.formCommonsenseDetection.SendMessageToWeb("detect-range", data);
}
public void SendNoticeToShowCheckHistory()
@ -384,7 +384,27 @@ namespace AIProofread
}
public string GetTextByRange(int start, int end)
{
return Globals.ThisAddIn.ActiveDocument.GetRangeText(start, end);
var range = Globals.ThisAddIn.ActiveDocument.Range(start, end);
if (range == null)
{
return JSONObject.Create()
.Put("text", null)
.Put("page", -1)
.Put("line", -1)
.ToString();
}
var text = Globals.ThisAddIn.ActiveDocument.GetRangeText(range);
// 获取书签在文档的页码数
var pageNumber = range.get_Information(WdInformation.wdActiveEndPageNumber);
// 获取书签在当前页面的行数
var lineNumber = range.get_Information(WdInformation.wdFirstCharacterLineNumber);
return JSONObject.Create()
.Put("text",text)
.Put("page", pageNumber)
.Put("line", lineNumber)
.ToString();
}
/// <summary>
/// 获取文档所有段落文本

View File

@ -41,7 +41,7 @@
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.Size = new System.Drawing.Size(800, 600);
this.MainWebView.TabIndex = 0;
this.MainWebView.ZoomFactor = 1D;
//
@ -49,9 +49,10 @@
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(700, 600);
this.ClientSize = new System.Drawing.Size(800, 600);
this.Controls.Add(this.MainWebView);
this.Name = "FormCommonsenseDetection";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "FormCommonsenseDetection";
this.Load += new System.EventHandler(this.FormCommonsenseDetection_Load);
((System.ComponentModel.ISupportInitialize)(this.MainWebView)).EndInit();

View File

@ -21,6 +21,10 @@ namespace AIProofread.Model
public CommonsenseDetectionType Type { get; set; }
[JsonProperty("summary")]
public string Summary { get; set; }
[JsonProperty("location")]
public string Location { get; set; }
[JsonProperty("result_content")]
public string ResultContent { get; set; }
}

View File

@ -356,6 +356,12 @@ namespace AIProofread.Model
return GetRangeText(CurrentDocument.Range(start, end));
}
public Range Range(int start, int end)
{
if (start >= end) return null;
return CurrentDocument.Range(start, end);
}
/// <summary>
/// 保存校对缓存结果
/// </summary>

View File

@ -575,7 +575,7 @@ namespace AIProofread
// 获取当前选中的选区的首尾段落起始与结束位置
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();
var data = JSONObject.Create().Put("start", start).Put("end", end).ToString();
Globals.ThisAddIn.SendMessageToWeb("show-check-range", data);
}
@ -592,8 +592,13 @@ namespace AIProofread
public void ParseSelectionChange(Selection s)
{
var r = s.Range;
btnDetectionParagraph.Enabled = r.Start != r.End;
this.currectSelectRange = r;
if (CommonSenseDetection.instance.isChecking)
{
return;
}
btnDetectionParagraph.Enabled = r.Start != r.End;
btnDetectionAll.Enabled = r.Start == r.End;
}
public void SetDetectionBtnStatus(bool status)

View File

@ -21,7 +21,7 @@ namespace AIProofread.core
private List<CommonsenseDetectionItem> history = new List<CommonsenseDetectionItem>();
// 生成单例
private static readonly CommonSenseDetection instance = new CommonSenseDetection();
public static readonly CommonSenseDetection instance = new CommonSenseDetection();
private FormCommonsenseDetection formCommonsenseDetection;
private CommonSenseDetection() { }
@ -48,9 +48,9 @@ namespace AIProofread.core
public string GetCheckStatus()
{
return JSONObject.Create()
.AddField("isChecking", isChecking)
.AddField("checkingKey", checkingKey)
.AddField("checkingSummary", checkingSummary)
.Put("isChecking", isChecking)
.Put("checkingKey", checkingKey)
.Put("checkingSummary", checkingSummary)
.ToString();
}

View File

@ -21,7 +21,7 @@ namespace AIProofread.core
return obj;
}
public JSONObject AddField(string key, object value)
public JSONObject Put(string key, object value)
{
m_Dict.Add(key, value);
return this;