Commit Graph

8 Commits

Author SHA1 Message Date
NB-076 bb4a7a2346 fix: classification修复+grammar增强+75/75回归确认
分类修复:
- FILE-CONTROL关键词(0.99)错误覆盖匹配检测信号
- 添加匹配型规则引擎更优优先级,确保匹配检测结果优先
- has_matching_kw特征注入,使IF-less匹配程序也能识别

Grammar增强:
- LEVEL扩展到/[0-9]+/覆盖所有COBOL层级号
- HEX_STRING添加支持X'...'十六进制字面量
- VALUE子句逗号预处理剥离(88-level多值)
- COPY正则支持引号包覆的名称

结果: 内部75/75, 外部基准54/58(93%)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-22 13:18:07 +08:00
NB-076 a784c6974a fix: 高密度テスト52/52通過 + SPACES figurative constant FP fix
COBOL技術者による高密度テスト(52 tests)実装:

発見・修正されたバグ:
1. WS-KEY = SPACES の figurative constant 比較が FP 原因
   - _matches_key_comparison に figurative constant除外を追加
   - 構造検知の信号4でも SPACES/ZERO 等を除外
   - structural_matching で単一ファイルプログラムを除外

2. simple_vs_two_stage が常に単純マッチングを返していた
   - 実証拠なしでも0.5で返す → 他の分類を汚染
   - 修正: file_count>=2 + IF + 比較証拠がない場合は unknown

3. simple_vs_two_stageテストを現実に合わせて更新

回帰: 767 passed(0 new failures)
高密度テスト: 52/52 PASS
2026-06-21 17:04:48 +08:00
NB-076 875c593d85 fix: 構造検知の根本的改善 — 変数名に依存しないマッチング検出
COBOL技術者による徹底検証で発見された根本問題と修正:

問題1: 構造検知の信号が変数名の命名規則に依存しすぎていた
- EOF 固定 → WS-E1/WS-END-1/FE-1 も検知
- INTO ありのみ → READ AT END のみも検知
- IF 比較が WS- またはハイフン必須 → どんな名前でも検知
- OPEN 1行複数ファイルのみ → 複数行も検知

問題2: mn_output_mode が2ファイル4分岐でも M:N と誤判定
- しきい値を select>=3 or (select>=2 and 分岐>=4) に引き上げ
- 標準的な2ファイルマッチングプログラムを誤判定しない

問題3: has_cross_file_cmp が欠落していた
- ルールエンジンに IF K1 = K2 のような比較情報を注入
- 数字リテラルとの比較は除外(IF WS-COUNT > 0 など)

効果: 6種類の異なるコーディングスタイルすべてが一貫してマッチング判定
回帰: 767 passed (0 new)
2026-06-21 16:27:17 +08:00
NB-076 cdba324b5a fix: HINA 全类型缺陷修复 — SORT/CSV/ALT 3 个真实缺陷
对抗性全类型测试发现的缺陷和修复:

缺陷1: SORT/MERGE L1 关键词太严格(漏检)
  - 旧: 'SORT ON KEY' / 'MERGE ON KEY'(精确字符串)
  - COBOL 中的真实写法: SORT WORK-FILE ON ASCENDING KEY ...
  - 新: 正则 SORT(?:\s+\S+)?\s+ON\s+(?:ASCENDING|DESCENDING)?KEY

缺陷2: CSV 假阳性(STRING/INSPECT 非CSV也触发)
  - 旧: has_string=True -> CSV合并
  - 新: 要求 has_csv_merge(STRING+逗号分隔)
  - 单纯字符串拼接不再触发 CSV 分类

缺陷3: ALTERNATE RECORD KEY 被 ORGANIZATION IS 覆盖
  - 旧: 文件编成先于替代索引(同确信度先者胜)
  - 新: 替代索引放前面(更具体的分类优先)

回归: 767 passed(0 new failures)
2026-06-21 15:51:30 +08:00
NB-076 da5d1058e7 feat: structural matching detection — no KEY variable needed
Add _detect_matching_structure(): detection based on control flow
pattern, not variable naming conventions. Uses 5 structural signals:
1. READ + AT END + EOF pattern
2. PERFORM UNTIL with EOF condition
3. ELSE body with conditional READ (matching core)
4. IF comparing hyphenated fields (cross-file comparison)
5. Multi-file OPEN INPUT

