feat: SheetDetector 类型识别(名称/表头关键词)
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from genesis.data_models import SheetType
|
||||
|
||||
# Sheet 名关键词(design §3.5.1,顺序即优先级)
|
||||
NAME_KEYWORDS: list[tuple[str, SheetType]] = [
|
||||
("機能", SheetType.FUNCTION),
|
||||
("画面", SheetType.SCREEN),
|
||||
("帳票", SheetType.REPORT),
|
||||
("テーブル", SheetType.DATABASE),
|
||||
("DB", SheetType.DATABASE),
|
||||
("インターフェース", SheetType.INTERFACE),
|
||||
("IF", SheetType.INTERFACE),
|
||||
("バッチ", SheetType.BATCH),
|
||||
("ジョブ", SheetType.BATCH),
|
||||
("マスタ", SheetType.MASTER),
|
||||
("コード", SheetType.MASTER),
|
||||
]
|
||||
|
||||
# 表头关键词
|
||||
HEADER_KEYWORDS: list[tuple[str, SheetType]] = [
|
||||
("機能ID", SheetType.FUNCTION),
|
||||
("画面ID", SheetType.SCREEN),
|
||||
("帳票ID", SheetType.REPORT),
|
||||
("テーブルID", SheetType.DATABASE),
|
||||
("IF名", SheetType.INTERFACE),
|
||||
("バッチID", SheetType.BATCH),
|
||||
]
|
||||
|
||||
|
||||
def _name_hit(sheet_name: str) -> SheetType | None:
|
||||
for kw, st in NAME_KEYWORDS:
|
||||
if kw in sheet_name:
|
||||
return st
|
||||
return None
|
||||
|
||||
|
||||
def _header_hit(matrix: list[list[Any]]) -> SheetType | None:
|
||||
for row in matrix[:3]:
|
||||
for cell in row:
|
||||
if isinstance(cell, str):
|
||||
for kw, st in HEADER_KEYWORDS:
|
||||
if kw in cell:
|
||||
return st
|
||||
return None
|
||||
|
||||
|
||||
def detect_sheet_type(sheet_name: str, matrix: list[list[Any]]) -> SheetType:
|
||||
return _name_hit(sheet_name) or _header_hit(matrix) or SheetType.GENERIC
|
||||
@@ -0,0 +1,21 @@
|
||||
from genesis.data_models import SheetType
|
||||
from genesis.parsers.sheet_detector import detect_sheet_type
|
||||
|
||||
|
||||
def test_detect_by_sheet_name():
|
||||
assert detect_sheet_type("機能一覧", []) == SheetType.FUNCTION
|
||||
assert detect_sheet_type("画面一覧", []) == SheetType.SCREEN
|
||||
assert detect_sheet_type("帳票一覧", []) == SheetType.REPORT
|
||||
assert detect_sheet_type("DB定義", []) == SheetType.DATABASE
|
||||
assert detect_sheet_type("IF定義", []) == SheetType.INTERFACE
|
||||
assert detect_sheet_type("バッチ一覧", []) == SheetType.BATCH
|
||||
assert detect_sheet_type("コード管理", []) == SheetType.MASTER
|
||||
|
||||
|
||||
def test_detect_by_header_keyword():
|
||||
matrix = [["帳票ID", "帳票名"], ["TB1", "月次"]]
|
||||
assert detect_sheet_type("補充シート", matrix) == SheetType.REPORT
|
||||
|
||||
|
||||
def test_unknown_is_generic():
|
||||
assert detect_sheet_type("メモ", [["随筆"]]) == SheetType.GENERIC
|
||||
Reference in New Issue
Block a user