From d09da0213e50ba9588f1ce9a28f3fe27bf24d968 Mon Sep 17 00:00:00 2001 From: Mikhalkovich Stanislav Date: Tue, 17 Feb 2026 19:59:28 +0300 Subject: [PATCH] =?UTF-8?q?GetTranslation=20-=20=D1=81=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=B0=D0=BB=20=D0=BF=D1=83=D0=B1=D0=BB=D0=B8=D1=87=D0=BD=D0=BE?= =?UTF-8?q?=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MLExceptions - новый модуль --- Configuration/GlobalAssemblyInfo.cs | 2 +- Configuration/Version.defs | 4 +- Release/pabcversion.txt | 2 +- ReleaseGenerators/PascalABCNET_version.nsh | 2 +- ReleaseGenerators/RebuildStandartModules.pas | 2 +- .../RebuildStandartModulesMono.pas | 3 +- ReleaseGenerators/sect_Core.nsh | 6 +- bin/Lib/MLABC.pas | 8 ++- bin/Lib/MLExceptions.pas | 55 +++++++++++++++++++ bin/Lib/PABCSystem.pas | 45 +-------------- bin/Lib/ValidationML.pas | 11 +++- 11 files changed, 86 insertions(+), 54 deletions(-) create mode 100644 bin/Lib/MLExceptions.pas diff --git a/Configuration/GlobalAssemblyInfo.cs b/Configuration/GlobalAssemblyInfo.cs index 09b6e1cf0..7fe652d0f 100644 --- a/Configuration/GlobalAssemblyInfo.cs +++ b/Configuration/GlobalAssemblyInfo.cs @@ -15,7 +15,7 @@ internal static class RevisionClass public const string Major = "3"; public const string Minor = "11"; public const string Build = "1"; - public const string Revision = "3753"; + public const string Revision = "3756"; public const string MainVersion = Major + "." + Minor; public const string FullVersion = Major + "." + Minor + "." + Build + "." + Revision; diff --git a/Configuration/Version.defs b/Configuration/Version.defs index 4936afea7..90799d7a5 100644 --- a/Configuration/Version.defs +++ b/Configuration/Version.defs @@ -1,4 +1,4 @@ -%MINOR%=11 -%REVISION%=3753 %COREVERSION%=1 +%REVISION%=3756 +%MINOR%=11 %MAJOR%=3 diff --git a/Release/pabcversion.txt b/Release/pabcversion.txt index 968c42b1c..2bb7a7a97 100644 --- a/Release/pabcversion.txt +++ b/Release/pabcversion.txt @@ -1 +1 @@ -3.11.1.3753 +3.11.1.3756 diff --git a/ReleaseGenerators/PascalABCNET_version.nsh b/ReleaseGenerators/PascalABCNET_version.nsh index 747eb5cbe..e0d4ef132 100644 --- a/ReleaseGenerators/PascalABCNET_version.nsh +++ b/ReleaseGenerators/PascalABCNET_version.nsh @@ -1 +1 @@ -!define VERSION '3.11.1.3753' +!define VERSION '3.11.1.3756' diff --git a/ReleaseGenerators/RebuildStandartModules.pas b/ReleaseGenerators/RebuildStandartModules.pas index 92c1f6b70..9e3754d37 100644 --- a/ReleaseGenerators/RebuildStandartModules.pas +++ b/ReleaseGenerators/RebuildStandartModules.pas @@ -21,7 +21,7 @@ uses TasksArr, TasksMatr, TasksStr, Tasks1Begin, Tasks1BoolIfCase, Tasks1Loops, Tasks1Arr, WPF, DataFrameABC, DataFrameABCCore, LinearAlgebraML, PreprocessorABC, - MetricsABC, MLABC, MLCoreABC, MLModelsABC, ValidationML + MetricsABC, MLABC, MLCoreABC, MLModelsABC, ValidationML, MLExceptions ; begin diff --git a/ReleaseGenerators/RebuildStandartModulesMono.pas b/ReleaseGenerators/RebuildStandartModulesMono.pas index 651ed1ae0..8b73c440e 100644 --- a/ReleaseGenerators/RebuildStandartModulesMono.pas +++ b/ReleaseGenerators/RebuildStandartModulesMono.pas @@ -10,7 +10,8 @@ Collections, Arrays, Core, ClientServer, Countries, ABCDatabases, School, SF, TurtleABC, - DataFrameABC, DataFrameABCCore, LinearAlgebraML, PreprocessorABC + DataFrameABC, DataFrameABCCore, LinearAlgebraML, PreprocessorABC, + MetricsABC, MLABC, MLCoreABC, MLModelsABC, ValidationML, MLExceptions ; begin diff --git a/ReleaseGenerators/sect_Core.nsh b/ReleaseGenerators/sect_Core.nsh index 40b9dfe19..3ebfd7e04 100644 --- a/ReleaseGenerators/sect_Core.nsh +++ b/ReleaseGenerators/sect_Core.nsh @@ -188,6 +188,8 @@ File ..\bin\Lib\MLCoreABC.pcu File ..\bin\Lib\MLModelsABC.pcu File ..\bin\Lib\ValidationML.pcu + File ..\bin\Lib\MLExceptions.pcu + File ..\bin\Lib\PABCRtl.dll File ..\bin\Lib\HelixToolkit.Wpf.dll @@ -290,6 +292,7 @@ ${AddFile} "MLCoreABC.pcu" ${AddFile} "MLModelsABC.pcu" ${AddFile} "ValidationML.pcu" + ${AddFile} "MLExceptions.pcu" ${AddFile} "turtle.png" @@ -429,7 +432,7 @@ File ..\bin\Lib\MLCoreABC.pas File ..\bin\Lib\MLModelsABC.pas File ..\bin\Lib\ValidationML.pas - + File ..\bin\Lib\MLExceptions.pas File ..\bin\Lib\__RedirectIOMode.vb File ..\bin\Lib\VBSystem.vb @@ -519,6 +522,7 @@ ${AddFile} "MLCoreABC.pas" ${AddFile} "MLModelsABC.pas" ${AddFile} "ValidationML.pas" + ${AddFile} "MLExceptions.pas" ${AddFile} "__RedirectIOMode.vb" ${AddFile} "VBSystem.vb" diff --git a/bin/Lib/MLABC.pas b/bin/Lib/MLABC.pas index 6bd3d4cdd..ca85b2180 100644 --- a/bin/Lib/MLABC.pas +++ b/bin/Lib/MLABC.pas @@ -9,7 +9,8 @@ uses ValidationML; uses MLModelsABC; uses MetricsABC; uses PreprocessorABC; -USES DataFrameABC; +uses DataFrameABC; +uses MLExceptions; type Vector = LinearAlgebraML.Vector; @@ -42,6 +43,11 @@ type ElasticNet = MLModelsABC.ElasticNet; MulticlassLogisticRegression = MLModelsABC.MulticlassLogisticRegression; + MLException = MLExceptions.MLException; + MLArgumentException = MLExceptions.MLArgumentException; + MLNotFittedException = MLExceptions.MLNotFittedException; + MLDimensionException = MLExceptions.MLDimensionException; + implementation function ToMatrix(Self: DataFrame; colNames: array of string): Matrix; extensionmethod; diff --git a/bin/Lib/MLExceptions.pas b/bin/Lib/MLExceptions.pas new file mode 100644 index 000000000..0277fb397 --- /dev/null +++ b/bin/Lib/MLExceptions.pas @@ -0,0 +1,55 @@ +unit MLExceptions; + +interface + +type + /// Базовое исключение ML-библиотеки + MLException = class(Exception); + + /// Ошибка аргументов ML-методов + MLArgumentException = class(System.ArgumentException); + + /// Попытка использования необученной модели/пайплайна + MLNotFittedException = class(MLException); + + /// Несоответствие размерностей + MLDimensionException = class(MLException); + +procedure Error(msg: string; params args: array of object); +procedure ArgumentError(msg: string; params args: array of object); +procedure NotFittedError(msg: string; params args: array of object); +procedure DimensionError(msg: string; params args: array of object); + +implementation + +function FormatSafe(msg: string; args: array of object): string; +begin + var text := GetTranslation(msg); + try + Result := Format(text, args); + except + Result := text; // если не совпали {0},{1} — оставляем как есть + end; +end; + +procedure Error(msg: string; params args: array of object); +begin + raise new MLException(FormatSafe(msg, args)); +end; + +procedure ArgumentError(msg: string; params args: array of object); +begin + raise new MLArgumentException(FormatSafe(msg, args)); +end; + +procedure NotFittedError(msg: string; params args: array of object); +begin + raise new MLNotFittedException(FormatSafe(msg, args)); +end; + +procedure DimensionError(msg: string; params args: array of object); +begin + raise new MLDimensionException(FormatSafe(msg, args)); +end; + +end. diff --git a/bin/Lib/PABCSystem.pas b/bin/Lib/PABCSystem.pas index e5877e380..2b4a32e2d 100644 --- a/bin/Lib/PABCSystem.pas +++ b/bin/Lib/PABCSystem.pas @@ -3139,48 +3139,6 @@ type end; -{type - ///-- - __TypeclassRestrictedFunctionAttribute = class(Attribute) - public - constructor; - begin - end; - end; - - - ///-- - __TypeclassGenericParameterAttribute = class(Attribute) - public - constructor(instanceName: string); - begin - end; - end; - - ///-- - __TypeclassAttribute = class(Attribute) - public - constructor(typeclassName: string); - begin - end; - end; - - ///-- - __TypeclassMemberAttribute = class(Attribute) - public - constructor; - begin - end; - end; - - ///-- - __TypeclassInstanceAttribute = class(Attribute) - public - constructor(instanceName: string); - begin - end; - end;} - type // Смысл полей Num, Width и Fmt соответствует // атрибутам форматирования {Num,Width:Fmt}. @@ -3237,6 +3195,8 @@ type constructor Create; end; +/// Функция для перевода сообщений об ошибках +function GetTranslation(message: string): string; // ----------------------------------------------------- // Internal procedures for PABCRTL.dll @@ -3330,6 +3290,7 @@ begin Result := 'ru'; end; +// Делаю публичной function GetTranslation(message: string): string; begin var cur_locale := GetCurrentLocale(); diff --git a/bin/Lib/ValidationML.pas b/bin/Lib/ValidationML.pas index a20233cd3..fb7934164 100644 --- a/bin/Lib/ValidationML.pas +++ b/bin/Lib/ValidationML.pas @@ -70,7 +70,12 @@ type implementation -uses System; +uses MLExceptions; + +const + ER_DIM_MISMATCH_TRAIN_TEST = + 'Несоответствие размерностей в TrainTestSplit: X.RowCount={0}, y.Length={1}!!' + + 'Dimension mismatch in TrainTestSplit: X.RowCount={0}, y.Length={1}'; //----------------------------- // Validation @@ -80,7 +85,7 @@ static function Validation.TrainTestSplit(X: Matrix; y: Vector; testRatio: real; seed: integer): (Matrix, Matrix, Vector, Vector); begin if X.RowCount <> y.Length then - raise new Exception('Dimension mismatch in TrainTestSplit'); + DimensionError(ER_DIM_MISMATCH_TRAIN_TEST, X.RowCount, y.Length); if (testRatio <= 0) or (testRatio >= 1) then raise new Exception('testRatio must be in (0,1)'); @@ -309,7 +314,7 @@ class function GridSearch.Search( ): (real, real, T); where T: IModel; begin if paramValues.Length = 0 then - raise new ArgumentException('paramValues is empty'); + raise new System.ArgumentException('paramValues is empty'); var bestParam := paramValues[0]; var bestScore := -1e308;