This commit is contained in:
owenchen committed 2026-05-29 13:03:00 +08:00
1 parent 597b88d075
commit 527205520b
12 files changed
+104 -43

No files matched your search

+15 -18
View File
@@ -2,12 +2,12 @@
using CloudBuilder.Core.DatabaseAccessor.Entity;
using CloudBuilder.Core.DependencyInjection.Task;
using CloudBuilder.Topshelf.Python;
using CloudBuilder.Topshelf.Task.Novel.Process;
using CloudBuilder.Topshelf.Utility;
using static System.Net.Mime.MediaTypeNames;
namespace CloudBuilder.Topshelf.Task
{
//task:ChineseNameExtractorTask guid:B000006
//task:ChineseNameExtractorTask book_id:B000008
public class ChineseNameExtractorTask : IScheduleTask
{
private readonly IApplicationService service;
@@ -19,16 +19,16 @@ namespace CloudBuilder.Topshelf.Task
public void Run(Dictionary<string, string> bodyDict)
{
if (!bodyDict.ContainsKey("guid")) return;
if (!bodyDict.ContainsKey("book_id")) return;
string guid = bodyDict["guid"];
string guid = bodyDict["book_id"];
PythonCommand python = new PythonCommand(service);
try
{
Hanlp2 hanlp = new Hanlp2(python);
IRepository<AiSentenceDialogueViewEntity> repository = service.GetRepository<IRepository<AiSentenceDialogueViewEntity>>();
IRepository<AiSentenceViewEntity> repository = service.GetRepository<IRepository<AiSentenceViewEntity>>();
IRepository<AiSentenceEntity> repositoryAiSentenceEntity = service.GetRepository<IRepository<AiSentenceEntity>>();
@@ -42,10 +42,12 @@ namespace CloudBuilder.Topshelf.Task
SpeakerAnalysisHelper speakerFeatureLearner = new SpeakerAnalysisHelper();
AiSentenceDialogueViewEntity[] ents = repository.DetachedEntities.Where(x => x.BookGuid == guid).OrderBy(x => x.ChapterIndex).ThenBy(x => x.ParagraphIndex).ThenBy(x => x.DialogueIndc).ToArray();
AiSentenceViewEntity[] ents = repository.DetachedEntities.Where(x => x.BookId == guid).OrderBy(x => x.ChapterId).ThenBy(x => x.ParagraphId).ThenBy(x => x.SentenceIndex).ToArray();
if (ents == null || ents.Length == 0) return;
AiSentenceEntity aiSentenceEntity;
string person = null;
int paragraphIndex = 0;
long paragraphIndex = 0;
int totalLines = ents.Length;
int processedLines = 0; // 已处理行数计数器
@@ -54,23 +56,17 @@ namespace CloudBuilder.Topshelf.Task
{
processedLines++;
if (!string.IsNullOrEmpty(person) && paragraphIndex == ent.ParagraphIndex)
person = speakerFeatureLearner.GetPerson(hanlp, ent.Content);
paragraphIndex = ent.ParagraphId;
if (!string.IsNullOrEmpty(person))
{
paragraphIndex = 0;
aiSentenceEntity = repositoryAiSentenceEntity.Entities.Where(x => x.Guid == ent.Guid).FirstOrDefault();
aiSentenceEntity = repositoryAiSentenceEntity.Entities.Where(x => x.SentenceId == ent.SentenceId).FirstOrDefault();
aiSentenceEntity.PersonName = person;
repositoryAiSentenceEntity.UpdateNow(aiSentenceEntity);
continue;
}
depRoot = hanlp.GetDepRoot(ent.Content);
ners = hanlp.GetHanlpNer(ent.Content);
srls = hanlp.GetHanlpSrl(ent.Content);
person = speakerFeatureLearner.GetPerson(depRoot, ners, srls, cons);
paragraphIndex = ent.ParagraphIndex;
UpdateProgress(processedLines, totalLines);
}
@@ -81,6 +77,7 @@ namespace CloudBuilder.Topshelf.Task
}
finally
{
Console.WriteLine("");
python.Dispose();
}
}