add: 修改部分注释
This commit is contained in:
		@@ -5,11 +5,27 @@ namespace Katheryne.Abstractions;
 | 
				
			|||||||
/// </summary>
 | 
					/// </summary>
 | 
				
			||||||
public interface IChatRobot
 | 
					public interface IChatRobot
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					    /// <summary>
 | 
				
			||||||
 | 
					    /// 定义机器人的名称
 | 
				
			||||||
 | 
					    /// </summary>
 | 
				
			||||||
    public string RobotName { get; }
 | 
					    public string RobotName { get; }
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
 | 
					    /// <summary>
 | 
				
			||||||
 | 
					    /// 机器人在启动时输出的对话
 | 
				
			||||||
 | 
					    /// </summary>
 | 
				
			||||||
 | 
					    /// <returns>对话列表</returns>
 | 
				
			||||||
    public IEnumerable<string> OnChatStart();
 | 
					    public IEnumerable<string> OnChatStart();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /// <summary>
 | 
				
			||||||
 | 
					    /// 机器人在结束对话时输出的对话列表
 | 
				
			||||||
 | 
					    /// </summary>
 | 
				
			||||||
 | 
					    /// <returns>对话列表</returns>
 | 
				
			||||||
    public IEnumerable<string> OnChatStop();
 | 
					    public IEnumerable<string> OnChatStop();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /// <summary>
 | 
				
			||||||
 | 
					    /// 机器人在获得用户输入时输出的对话列表
 | 
				
			||||||
 | 
					    /// </summary>
 | 
				
			||||||
 | 
					    /// <param name="input">用户的输入</param>
 | 
				
			||||||
 | 
					    /// <returns>机器人输出的对话列表</returns>
 | 
				
			||||||
    public IEnumerable<string> ChatNext(string input);
 | 
					    public IEnumerable<string> ChatNext(string input);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -3,7 +3,7 @@ using Katheryne.Exceptions;
 | 
				
			|||||||
namespace Katheryne.Abstractions;
 | 
					namespace Katheryne.Abstractions;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// <summary>
 | 
					/// <summary>
 | 
				
			||||||
/// 聊天机器人接口
 | 
					/// 聊天机器人工厂接口
 | 
				
			||||||
/// </summary>
 | 
					/// </summary>
 | 
				
			||||||
public interface IChatRobotFactory
 | 
					public interface IChatRobotFactory
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,9 +5,21 @@ namespace Katheryne.Abstractions;
 | 
				
			|||||||
/// </summary>
 | 
					/// </summary>
 | 
				
			||||||