5/5 signals → 0.55, 4/5 → 0.50, 3/5 → 0.40.

Real-world impact: matching programs with key fields named CUST-CODE
and ORDR-CODE (no '-KEY' in name) are now correctly detected.

Also:
- Rule engine type priority: main types (マッチング etc.) override
  secondary types (M:N, DIVIDE) when keyword confidence is low
- has_structural_match injected into features so rule engine can use it
- matching_vs_keybreak accepts equality IFs as matching evidence
- New test: test_structural_matching_no_keyword()

Regression: 764 passed (0 new failures).
2026-06-21 15:28:32 +08:00
NB-076 33762ca959 fix: adversarial testing — 4 false positive/negative fixes + comment stripping
COBOL migration expert adversarial testing found 4 real defects:

FIX 1: Comment-stripping in detect_keyword() (FP-2)
- Remove *> inline comments and * comment lines before keyword matching
- Prevents 「マッチング」 from triggering on WS-KEY in comments

FIX 2: KEY comparison context validation (FP-1, FP-6)
- Add _matches_key_comparison() — requires WS-KEY variable to appear
  NEAR an actual comparison operator (= < >), not just as PIC/VALUE decl
- Same check in _path_rule_engine features via has_key_var injection
- Fix regex bug: [=<>\s] vs [=<>] — \s matched whitespace after PIC decl

FIX 3: Old-school naming support (FN-1)
- Add L1 keyword r'[A-Z]\d{0,2}-\w*KEY' with 0.55 confidence
- Matches K01-KEY, KS-KEY etc. (non-WS- prefix naming convention)

FIX 4: mn_output_mode over-matching (FP-6)
- Require IF branches + KEY evidence before returning M:N for file>=3
- matching_vs_keybreak rule 3 now requires has_key_var

New tests: test_adversarial.py — 8 parametrized adversarial tests
Regression: 755 passed (0 new failures)
2026-06-21 15:16:41 +08:00
NB-076 958b12e9a9 fix: confusion group confidence calibration — false positive detection inflation
Issues found through matching program classification analysis:
1. dedup_vs_nodedup: 0.85→0.50 for negative detection (no WS-PREV-KEY
   is not strong evidence for '含まず')
2. validation_vs_keybreak: 0.80→0.55 for has_counter (counter is a
   generic pattern, not specific to key-break)
3. simple_vs_two_stage: 0.80→0.50 for non-open-close-open pattern
   (sequential OPEN is the default for most programs)

Result: matching programs now correctly classified:
- MT01-03/18/20 → マッチング  (was 項目チェック)
- MT16-17 → 二段階マッチング  (unchanged)
- MT32 → 項目チェック(重複含む)  (correct: has WS-PREV-KEY)
- VL01 → 項目チェック(重複含む)  (correct)
- CSV → CSV合并  (correct)
Regression: 745 passed (3 test expectation bounds updated)
2026-06-21 13:17:31 +08:00
hangshuo652 bc1d56d1a4 feat: Phase 2 complete — 13 Phases of COBOL type classification and test benchmark
P0.6: gcov infrastructure
P1: extract_structure output expansion (11 new feature fields)
P2: Confusion group rule engine (8 pairs + contradiction + backtrack)
P3: 4-factor confidence calculation + quality gate update
P4: 33+2 COBOL program type test samples (22 files, 7 categories)
P5: parametrized/ test data generation engine
P6: japanese_data.py lookup tables
P7-10: Type-specific test suites (~159 parametrized tests)
P11: Full classification pipeline (classify_program) + orchestrator integration
P12: Documentation (module-interfaces, test-plan v3.0, coverage-matrix)

Architecture decisions:
- classification_pipeline/ merged to hina/pipeline/
- parametrized/ as independent module
- japanese_data.py as root-level file
- hina/__all__ only exports classify_program()

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-19 23:51:55 +08:00