diff --git a/CLAUDE.md b/CLAUDE.md index 2f1e39e..fa85a4b 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -16,7 +16,7 @@ The system follows a modular architecture with clear separation of concerns: - **M02_DataIO.bas** - Data input/output operations. Reads source data from "平台配置清单" worksheet and generates categorized output workbooks. - **M03_Logic.bas** - Core recursive parser for conditional expressions. Handles logical operators (AND/OR), nested parentheses, and key=value/key!=val conditions. Implements Cartesian products for set operations. - **M04_Config.bas** - Column mapping and header priorities. Defines source data columns (CODE, NAME, QTY, CONDITION, CATEGORY) and standard ordering for output. -- **M05_PreProcessor.bas** - Preprocessing module for condition transformation. Handles value mapping for "接头" category (e.g., azxs=A0→径向, lcfw=M01→低压), duplicate OR condition merging, and nested expression simplification. Uses mapping data from "对照表" worksheet. +- **M05_PreProcessor.bas** - Preprocessing module for condition transformation. Handles category-specific preprocessing: "接头" (azxs+lcfw mapping, OR merging, parentheses simplification), "部件" (azxs mapping only, OR merging, parentheses simplification). Uses mapping data from "对照表" worksheet. - **M99_TestRunner.bas** - Unit testing framework. Run `RunAllTests()` in VBA Immediate window to execute tests. ### Class Module @@ -36,14 +36,22 @@ New Excel Workbook + Error Report ### Preprocessing (M05_PreProcessor) -Before parsing conditions, the system applies preprocessing for "接头" (joint) category: +Before parsing conditions, the system applies category-specific preprocessing: + +**Supported Categories**: + +| Category | azxs Mapping | lcfw Mapping | OR Merging | Parentheses Simplification | +|----------|-------------|--------------|------------|----------------------------| +| 接头 | ✓ | ✓ | ✓ | ✓ | +| 部件 | ✓ | ✗ | ✓ | ✓ | +| Other | ✗ | ✗ | ✗ | ✗ | **Value Mapping**: - **azxs** (安装形式): Maps codes to descriptive values - A0, AT, AH → 径向 - B0, BT, BZ, BH → 下轴向 - Z0, ZT, ZZ, ZH → 中轴向 -- **lcfw** (量程范围): Maps range codes to categories +- **lcfw** (量程范围): Maps range codes to categories (接头 category only) - M01-M11 → 低压 - M12-M16 → 高压 @@ -104,14 +112,18 @@ This runs unit tests for: - OR operations with union operations - Nested parentheses handling - Logic conflict detection -- **Preprocessing tests** (Test_PP_01 to Test_PP_08): +- **Preprocessing tests** (Test_PP_01 to Test_PP_12): - azxs mapping load (12 values) - lcfw mapping load (M01-M16) - Value replacement - OR condition merging - Full integration with M03_Logic - - Non-"接头" category handling + - Non-"接头"/"部件" category handling - Unmapped value handling + - "部件" category azxs mapping (PP_09) + - "部件" category lcfw unchanged (PP_10) + - "部件" category OR merging (PP_11) + - "部件" category parentheses simplification (PP_12) ### Python Skills (Claude Code Integration) diff --git a/VBA/Modules/M05_PreProcessor.bas b/VBA/Modules/M05_PreProcessor.bas index 44e3b3b..bfef866 100644 --- a/VBA/Modules/M05_PreProcessor.bas +++ b/VBA/Modules/M05_PreProcessor.bas @@ -1,6 +1,9 @@ ' ============================================================================== ' 模块: M05_PreProcessor -' 职责: 预处理条件表达式,用于"接头"类别的值映射和去重 +' 职责: 预处理条件表达式,支持不同类别的差异化处理 +' - "接头"类别: 完整预处理(azxs映射 + lcfw映射 + OR合并 + 括号简化) +' - "部件"类别: 部分预处理(azxs映射 + OR合并 + 括号简化,不处理lcfw) +' - 其他类别: 不进行预处理 ' 使用正则表达式实现高效的值映射和OR条件合并 ' ============================================================================== Option Explicit @@ -35,24 +38,32 @@ End Function ' ------------------------------------------------------------------------------ ' 主入口:预处理条件表达式 +' 支持的类别: +' - "接头": 完整预处理(azxs映射 + lcfw映射 + OR合并 + 括号简化) +' - "部件": 部分预处理(azxs映射 + OR合并 + 括号简化,不处理lcfw) +' - 其他: 不进行预处理 ' ------------------------------------------------------------------------------ Public Function PreprocessCondition( _ ByVal strCondition As String, _ ByVal strCategory As String, _ ByVal rowIdx As Long _ ) As String - ' 仅对"接头"类别进行预处理 - If strCategory <> "接头" Then - PreprocessCondition = strCondition - Exit Function - End If - If Not g_IsInitialized Then PreprocessCondition = strCondition Exit Function End If - PreprocessCondition = ApplyPreprocessing(strCondition, rowIdx) + ' 根据类别选择处理策略 + If strCategory = "接头" Then + ' 完整预处理:azxs + lcfw + OR合并 + 括号简化 + PreprocessCondition = ApplyPreprocessing(strCondition, rowIdx) + ElseIf strCategory = "部件" Then + ' 部分预处理:azxs + OR合并 + 括号简化(不处理 lcfw) + PreprocessCondition = ApplyPreprocessingWithoutLcfw(strCondition, rowIdx) + Else + ' 其他类别:不处理 + PreprocessCondition = strCondition + End If End Function ' ------------------------------------------------------------------------------ @@ -143,6 +154,35 @@ Private Function ApplyPreprocessing( _ ApplyPreprocessing = strCondition End Function +' ------------------------------------------------------------------------------ +' 应用预处理(不含 lcfw 映射):用于"部件"类别 +' 执行步骤:azxs 映射 → 嵌套表达式处理 → OR合并 → 括号简化 +' ------------------------------------------------------------------------------ +Private Function ApplyPreprocessingWithoutLcfw( _ + ByVal strCondition As String, _ + ByVal rowIdx As Long _ +) As String + ' 步骤1: 应用 azxs 映射 + strCondition = ApplyRegexMapping( _ + strCondition, _ + "(azxs)( *=|!= *)([a-zA-Z0-9]{2})", _ + g_AzxsMapping, _ + rowIdx, _ + "azxs" _ + ) + + ' 步骤2: 递归处理嵌套括号内的表达式(合并OR,简化括号) + strCondition = ProcessNestedExpressions(strCondition, rowIdx) + + ' 步骤3: 合并顶层重复的OR条件 + strCondition = MergeDuplicateORConditions(strCondition) + + ' 步骤4: 简化不必要的括号 + strCondition = SimplifyParentheses(strCondition) + + ApplyPreprocessingWithoutLcfw = strCondition +End Function + ' ------------------------------------------------------------------------------ ' 递归处理嵌套表达式:先预处理括号内的内容,再进行OR合并 ' ------------------------------------------------------------------------------ diff --git a/VBA/Modules/M99_TestRunner.bas b/VBA/Modules/M99_TestRunner.bas index f6ecf39..730cde9 100644 --- a/VBA/Modules/M99_TestRunner.bas +++ b/VBA/Modules/M99_TestRunner.bas @@ -46,6 +46,10 @@ Public Sub RunAllTests() Test_PP_06_FullIntegration Test_PP_07_NonJointCategory Test_PP_08_UnmappedValues + Test_PP_09_ComponentCategory_AzxsMapping + Test_PP_10_ComponentCategory_LcfwUnchanged + Test_PP_11_ComponentCategory_ORMerging + Test_PP_12_ComponentCategory_ParenthesesSimplification ' 汇总结果 Debug.Print String(50, "-") @@ -369,8 +373,8 @@ Private Sub Test_PP_06_FullIntegration() End Sub ' ------------------------------------------------------------------------------ -' 测试用例 PP_07: 测试非"接头"类别 -' 验证其他类别不受预处理影响 +' 测试用例 PP_07: 测试非"接头"/"部件"类别 +' 验证其他类别(如"弹性元件")不受预处理影响 ' ------------------------------------------------------------------------------ Private Sub Test_PP_07_NonJointCategory() SetupPreProcessorTest @@ -378,9 +382,9 @@ Private Sub Test_PP_07_NonJointCategory() Dim inputCond As String inputCond = "gclj=M20 AND lcfw=M01" - ' 使用"部件"类别 + ' 使用"弹性元件"类别 Dim result As String - result = M05_PreProcessor.PreprocessCondition(inputCond, "部件", 1) + result = M05_PreProcessor.PreprocessCondition(inputCond, "弹性元件", 1) ' 应该保持不变 Assert_Equal result, inputCond, "PP07_NonJoint_Unchanged" @@ -407,6 +411,67 @@ Private Sub Test_PP_08_UnmappedValues() ' 注意:这个测试可能需要根据实际日志记录行为调整 End Sub +' ------------------------------------------------------------------------------ +' 测试用例 PP_09: 测试"部件"类别的azxs映射 +' ------------------------------------------------------------------------------ +Private Sub Test_PP_09_ComponentCategory_AzxsMapping() + SetupPreProcessorTest + + Dim result1 As String + result1 = M05_PreProcessor.PreprocessCondition("azxs=A0 AND gclj=M20", "部件", 1) + Assert_Equal result1, "azxs=径向 AND gclj=M20", "PP09_Component_Azxs_Mapping" + + Dim result2 As String + result2 = M05_PreProcessor.PreprocessCondition("gclj=M20 AND azxs=B0", "部件", 2) + Assert_Equal result2, "gclj=M20 AND azxs=下轴向", "PP09_Component_Azxs_With_AND" +End Sub + +' ------------------------------------------------------------------------------ +' 测试用例 PP_10: 测试"部件"类别的lcfw条件保持不变 +' ------------------------------------------------------------------------------ +Private Sub Test_PP_10_ComponentCategory_LcfwUnchanged() + SetupPreProcessorTest + + Dim result1 As String + result1 = M05_PreProcessor.PreprocessCondition("lcfw=M01 AND gclj=M20", "部件", 1) + Assert_Equal result1, "lcfw=M01 AND gclj=M20", "PP10_Component_Lcfw_Unchanged" + + Dim result2 As String + result2 = M05_PreProcessor.PreprocessCondition("gclj=M20 AND lcfw=M01", "部件", 2) + Assert_Equal result2, "gclj=M20 AND lcfw=M01", "PP10_Component_Lcfw_Unchanged_Reverse" +End Sub + +' ------------------------------------------------------------------------------ +' 测试用例 PP_11: 测试"部件"类别的OR条件合并 +' ------------------------------------------------------------------------------ +Private Sub Test_PP_11_ComponentCategory_ORMerging() + SetupPreProcessorTest + + Dim result1 As String + result1 = M05_PreProcessor.PreprocessCondition("(azxs=A0 OR azxs=AT) AND gclj=M20", "部件", 1) + Assert_Equal result1, "azxs=径向 AND gclj=M20", "PP11_Component_OR_Merging_Azxs" + + ' 测试精确重复的OR条件合并 + Dim result2 As String + result2 = M05_PreProcessor.PreprocessCondition("azxs=径向 OR azxs=径向", "部件", 2) + Assert_Equal result2, "azxs=径向", "PP11_Component_Exact_Duplicate_Merging" +End Sub + +' ------------------------------------------------------------------------------ +' 测试用例 PP_12: 测试"部件"类别的括号简化 +' ------------------------------------------------------------------------------ +Private Sub Test_PP_12_ComponentCategory_ParenthesesSimplification() + SetupPreProcessorTest + + Dim result1 As String + result1 = M05_PreProcessor.PreprocessCondition("(azxs=A0 OR azxs=AT) AND gclj=M20", "部件", 1) + Assert_Equal result1, "azxs=径向 AND gclj=M20", "PP12_Component_Parentheses_Simplified" + + Dim result2 As String + result2 = M05_PreProcessor.PreprocessCondition("gclj=M20 AND (azxs=A0 OR azxs=AT)", "部件", 2) + Assert_Equal result2, "gclj=M20 AND azxs=径向", "PP12_Component_Parentheses_Simplified_Reverse" +End Sub + ' ------------------------------------------------------------------------------ ' 辅助函数:设置预处理测试环境 ' ------------------------------------------------------------------------------