public interface IParamsModule
 | 
					public interface IParamsModule
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					    /// <summary>
 | 
				
			||||||
 | 
					    /// 模块的名称
 | 
				
			||||||
 | 
					    /// </summary>
 | 
				
			||||||
    public string ModuleName { get; }
 | 
					    public string ModuleName { get; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /// <summary>
 | 
				
			||||||
 | 
					    /// 获得模块中特定指定参数的文本
 | 
				
			||||||
 | 
					    /// </summary>
 | 
				
			||||||
 | 
					    /// <param name="param">指定参数</param>
 | 
				
			||||||
    public string this[string param] { get; }
 | 
					    public string this[string param] { get; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /// <summary>
 | 
				
			||||||
 | 
					    /// 判断模块是否提供指定参数
 | 
				
			||||||
 | 
					    /// </summary>
 | 
				
			||||||
 | 
					    /// <param name="param">指定参数</param>
 | 
				
			||||||
 | 
					    /// <returns>如果为真,说明模块提供该参数,反之没有提供</returns>
 | 
				
			||||||
    public bool ContainsParam(string param);
 | 
					    public bool ContainsParam(string param);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -1,3 +1,8 @@
 | 
				
			|||||||
namespace Katheryne.Models;
 | 
					namespace Katheryne.Models;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/// <summary>
 | 
				
			||||||
 | 
					/// 格式化标记
 | 
				
			||||||
 | 
					/// </summary>
 | 
				
			||||||
 | 
					/// <param name="Value">原始字符串</param>
 | 
				
			||||||
 | 
					/// <param name="Index">在匹配结果中的序号</param>
 | 
				
			||||||
public record FormatTag(string Value, int Index);
 | 
					public record FormatTag(string Value, int Index);
 | 
				
			||||||
@@ -1,3 +1,9 @@
 | 
				
			|||||||
namespace Katheryne.Models;
 | 
					namespace Katheryne.Models;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/// <summary>
 | 
				
			||||||
 | 
					/// 语法中的模块参数
 | 
				
			||||||
 | 
					/// </summary>
 | 
				
			||||||
 | 
					/// <param name="OriginString">原始字符串</param>
 | 
				
			||||||
 | 
					/// <param name="Module">模块名称</param>
 | 
				
			||||||
 | 
					/// <param name="Param">参数</param>
 | 
				
			||||||
public record GrammarParam(string OriginString, string Module, string Param);
 | 
					public record GrammarParam(string OriginString, string Module, string Param);
 | 
				
			||||||
@@ -3,6 +3,9 @@ using Katheryne.Exceptions;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
namespace Katheryne.Models;
 | 
					namespace Katheryne.Models;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/// <summary>
 | 
				
			||||||
 | 
					/// 语法树
 | 
				
			||||||
 | 
					/// </summary>
 | 
				
			||||||
public class GrammarTree
 | 
					public class GrammarTree
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    private readonly Dictionary<string, InnerStage> _stages = new();
 | 
					    private readonly Dictionary<string, InnerStage> _stages = new();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,8 @@
 | 
				
			|||||||
namespace Katheryne.Models;
 | 
					namespace Katheryne.Models;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/// <summary>
 | 
				
			||||||
 | 
					/// 词法模型
 | 
				
			||||||
 | 
					/// </summary>
 | 
				
			||||||
public class LexicalModel
 | 
					public class LexicalModel
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    public required string RobotName { get; set; }
 | 
					    public required string RobotName { get; set; }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -27,10 +27,21 @@ public class StringFormatter
 | 
				
			|||||||
        GetFormatTags();
 | 
					        GetFormatTags();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /// <summary>
 | 
				
			||||||
 | 
					    /// 字符串是否需要进行格式化
 | 
				
			||||||
 | 
					    /// </summary>
 | 
				
			||||||
    public bool IsFormat => _formatTags.Count != 0 || _params.Count != 0;
 | 
					    public bool IsFormat => _formatTags.Count != 0 || _params.Count != 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /// <summary>
 | 
				
			||||||
 | 
					    /// 原始字符串
 | 
				
			||||||
 | 
					    /// </summary>
 | 
				
			||||||
    public string RowString => _originString;
 | 
					    public string RowString => _originString;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /// <summary>
 | 
				
			||||||
 | 
					    /// 格式化字符串
 | 
				
			||||||
 | 
					    /// </summary>
 | 
				
			||||||
 | 
					    /// <param name="collection">正则表达式匹配的结果列表</param>
 | 
				
			||||||
 | 
					    /// <returns>格式化之后的字符串</returns>
 | 
				
			||||||
    public string Format(GroupCollection collection)
 | 
					    public string Format(GroupCollection collection)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        var result = new string(_originString);
 | 
					        var result = new string(_originString);
 | 
				
			||||||
@@ -54,6 +65,10 @@ public class StringFormatter
 | 
				
			|||||||
        return result;
 | 
					        return result;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /// <summary>
 | 
				
			||||||
 | 
					    /// 解析字符串中需要格式化的标签
 | 
				
			||||||
 | 
					    /// </summary>
 | 
				
			||||||
 | 
					    /// <exception cref="GrammarException">文法中调用的模块不存在</exception>
 | 
				
			||||||
    private void GetFormatTags()
 | 
					    private void GetFormatTags()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        List<int> tagIndices = new();
 | 
					        List<int> tagIndices = new();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,6 +3,9 @@ using Katheryne.Abstractions;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
namespace Katheryne.Modules;
 | 
					namespace Katheryne.Modules;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/// <summary>
 | 
				
			||||||
 | 
					/// 参数模块实现基类
 | 
				
			||||||
 | 
					/// </summary>
 | 
				
			||||||
public abstract class ModuleBase : IParamsModule
 | 
					public abstract class ModuleBase : IParamsModule
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    protected readonly Dictionary<string, Func<string>> Functions = new();
 | 
					    protected readonly Dictionary<string, Func<string>> Functions = new();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,6 +4,9 @@ using Katheryne.Exceptions;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
namespace Katheryne.Modules;
 | 
					namespace Katheryne.Modules;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/// <summary>
 | 
				
			||||||
 | 
					/// 提供天气服务的模块
 | 
				
			||||||
 | 
					/// </summary>
 | 
				
			||||||
public class WeatherModule : ModuleBase
 | 
					public class WeatherModule : ModuleBase
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    private static readonly HttpClient s_httpClient = new();
 | 
					    private static readonly HttpClient s_httpClient = new();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,6 +8,9 @@ namespace Katheryne;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
public static class ServiceCollectionExtensions
 | 
					public static class ServiceCollectionExtensions
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					    /// <summary>
 | 
				
			||||||
 | 
					    /// 在服务集合中添加Katheryne DSL解释机器人服务
 | 
				
			||||||
 | 
					    /// </summary>
 | 
				
			||||||
    public static void AddKatheryne(this IServiceCollection collection)
 | 
					    public static void AddKatheryne(this IServiceCollection collection)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        collection.AddSingleton<YamlDeserializerFactory>();
 | 
					        collection.AddSingleton<YamlDeserializerFactory>();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,6 +6,9 @@ using YamlDotNet.Serialization;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
namespace Katheryne.Services;
 | 
					namespace Katheryne.Services;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/// <summary>
 | 
				
			||||||
 | 
					/// Katheryne 聊天机器人工厂实现
 | 
				
			||||||
 | 
					/// </summary>
 | 
				
			||||||
public class KatheryneChatRobotFactory : IChatRobotFactory
 | 
					public class KatheryneChatRobotFactory : IChatRobotFactory
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    private readonly YamlDeserializerFactory _deserializerFactory;
 | 
					    private readonly YamlDeserializerFactory _deserializerFactory;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,6 +3,9 @@ using YamlDotNet.Serialization.NamingConventions;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
namespace Katheryne.Services;
 | 
					namespace Katheryne.Services;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/// <summary>
 | 
				
			||||||
 | 
					/// YAML 反序列化对象工厂
 | 
				
			||||||
 | 
					/// </summary>
 | 
				
			||||||
public class YamlDeserializerFactory
 | 
					public class YamlDeserializerFactory
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    private readonly DeserializerBuilder _builder;
 | 
					    private readonly DeserializerBuilder _builder;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user