diff --git a/src/common/roofShapePattern.js b/src/common/roofShapePattern.js index abba02a6..bf264c0f 100644 --- a/src/common/roofShapePattern.js +++ b/src/common/roofShapePattern.js @@ -126,3 +126,25 @@ export const matchRoofShapePattern = (descriptor) => { return candidate.shapeNum } + +// Gemini 자유 출력(raw) → 매처 strict 어휘로 정규화한 RoofShapeDescriptor | null. +// 어휘 밖 type/ridge 는 ''(매처가 결측 관대), flows 는 ROOF_FLOW 어휘만 소문자화·중복제거. +// type·ridge·flows 가 모두 비면 null. direction 은 산출하지 않는다(매처 미사용). +export const normalizeRoofShape = (raw) => { + if (!raw || typeof raw !== 'object') return null + + const norm = (value) => (typeof value === 'string' ? value.trim().toLowerCase() : '') + const TYPE_VALUES = Object.values(ROOF_SHAPE_TYPE) + const RIDGE_VALUES = Object.values(ROOF_RIDGE) + const FLOW_VALUES = Object.values(ROOF_FLOW) + + const type = TYPE_VALUES.includes(norm(raw.type)) ? norm(raw.type) : '' + const ridge = RIDGE_VALUES.includes(norm(raw.ridge)) ? norm(raw.ridge) : '' + const flows = Array.isArray(raw.flows) ? [...new Set(raw.flows.map(norm).filter((flow) => FLOW_VALUES.includes(flow)))] : [] + + if (!type && !ridge && flows.length === 0) return null + + const result = { type, ridge, flows } + if (typeof raw.confidence === 'number') result.confidence = raw.confidence + return result +}