ow
This commit is contained in:
1 parent
30c22a3d0c
commit
0c79fb3519
11 files changed
+296
-40
No files matched your search
@@ -12,6 +12,7 @@ using CloudBuilder.Security.Policy;
|
||||
using CloudBuilder.Security.Service;
|
||||
using CloudBuilder.Security.Utility;
|
||||
using DocumentFormat.OpenXml.ExtendedProperties;
|
||||
using DocumentFormat.OpenXml.Presentation;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System.Diagnostics.Contracts;
|
||||
@@ -24,6 +25,8 @@ namespace CloudBuilder.AI.Service
|
||||
private readonly IApplicationService service;
|
||||
|
||||
private IRepository<AiBookEntity> repository;
|
||||
|
||||
private ChineseNameExtractor chineseNameExtractor;
|
||||
public AiBookService(IApplicationService service)
|
||||
{
|
||||
this.service = service;
|
||||
@@ -252,5 +255,54 @@ namespace CloudBuilder.AI.Service
|
||||
|
||||
return FindByKey(key);
|
||||
}
|
||||
|
||||
[PermissionOperate(name: AIPermissionPolicy.AiBook, operate: Operate.Update)]
|
||||
[UnitOfWork]
|
||||
public void ExtractNames(string bookGuid)
|
||||
{
|
||||
ExtractNamesByChapterGuid(bookGuid, null);
|
||||
}
|
||||
|
||||
[PermissionOperate(name: AIPermissionPolicy.AiBook, operate: Operate.Update)]
|
||||
[UnitOfWork]
|
||||
public void ExtractNamesByChapterGuid(string bookGuid, string chapterGuid)
|
||||
{
|
||||
if (chineseNameExtractor == null) chineseNameExtractor = new ChineseNameExtractor(service);
|
||||
|
||||
IRepository<AiChapterPersonEntity> repositoryAiChapterPersonEntity = repository.GetRepository<IRepository<AiChapterPersonEntity>>();
|
||||
|
||||
IRepository<AiParagraphViewEntity> repositoryAiParagraphEntity = repository.GetRepository<IRepository<AiParagraphViewEntity>>();
|
||||
|
||||
AiParagraphViewEntity[] paragraphs = repositoryAiParagraphEntity.DetachedEntities.Where(x => x.BookGuid == bookGuid && (string.IsNullOrEmpty(chapterGuid) || x.ChapterGuid == chapterGuid)).ToArray();
|
||||
|
||||
if (paragraphs == null || paragraphs.Length == 0) return;
|
||||
|
||||
List<string> names = new List<string>();
|
||||
List<AiChapterPersonEntity> aiChapterPersonEntities = new List<AiChapterPersonEntity>();
|
||||
AiChapterPersonEntity entity;
|
||||
int orderIndex = 0;
|
||||
foreach (var paragraph in paragraphs)
|
||||
{
|
||||
names = chineseNameExtractor.ExtractNames(paragraph.Content);
|
||||
|
||||
if (names == null || names.Count() == 0) continue;
|
||||
|
||||
orderIndex = 1;
|
||||
foreach (var name in names)
|
||||
{
|
||||
entity = new AiChapterPersonEntity();
|
||||
entity.Guid= Guid.NewGuid().ToString();
|
||||
entity.ChapterGuid = paragraph.ChapterGuid;
|
||||
entity.ParagraphGuid = paragraph.Guid;
|
||||
entity.ParagraphIndex = paragraph.ParagraphIndex;
|
||||
entity.OrderIndex = orderIndex++;
|
||||
entity.PersonName = name;
|
||||
aiChapterPersonEntities.Add(entity);
|
||||
}
|
||||
}
|
||||
|
||||
if (aiChapterPersonEntities != null && aiChapterPersonEntities.Count() > 0)
|
||||
repositoryAiChapterPersonEntity.InsertNow(aiChapterPersonEntities);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,9 @@
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.ML" Version="5.0.0" />
|
||||
<PackageReference Include="Microsoft.ML.OnnxRuntime" Version="1.26.0" />
|
||||
<PackageReference Include="Microsoft.ML.OnnxTransformer" Version="5.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Reference in new issue
Block a user