From bd2a66a2419973e91b87eecd0e96060a6d060a7b Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Wed, 17 Dec 2025 17:50:02 -0600 Subject: [PATCH 1/2] Rename NER --- .../BotSharp.Abstraction/NER/INERAnalyzer.cs | 11 +++++ .../INERDataLoader.cs} | 4 +- .../Models/NEROptions.cs} | 4 +- .../Models/NERResult.cs} | 4 +- .../NER/Responses/NERResponse.cs | 8 ++++ .../Tokenizers/ITokenizer.cs | 11 ----- .../Tokenizers/Responses/TokenizeResponse.cs | 8 ---- .../KnowledgeBaseController.Document.cs | 4 +- .../KnowledgeBaseController.NER.cs | 46 ++++++++++++++++++ .../KnowledgeBaseController.Tokenizer.cs | 48 ------------------- src/Infrastructure/BotSharp.OpenAPI/Using.cs | 4 ++ ...kenizeRequest.cs => NERAnalysisRequest.cs} | 6 +-- .../FuzzySharpPlugin.cs | 4 +- ...TokenDataLoader.cs => CsvNERDataLoader.cs} | 8 ++-- ...pTokenizer.cs => FuzzySharpNERAnalyzer.cs} | 25 +++++----- .../BotSharp.Plugin.FuzzySharp/Using.cs | 6 +-- 16 files changed, 100 insertions(+), 101 deletions(-) create mode 100644 src/Infrastructure/BotSharp.Abstraction/NER/INERAnalyzer.cs rename src/Infrastructure/BotSharp.Abstraction/{Tokenizers/ITokenDataLoader.cs => NER/INERDataLoader.cs} (86%) rename src/Infrastructure/BotSharp.Abstraction/{Tokenizers/Models/TokenizeOptions.cs => NER/Models/NEROptions.cs} (91%) rename src/Infrastructure/BotSharp.Abstraction/{Tokenizers/Models/TokenizeResult.cs => NER/Models/NERResult.cs} (77%) create mode 100644 src/Infrastructure/BotSharp.Abstraction/NER/Responses/NERResponse.cs delete mode 100644 src/Infrastructure/BotSharp.Abstraction/Tokenizers/ITokenizer.cs delete mode 100644 src/Infrastructure/BotSharp.Abstraction/Tokenizers/Responses/TokenizeResponse.cs create mode 100644 src/Infrastructure/BotSharp.OpenAPI/Controllers/KnowledgeBase/KnowledgeBaseController.NER.cs delete mode 100644 src/Infrastructure/BotSharp.OpenAPI/Controllers/KnowledgeBase/KnowledgeBaseController.Tokenizer.cs rename src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/Request/{TokenizeRequest.cs => NERAnalysisRequest.cs} (54%) rename src/Plugins/BotSharp.Plugin.FuzzySharp/Services/DataLoaders/{CsvTokenDataLoader.cs => CsvNERDataLoader.cs} (97%) rename src/Plugins/BotSharp.Plugin.FuzzySharp/Services/{FuzzySharpTokenizer.cs => FuzzySharpNERAnalyzer.cs} (91%) diff --git a/src/Infrastructure/BotSharp.Abstraction/NER/INERAnalyzer.cs b/src/Infrastructure/BotSharp.Abstraction/NER/INERAnalyzer.cs new file mode 100644 index 000000000..b5795106d --- /dev/null +++ b/src/Infrastructure/BotSharp.Abstraction/NER/INERAnalyzer.cs @@ -0,0 +1,11 @@ +using BotSharp.Abstraction.NER.Models; +using BotSharp.Abstraction.NER.Responses; + +namespace BotSharp.Abstraction.NER; + +public interface INERAnalyzer +{ + string Provider { get; } + + Task AnalyzeAsync(string text, NEROptions? options = null); +} diff --git a/src/Infrastructure/BotSharp.Abstraction/Tokenizers/ITokenDataLoader.cs b/src/Infrastructure/BotSharp.Abstraction/NER/INERDataLoader.cs similarity index 86% rename from src/Infrastructure/BotSharp.Abstraction/Tokenizers/ITokenDataLoader.cs rename to src/Infrastructure/BotSharp.Abstraction/NER/INERDataLoader.cs index 745dfd914..2eb5a6ac9 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Tokenizers/ITokenDataLoader.cs +++ b/src/Infrastructure/BotSharp.Abstraction/NER/INERDataLoader.cs @@ -1,6 +1,6 @@ -namespace BotSharp.Abstraction.Tokenizers; +namespace BotSharp.Abstraction.NER; -public interface ITokenDataLoader +public interface INERDataLoader { string Provider { get; } diff --git a/src/Infrastructure/BotSharp.Abstraction/Tokenizers/Models/TokenizeOptions.cs b/src/Infrastructure/BotSharp.Abstraction/NER/Models/NEROptions.cs similarity index 91% rename from src/Infrastructure/BotSharp.Abstraction/Tokenizers/Models/TokenizeOptions.cs rename to src/Infrastructure/BotSharp.Abstraction/NER/Models/NEROptions.cs index 1f1c70f25..4b090d675 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Tokenizers/Models/TokenizeOptions.cs +++ b/src/Infrastructure/BotSharp.Abstraction/NER/Models/NEROptions.cs @@ -1,6 +1,6 @@ -namespace BotSharp.Abstraction.Tokenizers.Models; +namespace BotSharp.Abstraction.NER.Models; -public class TokenizeOptions +public class NEROptions { /// /// Token data providers diff --git a/src/Infrastructure/BotSharp.Abstraction/Tokenizers/Models/TokenizeResult.cs b/src/Infrastructure/BotSharp.Abstraction/NER/Models/NERResult.cs similarity index 77% rename from src/Infrastructure/BotSharp.Abstraction/Tokenizers/Models/TokenizeResult.cs rename to src/Infrastructure/BotSharp.Abstraction/NER/Models/NERResult.cs index a02a716d2..acd430b65 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Tokenizers/Models/TokenizeResult.cs +++ b/src/Infrastructure/BotSharp.Abstraction/NER/Models/NERResult.cs @@ -1,6 +1,6 @@ -namespace BotSharp.Abstraction.Tokenizers.Models; +namespace BotSharp.Abstraction.NER.Models; -public class TokenizeResult +public class NERResult { public string Token { get; set; } = string.Empty; diff --git a/src/Infrastructure/BotSharp.Abstraction/NER/Responses/NERResponse.cs b/src/Infrastructure/BotSharp.Abstraction/NER/Responses/NERResponse.cs new file mode 100644 index 000000000..b59600f6b --- /dev/null +++ b/src/Infrastructure/BotSharp.Abstraction/NER/Responses/NERResponse.cs @@ -0,0 +1,8 @@ +using BotSharp.Abstraction.NER.Models; + +namespace BotSharp.Abstraction.NER.Responses; + +public class NERResponse : ResponseBase +{ + public List Results { get; set; } = []; +} diff --git a/src/Infrastructure/BotSharp.Abstraction/Tokenizers/ITokenizer.cs b/src/Infrastructure/BotSharp.Abstraction/Tokenizers/ITokenizer.cs deleted file mode 100644 index b13663899..000000000 --- a/src/Infrastructure/BotSharp.Abstraction/Tokenizers/ITokenizer.cs +++ /dev/null @@ -1,11 +0,0 @@ -using BotSharp.Abstraction.Tokenizers.Models; -using BotSharp.Abstraction.Tokenizers.Responses; - -namespace BotSharp.Abstraction.Tokenizers; - -public interface ITokenizer -{ - string Provider { get; } - - Task TokenizeAsync(string text, TokenizeOptions? options = null); -} diff --git a/src/Infrastructure/BotSharp.Abstraction/Tokenizers/Responses/TokenizeResponse.cs b/src/Infrastructure/BotSharp.Abstraction/Tokenizers/Responses/TokenizeResponse.cs deleted file mode 100644 index e01fe153f..000000000 --- a/src/Infrastructure/BotSharp.Abstraction/Tokenizers/Responses/TokenizeResponse.cs +++ /dev/null @@ -1,8 +0,0 @@ -using BotSharp.Abstraction.Tokenizers.Models; - -namespace BotSharp.Abstraction.Tokenizers.Responses; - -public class TokenizeResponse : ResponseBase -{ - public List Results { get; set; } = []; -} diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/KnowledgeBase/KnowledgeBaseController.Document.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/KnowledgeBase/KnowledgeBaseController.Document.cs index 7411e98b9..cdd91c2dd 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/KnowledgeBase/KnowledgeBaseController.Document.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/KnowledgeBase/KnowledgeBaseController.Document.cs @@ -9,8 +9,8 @@ namespace BotSharp.OpenAPI.Controllers; public partial class KnowledgeBaseController { #region Document - [HttpGet("/knowledge/document/processors")] - public IEnumerable GetKnowledgeDocumentProcessors() + [HttpGet("/knowledge/processors")] + public IEnumerable GetKnowledgeProcessors() { return _services.GetServices().Select(x => x.Provider); } diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/KnowledgeBase/KnowledgeBaseController.NER.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/KnowledgeBase/KnowledgeBaseController.NER.cs new file mode 100644 index 000000000..f856fcb7a --- /dev/null +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/KnowledgeBase/KnowledgeBaseController.NER.cs @@ -0,0 +1,46 @@ +using BotSharp.OpenAPI.ViewModels.Knowledges; + +namespace BotSharp.OpenAPI.Controllers; + +public partial class KnowledgeBaseController +{ + /// + /// NER analyis with options + /// + /// + /// + [HttpPost("knowledge/NER/analyze")] + public async Task NERAnalyze([FromBody] NERAnalysisRequest request) + { + var analyzer = _services.GetServices() + .FirstOrDefault(x => x.Provider.IsEqualTo(request.Provider)); + + if (analyzer == null) + { + return null; + } + return await analyzer.AnalyzeAsync(request.Text, request.Options); + } + + /// + /// Get NER analyzers + /// + /// + [HttpGet("knowledge/NER/analyzers")] + public IEnumerable GetNERAnalyzers() + { + var analyzers = _services.GetServices(); + return analyzers.Select(x => x.Provider); + } + + /// + /// Get NER data providers + /// + /// + [HttpGet("knowledge/NER/data-providers")] + public IEnumerable GetNERDataProviders() + { + var dataLoaders = _services.GetServices(); + return dataLoaders.Select(x => x.Provider); + } +} diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/KnowledgeBase/KnowledgeBaseController.Tokenizer.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/KnowledgeBase/KnowledgeBaseController.Tokenizer.cs deleted file mode 100644 index 08f7812fc..000000000 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/KnowledgeBase/KnowledgeBaseController.Tokenizer.cs +++ /dev/null @@ -1,48 +0,0 @@ -using BotSharp.Abstraction.Tokenizers; -using BotSharp.Abstraction.Tokenizers.Responses; -using BotSharp.OpenAPI.ViewModels.Knowledges; - -namespace BotSharp.OpenAPI.Controllers; - -public partial class KnowledgeBaseController -{ - /// - /// Tokenize text with options - /// - /// - /// - [HttpPost("knowledge/tokenize")] - public async Task Tokenize([FromBody] TokenizeRequest request) - { - var tokenizer = _services.GetServices() - .FirstOrDefault(x => x.Provider.IsEqualTo(request.Provider)); - - if (tokenizer == null) - { - return null; - } - return await tokenizer.TokenizeAsync(request.Text, request.Options); - } - - /// - /// Get tokenizer providers - /// - /// - [HttpGet("knowledge/tokenizer/providers")] - public IEnumerable GetTokenizerProviders() - { - var tokenizers = _services.GetServices(); - return tokenizers.Select(x => x.Provider); - } - - /// - /// Get token data loader providers - /// - /// - [HttpGet("knowledge/tokenizer/data-providers")] - public IEnumerable GetTokenizerDataProviders() - { - var dataLoaders = _services.GetServices(); - return dataLoaders.Select(x => x.Provider); - } -} diff --git a/src/Infrastructure/BotSharp.OpenAPI/Using.cs b/src/Infrastructure/BotSharp.OpenAPI/Using.cs index ea5f9f7cc..37890314b 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Using.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Using.cs @@ -29,6 +29,10 @@ global using BotSharp.Abstraction.VectorStorage.Enums; global using BotSharp.Abstraction.Knowledges.Models; global using BotSharp.Abstraction.Chart.Models; +global using BotSharp.Abstraction.NER; +global using BotSharp.Abstraction.NER.Models; +global using BotSharp.Abstraction.NER.Responses; + global using BotSharp.OpenAPI.ViewModels.Conversations; global using BotSharp.OpenAPI.ViewModels.Users; global using BotSharp.OpenAPI.ViewModels.Agents; diff --git a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/Request/TokenizeRequest.cs b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/Request/NERAnalysisRequest.cs similarity index 54% rename from src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/Request/TokenizeRequest.cs rename to src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/Request/NERAnalysisRequest.cs index 125013d0d..31b792eae 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/Request/TokenizeRequest.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/Request/NERAnalysisRequest.cs @@ -1,10 +1,8 @@ -using BotSharp.Abstraction.Tokenizers.Models; - namespace BotSharp.OpenAPI.ViewModels.Knowledges; -public class TokenizeRequest +public class NERAnalysisRequest { public string Text { get; set; } = string.Empty; public string? Provider { get; set; } - public TokenizeOptions? Options { get; set; } + public NEROptions? Options { get; set; } } diff --git a/src/Plugins/BotSharp.Plugin.FuzzySharp/FuzzySharpPlugin.cs b/src/Plugins/BotSharp.Plugin.FuzzySharp/FuzzySharpPlugin.cs index fc1a75326..c0b31a661 100644 --- a/src/Plugins/BotSharp.Plugin.FuzzySharp/FuzzySharpPlugin.cs +++ b/src/Plugins/BotSharp.Plugin.FuzzySharp/FuzzySharpPlugin.cs @@ -19,8 +19,8 @@ public void RegisterDI(IServiceCollection services, IConfiguration config) services.AddScoped(); services.AddScoped(); - services.AddScoped(); - services.AddScoped(); + services.AddScoped(); + services.AddScoped(); services.AddScoped(); services.AddScoped(); diff --git a/src/Plugins/BotSharp.Plugin.FuzzySharp/Services/DataLoaders/CsvTokenDataLoader.cs b/src/Plugins/BotSharp.Plugin.FuzzySharp/Services/DataLoaders/CsvNERDataLoader.cs similarity index 97% rename from src/Plugins/BotSharp.Plugin.FuzzySharp/Services/DataLoaders/CsvTokenDataLoader.cs rename to src/Plugins/BotSharp.Plugin.FuzzySharp/Services/DataLoaders/CsvNERDataLoader.cs index beca5c6b3..90c0bc6e7 100644 --- a/src/Plugins/BotSharp.Plugin.FuzzySharp/Services/DataLoaders/CsvTokenDataLoader.cs +++ b/src/Plugins/BotSharp.Plugin.FuzzySharp/Services/DataLoaders/CsvNERDataLoader.cs @@ -8,14 +8,14 @@ namespace BotSharp.Plugin.FuzzySharp.Services.DataLoaders; -public class CsvTokenDataLoader : ITokenDataLoader +public class CsvNERDataLoader : INERDataLoader { - private readonly ILogger _logger; + private readonly ILogger _logger; private readonly FuzzySharpSettings _settings; private readonly string _basePath; - public CsvTokenDataLoader( - ILogger logger, + public CsvNERDataLoader( + ILogger logger, FuzzySharpSettings settings) { _settings = settings; diff --git a/src/Plugins/BotSharp.Plugin.FuzzySharp/Services/FuzzySharpTokenizer.cs b/src/Plugins/BotSharp.Plugin.FuzzySharp/Services/FuzzySharpNERAnalyzer.cs similarity index 91% rename from src/Plugins/BotSharp.Plugin.FuzzySharp/Services/FuzzySharpTokenizer.cs rename to src/Plugins/BotSharp.Plugin.FuzzySharp/Services/FuzzySharpNERAnalyzer.cs index 863cda1b0..c3e3f75cc 100644 --- a/src/Plugins/BotSharp.Plugin.FuzzySharp/Services/FuzzySharpTokenizer.cs +++ b/src/Plugins/BotSharp.Plugin.FuzzySharp/Services/FuzzySharpNERAnalyzer.cs @@ -3,16 +3,16 @@ namespace BotSharp.Plugin.FuzzySharp.Services; -public class FuzzySharpTokenizer : ITokenizer +public class FuzzySharpNERAnalyzer : INERAnalyzer { - private readonly ILogger _logger; - private readonly IEnumerable _tokenDataLoaders; + private readonly ILogger _logger; + private readonly IEnumerable _tokenDataLoaders; private readonly INgramProcessor _ngramProcessor; private readonly IResultProcessor _resultProcessor; - public FuzzySharpTokenizer( - ILogger logger, - IEnumerable tokenDataLoaders, + public FuzzySharpNERAnalyzer( + ILogger logger, + IEnumerable tokenDataLoaders, INgramProcessor ngramProcessor, IResultProcessor resultProcessor) { @@ -24,18 +24,17 @@ public FuzzySharpTokenizer( public string Provider => "fuzzy-sharp"; - public async Task TokenizeAsync(string text, TokenizeOptions? options = null) + public async Task AnalyzeAsync(string text, NEROptions? options = null) { - var response = new TokenizeResponse(); + var response = new NERResponse(); try { var result = await AnalyzeTextAsync(text, options); - - return new TokenizeResponse + return new NERResponse { Success = true, - Results = result?.FlaggedItems?.Select(f => new TokenizeResult + Results = result?.FlaggedItems?.Select(f => new NERResult { Token = f.Token, CanonicalText = f.CanonicalForm, @@ -59,7 +58,7 @@ public async Task TokenizeAsync(string text, TokenizeOptions? /// /// Analyze text for typos and entities using domain-specific vocabulary /// - private async Task AnalyzeTextAsync(string text, TokenizeOptions? options = null) + private async Task AnalyzeTextAsync(string text, NEROptions? options = null) { var stopwatch = Stopwatch.StartNew(); try @@ -148,7 +147,7 @@ private List AnalyzeTokens( List tokens, Dictionary> vocabulary, Dictionary synonymMapping, - TokenizeOptions? options) + NEROptions? options) { // Build lookup table for O(1) exact match lookups (matching Python's build_lookup) var lookup = BuildLookup(vocabulary); diff --git a/src/Plugins/BotSharp.Plugin.FuzzySharp/Using.cs b/src/Plugins/BotSharp.Plugin.FuzzySharp/Using.cs index 9a6ec03d5..679113e33 100644 --- a/src/Plugins/BotSharp.Plugin.FuzzySharp/Using.cs +++ b/src/Plugins/BotSharp.Plugin.FuzzySharp/Using.cs @@ -4,9 +4,9 @@ global using System.Text; global using System.Threading.Tasks; -global using BotSharp.Abstraction.Tokenizers; -global using BotSharp.Abstraction.Tokenizers.Models; -global using BotSharp.Abstraction.Tokenizers.Responses; +global using BotSharp.Abstraction.NER; +global using BotSharp.Abstraction.NER.Models; +global using BotSharp.Abstraction.NER.Responses; global using BotSharp.Plugin.FuzzySharp.Models; global using BotSharp.Plugin.FuzzySharp.Utils; From 6bfc3f43c609a9d95b57add200e0dc774781f712 Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Wed, 17 Dec 2025 18:04:50 -0600 Subject: [PATCH 2/2] rename --- .../Entity/IEntityAnalyzer.cs | 11 +++++++++ .../IEntityDataLoader.cs} | 4 ++-- .../Models/EntityAnalysisOptions.cs} | 4 ++-- .../Models/EntityAnalysisResult.cs} | 4 ++-- .../Responses/EntityAnalysisResponse.cs | 8 +++++++ .../BotSharp.Abstraction/NER/INERAnalyzer.cs | 11 --------- .../NER/Responses/NERResponse.cs | 8 ------- ...R.cs => KnowledgeBaseController.Entity.cs} | 24 +++++++++---------- src/Infrastructure/BotSharp.OpenAPI/Using.cs | 6 ++--- ...sisRequest.cs => EntityAnalysisRequest.cs} | 4 ++-- .../FuzzySharpPlugin.cs | 4 ++-- .../Services/DataLoaders/CsvNERDataLoader.cs | 2 +- ...nalyzer.cs => FuzzySharpEntityAnalyzer.cs} | 24 +++++++++---------- .../BotSharp.Plugin.FuzzySharp/Using.cs | 6 ++--- 14 files changed, 60 insertions(+), 60 deletions(-) create mode 100644 src/Infrastructure/BotSharp.Abstraction/Entity/IEntityAnalyzer.cs rename src/Infrastructure/BotSharp.Abstraction/{NER/INERDataLoader.cs => Entity/IEntityDataLoader.cs} (87%) rename src/Infrastructure/BotSharp.Abstraction/{NER/Models/NEROptions.cs => Entity/Models/EntityAnalysisOptions.cs} (91%) rename src/Infrastructure/BotSharp.Abstraction/{NER/Models/NERResult.cs => Entity/Models/EntityAnalysisResult.cs} (77%) create mode 100644 src/Infrastructure/BotSharp.Abstraction/Entity/Responses/EntityAnalysisResponse.cs delete mode 100644 src/Infrastructure/BotSharp.Abstraction/NER/INERAnalyzer.cs delete mode 100644 src/Infrastructure/BotSharp.Abstraction/NER/Responses/NERResponse.cs rename src/Infrastructure/BotSharp.OpenAPI/Controllers/KnowledgeBase/{KnowledgeBaseController.NER.cs => KnowledgeBaseController.Entity.cs} (53%) rename src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/Request/{NERAnalysisRequest.cs => EntityAnalysisRequest.cs} (62%) rename src/Plugins/BotSharp.Plugin.FuzzySharp/Services/{FuzzySharpNERAnalyzer.cs => FuzzySharpEntityAnalyzer.cs} (90%) diff --git a/src/Infrastructure/BotSharp.Abstraction/Entity/IEntityAnalyzer.cs b/src/Infrastructure/BotSharp.Abstraction/Entity/IEntityAnalyzer.cs new file mode 100644 index 000000000..ca6a8680c --- /dev/null +++ b/src/Infrastructure/BotSharp.Abstraction/Entity/IEntityAnalyzer.cs @@ -0,0 +1,11 @@ +using BotSharp.Abstraction.Entity.Models; +using BotSharp.Abstraction.Entity.Responses; + +namespace BotSharp.Abstraction.Entity; + +public interface IEntityAnalyzer +{ + string Provider { get; } + + Task AnalyzeAsync(string text, EntityAnalysisOptions? options = null); +} diff --git a/src/Infrastructure/BotSharp.Abstraction/NER/INERDataLoader.cs b/src/Infrastructure/BotSharp.Abstraction/Entity/IEntityDataLoader.cs similarity index 87% rename from src/Infrastructure/BotSharp.Abstraction/NER/INERDataLoader.cs rename to src/Infrastructure/BotSharp.Abstraction/Entity/IEntityDataLoader.cs index 2eb5a6ac9..caf8fe227 100644 --- a/src/Infrastructure/BotSharp.Abstraction/NER/INERDataLoader.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Entity/IEntityDataLoader.cs @@ -1,6 +1,6 @@ -namespace BotSharp.Abstraction.NER; +namespace BotSharp.Abstraction.Entity; -public interface INERDataLoader +public interface IEntityDataLoader { string Provider { get; } diff --git a/src/Infrastructure/BotSharp.Abstraction/NER/Models/NEROptions.cs b/src/Infrastructure/BotSharp.Abstraction/Entity/Models/EntityAnalysisOptions.cs similarity index 91% rename from src/Infrastructure/BotSharp.Abstraction/NER/Models/NEROptions.cs rename to src/Infrastructure/BotSharp.Abstraction/Entity/Models/EntityAnalysisOptions.cs index 4b090d675..b0e08dc63 100644 --- a/src/Infrastructure/BotSharp.Abstraction/NER/Models/NEROptions.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Entity/Models/EntityAnalysisOptions.cs @@ -1,6 +1,6 @@ -namespace BotSharp.Abstraction.NER.Models; +namespace BotSharp.Abstraction.Entity.Models; -public class NEROptions +public class EntityAnalysisOptions { /// /// Token data providers diff --git a/src/Infrastructure/BotSharp.Abstraction/NER/Models/NERResult.cs b/src/Infrastructure/BotSharp.Abstraction/Entity/Models/EntityAnalysisResult.cs similarity index 77% rename from src/Infrastructure/BotSharp.Abstraction/NER/Models/NERResult.cs rename to src/Infrastructure/BotSharp.Abstraction/Entity/Models/EntityAnalysisResult.cs index acd430b65..c760456ca 100644 --- a/src/Infrastructure/BotSharp.Abstraction/NER/Models/NERResult.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Entity/Models/EntityAnalysisResult.cs @@ -1,6 +1,6 @@ -namespace BotSharp.Abstraction.NER.Models; +namespace BotSharp.Abstraction.Entity.Models; -public class NERResult +public class EntityAnalysisResult { public string Token { get; set; } = string.Empty; diff --git a/src/Infrastructure/BotSharp.Abstraction/Entity/Responses/EntityAnalysisResponse.cs b/src/Infrastructure/BotSharp.Abstraction/Entity/Responses/EntityAnalysisResponse.cs new file mode 100644 index 000000000..143e24f64 --- /dev/null +++ b/src/Infrastructure/BotSharp.Abstraction/Entity/Responses/EntityAnalysisResponse.cs @@ -0,0 +1,8 @@ +using BotSharp.Abstraction.Entity.Models; + +namespace BotSharp.Abstraction.Entity.Responses; + +public class EntityAnalysisResponse : ResponseBase +{ + public List Results { get; set; } = []; +} diff --git a/src/Infrastructure/BotSharp.Abstraction/NER/INERAnalyzer.cs b/src/Infrastructure/BotSharp.Abstraction/NER/INERAnalyzer.cs deleted file mode 100644 index b5795106d..000000000 --- a/src/Infrastructure/BotSharp.Abstraction/NER/INERAnalyzer.cs +++ /dev/null @@ -1,11 +0,0 @@ -using BotSharp.Abstraction.NER.Models; -using BotSharp.Abstraction.NER.Responses; - -namespace BotSharp.Abstraction.NER; - -public interface INERAnalyzer -{ - string Provider { get; } - - Task AnalyzeAsync(string text, NEROptions? options = null); -} diff --git a/src/Infrastructure/BotSharp.Abstraction/NER/Responses/NERResponse.cs b/src/Infrastructure/BotSharp.Abstraction/NER/Responses/NERResponse.cs deleted file mode 100644 index b59600f6b..000000000 --- a/src/Infrastructure/BotSharp.Abstraction/NER/Responses/NERResponse.cs +++ /dev/null @@ -1,8 +0,0 @@ -using BotSharp.Abstraction.NER.Models; - -namespace BotSharp.Abstraction.NER.Responses; - -public class NERResponse : ResponseBase -{ - public List Results { get; set; } = []; -} diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/KnowledgeBase/KnowledgeBaseController.NER.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/KnowledgeBase/KnowledgeBaseController.Entity.cs similarity index 53% rename from src/Infrastructure/BotSharp.OpenAPI/Controllers/KnowledgeBase/KnowledgeBaseController.NER.cs rename to src/Infrastructure/BotSharp.OpenAPI/Controllers/KnowledgeBase/KnowledgeBaseController.Entity.cs index f856fcb7a..266155539 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/KnowledgeBase/KnowledgeBaseController.NER.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/KnowledgeBase/KnowledgeBaseController.Entity.cs @@ -5,14 +5,14 @@ namespace BotSharp.OpenAPI.Controllers; public partial class KnowledgeBaseController { /// - /// NER analyis with options + /// Entity analyis with options /// /// /// - [HttpPost("knowledge/NER/analyze")] - public async Task NERAnalyze([FromBody] NERAnalysisRequest request) + [HttpPost("knowledge/entity/analyze")] + public async Task EntityAnalyze([FromBody] EntityAnalysisRequest request) { - var analyzer = _services.GetServices() + var analyzer = _services.GetServices() .FirstOrDefault(x => x.Provider.IsEqualTo(request.Provider)); if (analyzer == null) @@ -23,24 +23,24 @@ public partial class KnowledgeBaseController } /// - /// Get NER analyzers + /// Get entity analyzers /// /// - [HttpGet("knowledge/NER/analyzers")] - public IEnumerable GetNERAnalyzers() + [HttpGet("knowledge/entity/analyzers")] + public IEnumerable GetEntityAnalyzers() { - var analyzers = _services.GetServices(); + var analyzers = _services.GetServices(); return analyzers.Select(x => x.Provider); } /// - /// Get NER data providers + /// Get entity data providers /// /// - [HttpGet("knowledge/NER/data-providers")] - public IEnumerable GetNERDataProviders() + [HttpGet("knowledge/entity/data-providers")] + public IEnumerable GetEntityDataProviders() { - var dataLoaders = _services.GetServices(); + var dataLoaders = _services.GetServices(); return dataLoaders.Select(x => x.Provider); } } diff --git a/src/Infrastructure/BotSharp.OpenAPI/Using.cs b/src/Infrastructure/BotSharp.OpenAPI/Using.cs index 37890314b..d811452ee 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Using.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Using.cs @@ -29,9 +29,9 @@ global using BotSharp.Abstraction.VectorStorage.Enums; global using BotSharp.Abstraction.Knowledges.Models; global using BotSharp.Abstraction.Chart.Models; -global using BotSharp.Abstraction.NER; -global using BotSharp.Abstraction.NER.Models; -global using BotSharp.Abstraction.NER.Responses; +global using BotSharp.Abstraction.Entity; +global using BotSharp.Abstraction.Entity.Models; +global using BotSharp.Abstraction.Entity.Responses; global using BotSharp.OpenAPI.ViewModels.Conversations; global using BotSharp.OpenAPI.ViewModels.Users; diff --git a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/Request/NERAnalysisRequest.cs b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/Request/EntityAnalysisRequest.cs similarity index 62% rename from src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/Request/NERAnalysisRequest.cs rename to src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/Request/EntityAnalysisRequest.cs index 31b792eae..890113448 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/Request/NERAnalysisRequest.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/Request/EntityAnalysisRequest.cs @@ -1,8 +1,8 @@ namespace BotSharp.OpenAPI.ViewModels.Knowledges; -public class NERAnalysisRequest +public class EntityAnalysisRequest { public string Text { get; set; } = string.Empty; public string? Provider { get; set; } - public NEROptions? Options { get; set; } + public EntityAnalysisOptions? Options { get; set; } } diff --git a/src/Plugins/BotSharp.Plugin.FuzzySharp/FuzzySharpPlugin.cs b/src/Plugins/BotSharp.Plugin.FuzzySharp/FuzzySharpPlugin.cs index c0b31a661..cc6f3e8f1 100644 --- a/src/Plugins/BotSharp.Plugin.FuzzySharp/FuzzySharpPlugin.cs +++ b/src/Plugins/BotSharp.Plugin.FuzzySharp/FuzzySharpPlugin.cs @@ -19,8 +19,8 @@ public void RegisterDI(IServiceCollection services, IConfiguration config) services.AddScoped(); services.AddScoped(); - services.AddScoped(); - services.AddScoped(); + services.AddScoped(); + services.AddScoped(); services.AddScoped(); services.AddScoped(); diff --git a/src/Plugins/BotSharp.Plugin.FuzzySharp/Services/DataLoaders/CsvNERDataLoader.cs b/src/Plugins/BotSharp.Plugin.FuzzySharp/Services/DataLoaders/CsvNERDataLoader.cs index 90c0bc6e7..1e1c2b949 100644 --- a/src/Plugins/BotSharp.Plugin.FuzzySharp/Services/DataLoaders/CsvNERDataLoader.cs +++ b/src/Plugins/BotSharp.Plugin.FuzzySharp/Services/DataLoaders/CsvNERDataLoader.cs @@ -8,7 +8,7 @@ namespace BotSharp.Plugin.FuzzySharp.Services.DataLoaders; -public class CsvNERDataLoader : INERDataLoader +public class CsvNERDataLoader : IEntityDataLoader { private readonly ILogger _logger; private readonly FuzzySharpSettings _settings; diff --git a/src/Plugins/BotSharp.Plugin.FuzzySharp/Services/FuzzySharpNERAnalyzer.cs b/src/Plugins/BotSharp.Plugin.FuzzySharp/Services/FuzzySharpEntityAnalyzer.cs similarity index 90% rename from src/Plugins/BotSharp.Plugin.FuzzySharp/Services/FuzzySharpNERAnalyzer.cs rename to src/Plugins/BotSharp.Plugin.FuzzySharp/Services/FuzzySharpEntityAnalyzer.cs index c3e3f75cc..f17afafe4 100644 --- a/src/Plugins/BotSharp.Plugin.FuzzySharp/Services/FuzzySharpNERAnalyzer.cs +++ b/src/Plugins/BotSharp.Plugin.FuzzySharp/Services/FuzzySharpEntityAnalyzer.cs @@ -3,16 +3,16 @@ namespace BotSharp.Plugin.FuzzySharp.Services; -public class FuzzySharpNERAnalyzer : INERAnalyzer +public class FuzzySharpEntityAnalyzer : IEntityAnalyzer { - private readonly ILogger _logger; - private readonly IEnumerable _tokenDataLoaders; + private readonly ILogger _logger; + private readonly IEnumerable _tokenDataLoaders; private readonly INgramProcessor _ngramProcessor; private readonly IResultProcessor _resultProcessor; - public FuzzySharpNERAnalyzer( - ILogger logger, - IEnumerable tokenDataLoaders, + public FuzzySharpEntityAnalyzer( + ILogger logger, + IEnumerable tokenDataLoaders, INgramProcessor ngramProcessor, IResultProcessor resultProcessor) { @@ -24,17 +24,17 @@ public FuzzySharpNERAnalyzer( public string Provider => "fuzzy-sharp"; - public async Task AnalyzeAsync(string text, NEROptions? options = null) + public async Task AnalyzeAsync(string text, EntityAnalysisOptions? options = null) { - var response = new NERResponse(); + var response = new EntityAnalysisResponse(); try { var result = await AnalyzeTextAsync(text, options); - return new NERResponse + return new EntityAnalysisResponse { Success = true, - Results = result?.FlaggedItems?.Select(f => new NERResult + Results = result?.FlaggedItems?.Select(f => new EntityAnalysisResult { Token = f.Token, CanonicalText = f.CanonicalForm, @@ -58,7 +58,7 @@ public async Task AnalyzeAsync(string text, NEROptions? options = n /// /// Analyze text for typos and entities using domain-specific vocabulary /// - private async Task AnalyzeTextAsync(string text, NEROptions? options = null) + private async Task AnalyzeTextAsync(string text, EntityAnalysisOptions? options = null) { var stopwatch = Stopwatch.StartNew(); try @@ -147,7 +147,7 @@ private List AnalyzeTokens( List tokens, Dictionary> vocabulary, Dictionary synonymMapping, - NEROptions? options) + EntityAnalysisOptions? options) { // Build lookup table for O(1) exact match lookups (matching Python's build_lookup) var lookup = BuildLookup(vocabulary); diff --git a/src/Plugins/BotSharp.Plugin.FuzzySharp/Using.cs b/src/Plugins/BotSharp.Plugin.FuzzySharp/Using.cs index 679113e33..776965b5e 100644 --- a/src/Plugins/BotSharp.Plugin.FuzzySharp/Using.cs +++ b/src/Plugins/BotSharp.Plugin.FuzzySharp/Using.cs @@ -4,9 +4,9 @@ global using System.Text; global using System.Threading.Tasks; -global using BotSharp.Abstraction.NER; -global using BotSharp.Abstraction.NER.Models; -global using BotSharp.Abstraction.NER.Responses; +global using BotSharp.Abstraction.Entity; +global using BotSharp.Abstraction.Entity.Models; +global using BotSharp.Abstraction.Entity.Responses; global using BotSharp.Plugin.FuzzySharp.Models; global using BotSharp.Plugin.FuzzySharp.Utils;