优化多文档校对性能;
修复多文档同时校对时有几率数据错乱的问题;
This commit is contained in:
parent
93b46c16bf
commit
d2e960243c
Binary file not shown.
@ -83,16 +83,41 @@ namespace AIProofread
|
||||
|
||||
public void SetCurrentDocumentId(int id)
|
||||
{
|
||||
var doc = Globals.ThisAddIn.Application.ActiveDocument;
|
||||
Globals.ThisAddIn.documentIdDics[doc] = id;
|
||||
SetDocumentId(id, Globals.ThisAddIn.Application.ActiveDocument);
|
||||
}
|
||||
|
||||
|
||||
public void SetDocumentId(int id, Document document)
|
||||
{
|
||||
Globals.ThisAddIn.documentIdDics[document] = id;
|
||||
}
|
||||
public Document GetDocumentById(int id)
|
||||
{
|
||||
//return GeIdBytDocument(Globals.ThisAddIn.Application.ActiveDocument);
|
||||
var documentDic = Globals.ThisAddIn.documentIdDics;
|
||||
foreach (var doc in documentDic.Keys)
|
||||
{
|
||||
if (documentDic[doc] == id) return doc;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public int GetCurrentDocumentId()
|
||||
{
|
||||
var doc = Globals.ThisAddIn.Application.ActiveDocument;
|
||||
var dics = Globals.ThisAddIn.documentIdDics;
|
||||
return dics.ContainsKey(doc) ? dics[doc] : 0;
|
||||
return GeIdBytDocument(Globals.ThisAddIn.Application.ActiveDocument);
|
||||
}
|
||||
|
||||
public int GeIdBytDocument(Document document)
|
||||
{
|
||||
if (Globals.ThisAddIn.documentIdDics.ContainsKey(document))
|
||||
{
|
||||
return Globals.ThisAddIn.documentIdDics[document];
|
||||
}
|
||||
//int id = Globals.ThisAddIn.documentIdDics.Count + 1;
|
||||
//// 设置文档编号
|
||||
//SetCurrentDocumentId((int)id);
|
||||
//return id ;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 打开网页
|
||||
@ -162,6 +187,7 @@ namespace AIProofread
|
||||
var doc = Globals.ThisAddIn.Application.ActiveDocument;
|
||||
data.Add("name", doc.Name);
|
||||
data.Add("fullName", doc.FullName);
|
||||
//data.Add("documentId", GeIdBytDocument(doc));
|
||||
data.Add("wordsCount", doc.Words.Count);
|
||||
data.Add("charactersCount", doc.Characters.Count);
|
||||
data.Add("content", Tools.GetAllText(doc));
|
||||
@ -310,10 +336,10 @@ namespace AIProofread
|
||||
|
||||
|
||||
// 清除所有标记
|
||||
public void clearAllProofreadMark()
|
||||
public void clearAllProofreadMark(Document document)
|
||||
{
|
||||
// 标记当前文档所有书签数据
|
||||
Globals.ThisAddIn.ActiveCurrentDocumentMarks();
|
||||
Globals.ThisAddIn.ActiveCurrentDocumentMarks(document);
|
||||
try
|
||||
{
|
||||
selectProofreadId = -1;
|
||||
@ -346,13 +372,13 @@ namespace AIProofread
|
||||
{
|
||||
DocumentUtil.RemoveBookmark(markId);
|
||||
}
|
||||
public void addBookmark(string data)
|
||||
{
|
||||
var item = JsonConvert.DeserializeObject<CorrectedContent>(data);
|
||||
//var mark = DocumentUtil.AddBookmark(item.color, item.start, item.end);
|
||||
// 初始化校对对象
|
||||
marks.Add(item.id, new ProofreadItem(item));
|
||||
}
|
||||
//public void addBookmark(string data)
|
||||
//{
|
||||
// var item = JsonConvert.DeserializeObject<CorrectedContent>(data);
|
||||
// //var mark = DocumentUtil.AddBookmark(item.color, item.start, item.end);
|
||||
// // 初始化校对对象
|
||||
// marks.Add(item.id, new ProofreadItem(item));
|
||||
//}
|
||||
|
||||
public string getAllBookmark()
|
||||
{
|
||||
@ -470,14 +496,14 @@ namespace AIProofread
|
||||
rng.Select();
|
||||
}
|
||||
|
||||
public void SelectMarkById(int proofreadId)
|
||||
public void SelectMarkById(int proofreadId,int documentId)
|
||||
{
|
||||
|
||||
var doc = documentId < 1 ? Globals.ThisAddIn.Application.ActiveDocument : GetDocumentById(documentId);
|
||||
//
|
||||
// 设置当前文档数据
|
||||
Globals.ThisAddIn.ActiveCurrentDocumentMarks();
|
||||
Globals.ThisAddIn.ActiveCurrentDocumentMarks(doc);
|
||||
|
||||
if (proofreadId == selectProofreadId) return;
|
||||
var doc = Globals.ThisAddIn.Application.ActiveDocument;
|
||||
// 取消上一个标签移除
|
||||
if (selectProofreadId > 0 && marks.ContainsKey(selectProofreadId))
|
||||
{
|
||||
@ -540,34 +566,51 @@ namespace AIProofread
|
||||
}
|
||||
}
|
||||
|
||||
public string InitContent(string content)
|
||||
public string InitContent(string content,int documentId)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 根据文档编号 获取当前文档避免数据混乱
|
||||
CurrentDocument = GetDocumentById(documentId);
|
||||
if(CurrentDocument == null)
|
||||
{
|
||||
throw new Exception("没有找到校对文档对象");
|
||||
}
|
||||
List<DocumentCorrectItem> list = JsonConvert.DeserializeObject<List<DocumentCorrectItem>>(content);
|
||||
|
||||
// 先清除所有数据
|
||||
clearAllProofreadMark();
|
||||
clearAllProofreadMark(CurrentDocument);
|
||||
|
||||
//var app = Globals.ThisAddIn.Application;
|
||||
//var cur = app.Selection;
|
||||
//
|
||||
var prevOffset = 0;
|
||||
List<int> disabledList = new List<int>();
|
||||
foreach (var correct in list)
|
||||
{
|
||||
if (correct.Diffs != null && correct.Diffs.Count > 0)
|
||||
{
|
||||
prevOffset = 0;
|
||||
int index = 0;
|
||||
foreach (var item in correct.Diffs)
|
||||
{
|
||||
if(item.id == 187117)
|
||||
if (item.id == 187095)
|
||||
{
|
||||
Console.WriteLine("xx");
|
||||
}
|
||||
var mark = FindRangeAndCreateBookmark(correct.Insert, item, index, correct.Sentence_offset, correct.Insert_len, correct.Paragraph_num);
|
||||
int _prev = prevOffset;
|
||||
// 查找对应区域并再该区域添加书签
|
||||
var mark = FindRangeAndCreateBookmark(item, correct,ref prevOffset);
|
||||
// 防止调用方法中没有更新
|
||||
if (_prev >= prevOffset)
|
||||
{
|
||||
prevOffset = correct.SentenceOffset + item.end;
|
||||
}
|
||||
|
||||
if (item.tag != "i") index++;
|
||||
if (mark != null)
|
||||
{
|
||||
marks.Add(item.id, new ProofreadItem(item, mark));
|
||||
marks.Add(item.id, new ProofreadItem(item, mark,documentId));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -576,8 +619,8 @@ namespace AIProofread
|
||||
{"message","没有找到标记对象" },
|
||||
{ "origin",item },
|
||||
{ "origin_correct",correct },
|
||||
{ "new_text",correct.New_text },
|
||||
{ "paragraph_num",correct.Paragraph_num },
|
||||
{ "new_text",correct.NewText },
|
||||
{ "paragraph_num",correct.ParagraphNumber },
|
||||
};
|
||||
Logger.Log(JsonConvert.SerializeObject(msg));
|
||||
}
|
||||
@ -646,21 +689,18 @@ namespace AIProofread
|
||||
/// <summary>
|
||||
/// 根据校对项查找文档对应的位置 并创建书签
|
||||
/// </summary>
|
||||
/// <param name="originText">接口原始文档</param>
|
||||
/// <param name="item">校对项</param>
|
||||
/// <param name="findIndex"></param>
|
||||
/// <param name="offset"></param>
|
||||
/// <param name="length"></param>
|
||||
/// <param name="paragraphIndex"></param>
|
||||
/// <param name="correct">校对项</param>
|
||||
/// <param name="sentense">校对</param>
|
||||
/// <param name="prevOffset"></param>
|
||||
/// <returns></returns>
|
||||
public Microsoft.Office.Tools.Word.Bookmark FindRangeAndCreateBookmark(string originText, CorrectedContent item, int findIndex, int offset, int length, int paragraphIndex)
|
||||
public Microsoft.Office.Tools.Word.Bookmark FindRangeAndCreateBookmark(CorrectedContent correct, DocumentCorrectItem sentense,ref int prevOffset)
|
||||
{
|
||||
Microsoft.Office.Tools.Word.Bookmark bookmark = null;
|
||||
try
|
||||
{
|
||||
var document = CurrentDocument;
|
||||
ControlCollection controls = Globals.Factory.GetVstoObject(document).Controls;
|
||||
var markName = Config.BuildBookmarkName(item.id);
|
||||
var markName = Config.BuildBookmarkName(correct.id);
|
||||
|
||||
// 判断是否已经存在
|
||||
if (controls.Contains(markName))
|
||||
@ -672,14 +712,16 @@ namespace AIProofread
|
||||
catch (Exception) { }
|
||||
}
|
||||
Range findRange = null;
|
||||
if (paragraphIndex > document.Paragraphs.Count) return null;
|
||||
var paragraph = document.Paragraphs[paragraphIndex];
|
||||
// 判断段落是否存在
|
||||
if (sentense.ParagraphNumber > document.Paragraphs.Count) return null;
|
||||
|
||||
var paragraph = document.Paragraphs[sentense.ParagraphNumber];
|
||||
Range paragraphRange = paragraph.Range;
|
||||
var paragraphStart = paragraphRange.Start;
|
||||
//offset += paragraphStart;
|
||||
|
||||
var Start = paragraphStart + offset;
|
||||
var End = Start + length - 1;
|
||||
|
||||
var Start = paragraphStart + sentense.SentenceOffset;
|
||||
var End = Start + sentense.InsertLength - 1;
|
||||
if (End > paragraphRange.End)
|
||||
{
|
||||
End = paragraphRange.End;
|
||||
@ -691,16 +733,22 @@ namespace AIProofread
|
||||
string fullText = fullRange.Text ?? paragraphRange.Text;
|
||||
// 当前段落文本
|
||||
string paragraphText = paragraphRange.Text;
|
||||
End = Start + item.end;
|
||||
Start = Start + item.start;
|
||||
End = Start + correct.end;
|
||||
Start = Start + correct.start;
|
||||
// 避免越界
|
||||
prevOffset = Math.Min(prevOffset, paragraphText.Length - 1);
|
||||
|
||||
int offset = sentense.SentenceOffset;
|
||||
int length = sentense.InsertLength;
|
||||
string originText = sentense.Insert;
|
||||
|
||||
// 如果是新增 则查找定位
|
||||
if (item.tag == "i")
|
||||
if (correct.tag == "i")
|
||||
{
|
||||
// s1. 通过接口的位置 和 文档内容进行比对
|
||||
try
|
||||
{
|
||||
// 判断接口的定位字符串和文档截取的字符串是否一致
|
||||
if (paragraphText.Substring(offset, length) == originText)
|
||||
{
|
||||
// 直接使用接口定位
|
||||
@ -715,20 +763,20 @@ namespace AIProofread
|
||||
if (findRange == null)
|
||||
{
|
||||
// 找前缀
|
||||
var prefix = item.start > 2 ? (
|
||||
item.start > INSERT_FIND_OFFSET
|
||||
? originText.Substring(item.start - INSERT_FIND_OFFSET, INSERT_FIND_OFFSET)
|
||||
: originText.Substring(0, item.start)
|
||||
var prefix = correct.start > 2 ? (
|
||||
correct.start > INSERT_FIND_OFFSET
|
||||
? originText.Substring(correct.start - INSERT_FIND_OFFSET, INSERT_FIND_OFFSET)
|
||||
: originText.Substring(0, correct.start)
|
||||
) : null;
|
||||
// 找后缀
|
||||
var suffix = prefix == null ? (
|
||||
item.end + INSERT_FIND_OFFSET < originText.Length
|
||||
? originText.Substring(item.start, INSERT_FIND_OFFSET)
|
||||
: originText.Substring(item.start, originText.Length - item.start)
|
||||
correct.end + INSERT_FIND_OFFSET < originText.Length
|
||||
? originText.Substring(correct.start, INSERT_FIND_OFFSET)
|
||||
: originText.Substring(correct.start, originText.Length - correct.start)
|
||||
) : null;
|
||||
// 偏移量
|
||||
var start = prefix != null || suffix != null
|
||||
? paragraphText.IndexOf(prefix ?? suffix, offset) // item.start +
|
||||
? paragraphText.IndexOf(prefix ?? suffix, prevOffset)
|
||||
: -1;
|
||||
if (start != -1)
|
||||
{
|
||||
@ -741,14 +789,18 @@ namespace AIProofread
|
||||
{
|
||||
findRange = document.Range(Start, End);
|
||||
}
|
||||
|
||||
if (item.tag != "i" && findRange.Text != item.origin)
|
||||
// 不是新增模式 且定位区域文本和原始文本不匹配
|
||||
if (correct.tag != "i" && findRange.Text != correct.origin)
|
||||
{
|
||||
findRange = DocumentUtil.FindRange(paragraphIndex, offset, originText, item.origin, item.start, item.end);
|
||||
// 查找
|
||||
findRange = DocumentUtil.FindRange(correct,sentense,ref prevOffset,CurrentDocument, paragraphRange);
|
||||
}
|
||||
|
||||
// 能够找到对应的区域 则再对应区域添加书签
|
||||
if (findRange != null)
|
||||
{
|
||||
// 更新查找的结束位置
|
||||
prevOffset = findRange.End - paragraphStart;
|
||||
bookmark = controls.AddBookmark(findRange, markName);
|
||||
bookmark.Tag = "ai_proofread";
|
||||
}
|
||||
@ -801,6 +853,11 @@ namespace AIProofread
|
||||
return bookmark;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="range"></param>
|
||||
/// <param name="whatToFind"></param>
|
||||
private void FindRange(ref Range range, ref object whatToFind)
|
||||
{
|
||||
object matchCase = false; // 是否区分大小写
|
||||
|
@ -3,6 +3,12 @@ using System.Text.RegularExpressions;
|
||||
|
||||
namespace AIProofread
|
||||
{
|
||||
public enum AppEnvironment
|
||||
{
|
||||
Dev,
|
||||
Test,
|
||||
Prod
|
||||
}
|
||||
public class Config
|
||||
{
|
||||
public static readonly string APP_NAME = "AI校对王";
|
||||
@ -16,10 +22,13 @@ namespace AIProofread
|
||||
/// </summary>
|
||||
public static string WEB_PATH = "http://192.168.10.100:5173/";
|
||||
public static bool RUN_IN_DEBUG = true;
|
||||
public static AppEnvironment APP_ENV = AppEnvironment.Dev;
|
||||
#else
|
||||
public static string WEB_PATH = "https://gm-plugin.gachafun.com/";
|
||||
public static bool RUN_IN_DEBUG = false;
|
||||
public static AppEnvironment APP_ENV = AppEnvironment.Prod;
|
||||
#endif
|
||||
|
||||
public static readonly string APP_DATA_PATH = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\ai_proofread";
|
||||
public static readonly string APP_LOG_PATH = APP_DATA_PATH + "\\logs\\";
|
||||
public static readonly string WEB_DATA_PATH = APP_DATA_PATH + "\\userdata";
|
||||
|
@ -16,9 +16,12 @@ namespace UtilLib
|
||||
private WdColor originColor;
|
||||
private WdColor originBackgroundColor;
|
||||
public string Name { get; set; }
|
||||
public ProofreadItem(CorrectedContent content)
|
||||
public int DocumentId { get; set; }
|
||||
|
||||
public ProofreadItem(CorrectedContent content,int documentId)
|
||||
{
|
||||
this.content = content;
|
||||
this.DocumentId = documentId;
|
||||
InitBookMark(null);
|
||||
SetMarkName();
|
||||
}
|
||||
@ -28,8 +31,9 @@ namespace UtilLib
|
||||
this.Name = this.mark != null ? mark.Name : Config.BuildBookmarkName(content.id);
|
||||
}
|
||||
|
||||
public ProofreadItem(CorrectedContent content, Bookmark bookmark)
|
||||
public ProofreadItem(CorrectedContent content, Bookmark bookmark, int documentId)
|
||||
{
|
||||
this.DocumentId = documentId;
|
||||
this.content = content;
|
||||
if (bookmark != null)
|
||||
{
|
||||
@ -68,7 +72,7 @@ namespace UtilLib
|
||||
private void OnMarkSelected(object sender, Microsoft.Office.Tools.Word.SelectionEventArgs e)
|
||||
{
|
||||
//throw new System.NotImplementedException();
|
||||
Bridge.bridge.SelectMarkById(content.id);
|
||||
Bridge.bridge.SelectMarkById(content.id,DocumentId);
|
||||
}
|
||||
|
||||
public void Select()
|
||||
|
9
AIProofread/Ribbon1.Designer.cs
generated
9
AIProofread/Ribbon1.Designer.cs
generated
@ -51,7 +51,6 @@ namespace AIProofread
|
||||
this.grpDebug = this.Factory.CreateRibbonGroup();
|
||||
this.btnShowPane = this.Factory.CreateRibbonButton();
|
||||
this.btnHidePane = this.Factory.CreateRibbonButton();
|
||||
this.btnSelectionPosition = this.Factory.CreateRibbonButton();
|
||||
this.BtnOpenLog = this.Factory.CreateRibbonButton();
|
||||
this.button1 = this.Factory.CreateRibbonButton();
|
||||
this.tabAIProofread.SuspendLayout();
|
||||
@ -170,7 +169,6 @@ namespace AIProofread
|
||||
//
|
||||
this.grpDebug.Items.Add(this.btnShowPane);
|
||||
this.grpDebug.Items.Add(this.btnHidePane);
|
||||
this.grpDebug.Items.Add(this.btnSelectionPosition);
|
||||
this.grpDebug.Items.Add(this.BtnOpenLog);
|
||||
this.grpDebug.Items.Add(this.button1);
|
||||
this.grpDebug.Label = "开发调试";
|
||||
@ -189,12 +187,6 @@ namespace AIProofread
|
||||
this.btnHidePane.Name = "btnHidePane";
|
||||
this.btnHidePane.Click += new Microsoft.Office.Tools.Ribbon.RibbonControlEventHandler(this.btnHidePane_Click);
|
||||
//
|
||||
// btnSelectionPosition
|
||||
//
|
||||
this.btnSelectionPosition.Label = "测试分段速度";
|
||||
this.btnSelectionPosition.Name = "btnSelectionPosition";
|
||||
this.btnSelectionPosition.Click += new Microsoft.Office.Tools.Ribbon.RibbonControlEventHandler(this.btnSelectionPosition_Click);
|
||||
//
|
||||
// BtnOpenLog
|
||||
//
|
||||
this.BtnOpenLog.Label = "打开日志目录";
|
||||
@ -240,7 +232,6 @@ namespace AIProofread
|
||||
internal Microsoft.Office.Tools.Ribbon.RibbonGroup grpDebug;
|
||||
internal Microsoft.Office.Tools.Ribbon.RibbonButton btnShowPane;
|
||||
internal Microsoft.Office.Tools.Ribbon.RibbonButton btnHidePane;
|
||||
internal Microsoft.Office.Tools.Ribbon.RibbonButton btnSelectionPosition;
|
||||
internal Microsoft.Office.Tools.Ribbon.RibbonButton BtnOpenLog;
|
||||
internal Microsoft.Office.Tools.Ribbon.RibbonButton button1;
|
||||
}
|
||||
|
@ -31,6 +31,9 @@ namespace AIProofread
|
||||
ShowDebug();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 用于调试或测试
|
||||
/// </summary>
|
||||
public void ShowDebug()
|
||||
{
|
||||
if (Config.RUN_IN_DEBUG)
|
||||
@ -136,7 +139,7 @@ namespace AIProofread
|
||||
var result = MessageBox.Show("请确认是否清除此文档的所有校对标注?", "提示", MessageBoxButtons.OKCancel);
|
||||
if(result == DialogResult.OK)
|
||||
{
|
||||
Bridge.bridge.clearAllProofreadMark();
|
||||
Bridge.bridge.clearAllProofreadMark(null);
|
||||
Globals.ThisAddIn.SendMessageToWeb("clear-tips", null);
|
||||
}
|
||||
}
|
||||
@ -153,28 +156,6 @@ namespace AIProofread
|
||||
|
||||
private Microsoft.Office.Interop.Word.Document CurrentDocument;
|
||||
|
||||
private void btnSelectionPosition_Click(object sender, RibbonControlEventArgs e)
|
||||
{
|
||||
// 测试加快速度处理 段落
|
||||
//CurrentDocument = Globals.ThisAddIn.Application.ActiveDocument;
|
||||
//var tables = CurrentDocument.Tables;
|
||||
//var tableCount = tables.Count;
|
||||
//System.Windows.Forms.MessageBox.Show("tables "+ tableCount);
|
||||
|
||||
//var footNotes = CurrentDocument.Footnotes;
|
||||
//System.Windows.Forms.MessageBox.Show("footNotes " + footNotes.Count);
|
||||
//var endNotes = CurrentDocument.Endnotes;
|
||||
//System.Windows.Forms.MessageBox.Show("endNotes " + endNotes.Count);
|
||||
//Bridge.bridge.getDocumentData();
|
||||
CurrentDocument = Globals.ThisAddIn.Application.ActiveDocument;
|
||||
|
||||
string path = Tools.GetReadDocumentFilePath(CurrentDocument);
|
||||
Debug.WriteLine(path);
|
||||
Logger.Log(path);
|
||||
|
||||
System.Windows.Forms.MessageBox.Show("Test");
|
||||
}
|
||||
|
||||
private void TestSplit()
|
||||
{
|
||||
//try
|
||||
|
@ -47,6 +47,7 @@ namespace AIProofread
|
||||
public Dictionary<Word.Document, CustomTaskPane> taskPanels = new Dictionary<Word.Document, CustomTaskPane>();
|
||||
public Dictionary<Word.Document, bool> panelsVisibleStatus = new Dictionary<Word.Document, bool>();
|
||||
public Dictionary<Word.Document, int> documentIdDics = new Dictionary<Word.Document, int>();
|
||||
|
||||
public CustomTaskPane currentDocumentTaskPane;
|
||||
|
||||
private static readonly Dictionary<Word.Document, Dictionary<int, ProofreadItem>> allMarks = new Dictionary<Word.Document, Dictionary<int, ProofreadItem>>();
|
||||
@ -99,10 +100,10 @@ namespace AIProofread
|
||||
DisposePanel(currentDoc);
|
||||
}
|
||||
|
||||
public void ActiveCurrentDocumentMarks()
|
||||
public void ActiveCurrentDocumentMarks(Word.Document document)
|
||||
{
|
||||
// 判断是否存在 没有的话初始化
|
||||
var currentDoc = Application.ActiveDocument;
|
||||
var currentDoc = document ?? Application.ActiveDocument ;
|
||||
if (!allMarks.ContainsKey(currentDoc))
|
||||
{
|
||||
allMarks[currentDoc] = new Dictionary<int, ProofreadItem>();
|
||||
@ -121,6 +122,7 @@ namespace AIProofread
|
||||
Logger.Log("Application_DocumentOpen -- " + Doc.FullName);
|
||||
ShowPanel(Doc);
|
||||
}
|
||||
|
||||
void DisposePanel(Word.Document doc)
|
||||
{
|
||||
if (panelsVisibleStatus.ContainsKey(doc))
|
||||
@ -249,17 +251,22 @@ namespace AIProofread
|
||||
Logger.Log("Found app.json " + content);
|
||||
if (content == null || content.Length == 0) return;
|
||||
AppConfig config = JsonConvert.DeserializeObject<AppConfig>(content);
|
||||
if (config.AppUrl?.Length > 0)
|
||||
|
||||
// 插件网址
|
||||
if (!string.IsNullOrEmpty(config.AppUrl))
|
||||
{
|
||||
Config.WEB_PATH = config.AppUrl;
|
||||
}
|
||||
if (config.AppRunInDebug)
|
||||
// 运行环境
|
||||
if (!string.IsNullOrEmpty(config.Environment))
|
||||
{
|
||||
Config.RUN_IN_DEBUG = config.AppRunInDebug;
|
||||
if (this.ribbon != null)
|
||||
{
|
||||
this.ribbon.ShowDebug();
|
||||
}
|
||||
Config.APP_ENV = config.Environment == "dev" ? AppEnvironment.Dev : (
|
||||
config.Environment == "test" ? AppEnvironment.Test : AppEnvironment.Prod
|
||||
);
|
||||
}
|
||||
if (Config.APP_ENV != AppEnvironment.Prod && this.ribbon != null)
|
||||
{
|
||||
this.ribbon.ShowDebug();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -316,9 +323,6 @@ namespace AIProofread
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void Application_WindowSelectionChange(Word.Selection s)
|
||||
{
|
||||
if (s.Bookmarks != null)
|
||||
@ -333,14 +337,14 @@ namespace AIProofread
|
||||
int proofreadId = Config.GetBookmarkIdByName(item.Name);
|
||||
if (proofreadId > 0)
|
||||
{
|
||||
Bridge.bridge.SelectMarkById(proofreadId);
|
||||
Bridge.bridge.SelectMarkById(proofreadId,0);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Bridge.bridge.SelectMarkById(-1);
|
||||
Bridge.bridge.SelectMarkById(-1,0);
|
||||
}
|
||||
|
||||
public int MyProperty { get; set; }
|
||||
|
@ -160,47 +160,48 @@ namespace AIProofread
|
||||
return list;
|
||||
}
|
||||
|
||||
private static readonly int INSERT_FIND_OFFSET = 5;
|
||||
/// <summary>
|
||||
/// 查找对应段落的range
|
||||
/// 查找偏移量
|
||||
/// </summary>
|
||||
/// <param name="paragraphsIndex">段落index,从第1开始计数</param>
|
||||
/// <param name="offset">当前偏移量</param>
|
||||
/// <param name="findText">要查找字符串</param>
|
||||
/// <param name="wordStart">字符串原始起始位置</param>
|
||||
/// <param name="wordEnd">字符串原始结束位置</param>
|
||||
private static readonly int INSERT_FIND_OFFSET = 5;
|
||||
|
||||
/// <summary>
|
||||
/// 查找校对项对应的range
|
||||
/// </summary>
|
||||
/// <param name="correct">校对项</param>
|
||||
/// <param name="sentense">当前校对项所在句子</param>
|
||||
/// <param name="prevOffset">上一个校对项结束位置</param>
|
||||
/// <param name="document"></param>
|
||||
/// <param name="range"></param>
|
||||
/// <returns></returns>
|
||||
public static Range FindRange(int paragraphsIndex,int offset,string originText, string findText, int wordStart, int wordEnd)
|
||||
public static Range FindRange(CorrectedContent correct, DocumentCorrectItem sentense,ref int prevOffset, Microsoft.Office.Interop.Word.Document document, Range range)
|
||||
{
|
||||
// <param name="findIndex"></param> 暂时接口无法支持
|
||||
var document = Globals.ThisAddIn.Application.ActiveDocument;
|
||||
if (paragraphsIndex > document.Paragraphs.Count) return null;
|
||||
var paragraph = document.Paragraphs[paragraphsIndex];
|
||||
var range = paragraph.Range;
|
||||
var paragraphText = range.Text;
|
||||
|
||||
string findText = correct.origin;
|
||||
int wordStart = correct.start;
|
||||
int wordEnd = correct.end;
|
||||
|
||||
int offset = sentense.SentenceOffset;
|
||||
string originText = sentense.Insert;
|
||||
|
||||
object Start = range.Start + offset + wordStart;
|
||||
object End = range.Start + offset + wordEnd;
|
||||
|
||||
try
|
||||
{
|
||||
//int num = 0;
|
||||
int num3 = 0;
|
||||
|
||||
// 段落开始和结束
|
||||
object Start = paragraph.Range.Start;
|
||||
object End = paragraph.Range.End;
|
||||
|
||||
// 段落选区
|
||||
//Range range = document.Range(ref Start, ref End);
|
||||
|
||||
var activeDocument = document;
|
||||
// 查找对象位置
|
||||
End = range.Start + offset + wordStart;
|
||||
Start = range.Start + offset + wordEnd;
|
||||
End = range.Start + offset + wordEnd;
|
||||
Start = range.Start + offset + wordStart;
|
||||
// 直接找到
|
||||
var findRange = activeDocument.Range(ref End, ref Start);
|
||||
var findRange = activeDocument.Range(ref Start,ref End);
|
||||
// 判断对应选区是否是要找的文本
|
||||
if (findRange.Text == findText)
|
||||
{
|
||||
return findRange;
|
||||
}
|
||||
#region 使用前后关联进行强匹配
|
||||
// 找前缀
|
||||
var prefix = wordStart > 2 ? (
|
||||
wordStart > INSERT_FIND_OFFSET
|
||||
@ -214,53 +215,25 @@ namespace AIProofread
|
||||
: originText.Substring(wordStart, originText.Length - wordStart)
|
||||
) : null;
|
||||
var start = prefix != null || suffix != null
|
||||
? paragraphText.IndexOf(prefix ?? suffix, offset) // item.start +
|
||||
? paragraphText.IndexOf(prefix ?? suffix, prevOffset) // item.start +
|
||||
: -1;
|
||||
|
||||
if (start != -1)
|
||||
{
|
||||
var findOffset = range.Start + start + (prefix != null ? prefix.Length : 0);
|
||||
findRange = document.Range(findOffset, findOffset + wordEnd - wordStart);
|
||||
if(findRange.Text == findText) { return findRange; }
|
||||
if (findRange.Text == findText) { return findRange; }
|
||||
}
|
||||
var msg = new Dictionary<string, object>{
|
||||
{"message","后端接口位置不可用,开始执行查找" },
|
||||
{ "origin_start",wordStart },
|
||||
{ "origin_end",wordEnd },
|
||||
{"find_text",findRange.Text },
|
||||
{"origin_text", findText}
|
||||
};
|
||||
Logger.Log(JsonConvert.SerializeObject(msg));
|
||||
// 查找
|
||||
range.Find.MatchByte = true;
|
||||
// 使用选区查找功能
|
||||
Find find = range.Find;
|
||||
// 节约变量
|
||||
End = findText;
|
||||
Start = true;
|
||||
#endregion
|
||||
|
||||
object MatchWholeWord = Type.Missing;
|
||||
object MatchWildcards = Type.Missing;
|
||||
object MatchSoundsLike = Type.Missing;
|
||||
object MatchAllWordForms = Type.Missing;
|
||||
object Forward = Type.Missing;
|
||||
object Wrap = Type.Missing;
|
||||
object Format = Type.Missing;
|
||||
object ReplaceWith = Type.Missing;
|
||||
object Replace = Type.Missing;
|
||||
object MatchKashida = Type.Missing;
|
||||
object MatchDiacritics = Type.Missing;
|
||||
object MatchAlefHamza = Type.Missing;
|
||||
object MatchControl = Type.Missing;
|
||||
// 使用段落字符串进行强匹配
|
||||
start = paragraphText.IndexOf(findText, prevOffset);
|
||||
if (start != -1)
|
||||
{
|
||||
start += range.Start;
|
||||
return document.Range(start, start + findText.Length);
|
||||
}
|
||||
|
||||
// 没有找到则执行查询
|
||||
find.Execute(
|
||||
ref End, ref Start, ref MatchWholeWord,
|
||||
ref MatchWildcards, ref MatchSoundsLike,
|
||||
ref MatchAllWordForms, ref Forward, ref Wrap,
|
||||
ref Format, ref ReplaceWith, ref Replace,
|
||||
ref MatchKashida, ref MatchDiacritics,
|
||||
ref MatchAlefHamza, ref MatchControl
|
||||
);
|
||||
|
||||
var msg1 = new Dictionary<string, object>{
|
||||
{"message",range.Find.Found?"搜索到可用位置":"没有搜索到可用位置" },
|
||||
@ -269,50 +242,51 @@ namespace AIProofread
|
||||
{ "search_text",range.Text }
|
||||
};
|
||||
Logger.Log(JsonConvert.SerializeObject(msg1));
|
||||
while (range.Find.Found)
|
||||
{
|
||||
var obj4 = range.Document;
|
||||
MatchControl = range.Start;
|
||||
MatchAlefHamza = range.End;
|
||||
var range2 = obj4.Range(ref MatchControl, ref MatchAlefHamza);
|
||||
num3 = range2.End;
|
||||
if (range2.Text == findText)
|
||||
{
|
||||
return range2;
|
||||
}
|
||||
break;
|
||||
//if (findIndex == num)
|
||||
//{
|
||||
//while (range.Find.Found)
|
||||
//{
|
||||
// var obj4 = range.Document;
|
||||
// MatchControl = range.Start;
|
||||
// MatchAlefHamza = range.End;
|
||||
// var range2 = obj4.Range(ref MatchControl, ref MatchAlefHamza);
|
||||
// num3 = range2.End;
|
||||
// if (range2.Text == findText)
|
||||
// {
|
||||
// return range2;
|
||||
// }
|
||||
// break;
|
||||
// //if (findIndex == num)
|
||||
// //{
|
||||
|
||||
//}
|
||||
//num++;
|
||||
//range.Find.MatchByte = true;
|
||||
//Find find2 = range.Find;
|
||||
//MatchAlefHamza = missword;
|
||||
//MatchControl = true;
|
||||
//MatchDiacritics = Type.Missing;
|
||||
//MatchKashida = Type.Missing;
|
||||
//Replace = Type.Missing;
|
||||
//ReplaceWith = Type.Missing;
|
||||
//Format = Type.Missing;
|
||||
//Wrap = Type.Missing;
|
||||
//Forward = Type.Missing;
|
||||
//MatchAllWordForms = Type.Missing;
|
||||
//MatchSoundsLike = Type.Missing;
|
||||
//MatchWildcards = Type.Missing;
|
||||
//MatchWholeWord = Type.Missing;
|
||||
//Start = Type.Missing;
|
||||
//End = Type.Missing;
|
||||
//// 再次重复查找
|
||||
//find2.Execute(ref MatchAlefHamza, ref MatchControl, ref MatchDiacritics, ref MatchKashida, ref Replace, ref ReplaceWith, ref Format, ref Wrap, ref Forward, ref MatchAllWordForms, ref MatchSoundsLike, ref MatchWildcards, ref MatchWholeWord, ref Start, ref End);
|
||||
}
|
||||
if (num3 == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
// //}
|
||||
// //num++;
|
||||
// //range.Find.MatchByte = true;
|
||||
// //Find find2 = range.Find;
|
||||
// //MatchAlefHamza = missword;
|
||||
// //MatchControl = true;
|
||||
// //MatchDiacritics = Type.Missing;
|
||||
// //MatchKashida = Type.Missing;
|
||||
// //Replace = Type.Missing;
|
||||
// //ReplaceWith = Type.Missing;
|
||||
// //Format = Type.Missing;
|
||||
// //Wrap = Type.Missing;
|
||||
// //Forward = Type.Missing;
|
||||
// //MatchAllWordForms = Type.Missing;
|
||||
// //MatchSoundsLike = Type.Missing;
|
||||
// //MatchWildcards = Type.Missing;
|
||||
// //MatchWholeWord = Type.Missing;
|
||||
// //Start = Type.Missing;
|
||||
// //End = Type.Missing;
|
||||
// //// 再次重复查找
|
||||
// //find2.Execute(ref MatchAlefHamza, ref MatchControl, ref MatchDiacritics, ref MatchKashida, ref Replace, ref ReplaceWith, ref Format, ref Wrap, ref Forward, ref MatchAllWordForms, ref MatchSoundsLike, ref MatchWildcards, ref MatchWholeWord, ref Start, ref End);
|
||||
//}
|
||||
//if (num3 == 0)
|
||||
//{
|
||||
// return null;
|
||||
//}
|
||||
}
|
||||
catch (Exception)
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Log(ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -5,5 +5,9 @@ namespace UtilLib
|
||||
{
|
||||
public string AppUrl { get; set; }
|
||||
public bool AppRunInDebug { get; set; }
|
||||
/// <summary>
|
||||
/// dev | test | product
|
||||
/// </summary>
|
||||
public string Environment { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -2,15 +2,45 @@
|
||||
{
|
||||
public class CorrectedContent
|
||||
{
|
||||
/// <summary>
|
||||
/// 校对类别()
|
||||
/// </summary>
|
||||
public string tag { get; set; }
|
||||
/// <summary>
|
||||
/// 校对原始文本
|
||||
/// </summary>
|
||||
public string origin { get; set; }
|
||||
/// <summary>
|
||||
/// 校对文本
|
||||
/// </summary>
|
||||
public string text { get; set; }
|
||||
/// <summary>
|
||||
/// 校对项在句子中的开始位置
|
||||
/// </summary>
|
||||
public int start { get; set; }
|
||||
/// <summary>
|
||||
/// 校对项在句子中的结束位置
|
||||
/// </summary>
|
||||
public int end { get; set; }
|
||||
/// <summary>
|
||||
/// 校对项ID
|
||||
/// </summary>
|
||||
public int id { get; set; }
|
||||
/// <summary>
|
||||
/// 校对项索引
|
||||
/// </summary>
|
||||
public int idx { get; set; }
|
||||
/// <summary>
|
||||
/// 校对所属分类
|
||||
/// </summary>
|
||||
public int type { get; set; }
|
||||
/// <summary>
|
||||
/// 校对状态
|
||||
/// </summary>
|
||||
public int isAccept { get; set; }
|
||||
/// <summary>
|
||||
/// 校对项颜色
|
||||
/// </summary>
|
||||
public string color { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,43 @@
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace UtilLib
|
||||
{
|
||||
public class DocumentCorrectItem
|
||||
{
|
||||
public string Key { get; set; }
|
||||
/// <summary>
|
||||
/// 句子原始文本(可能过滤掉空格等特殊字符)
|
||||
/// </summary>
|
||||
public string Insert { get; set; }
|
||||
public string New_text { get; set; }
|
||||
public int Insert_len { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 校对后的文本
|
||||
/// </summary>
|
||||
[JsonProperty("new_text")]
|
||||
public string NewText { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 句子原始文本长度
|
||||
/// </summary>
|
||||
[JsonProperty("insert_len")]
|
||||
public int InsertLength { get; set; }
|
||||
public int Offset { get; set; }
|
||||
public int Paragraph_offset { get; set; }
|
||||
public int Paragraph_num { get; set; }
|
||||
public int Sentence_offset { get; set; }
|
||||
/// <summary>
|
||||
/// 句子所在文档的段落数(从1开始)
|
||||
/// </summary>
|
||||
[JsonProperty("paragraph_num")]
|
||||
public int ParagraphNumber { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 句子在段落中的其实位置
|
||||
/// </summary>
|
||||
[JsonProperty("sentence_offset")]
|
||||
public int SentenceOffset { get; set; }
|
||||
/// <summary>
|
||||
/// 当前句子的校对列表项
|
||||
/// </summary>
|
||||
public List<CorrectedContent> Diffs { get; set; }
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user