Просмотр исходного кода

fix(kb): normalize Kangxi radicals in Java service

- Add normalizeIndicatorName() to convert U+2ED4/U+2F3C → U+95E8 (门)
- Apply normalization at both init (buildIndexes) and lookup time
- Remove duplicate Kangxi radical entries from JSON (now handled by code)
- Belt-and-suspenders: data + code both normalize
asus 2 месяцев назад
Родитель
Сommit
ce8a1314ae

+ 19 - 3
cfc-backend/src/main/java/com/etotem/cfc/service/KnowledgeBaseV3Service.java

@@ -105,7 +105,8 @@ public class KnowledgeBaseV3Service {
                             Map<String, Object> entry = (Map<String, Object>) item;
                             String name = (String) entry.get("名称");
                             if (name != null && !name.isEmpty()) {
-                                sectionIndex.put(name, entry);
+                                // 归一化防止部首变体导致的重复条目(后写入覆盖前写入,结果一致)
+                                sectionIndex.put(normalizeIndicatorName(name), entry);
                             }
                         }
                     }
@@ -201,8 +202,9 @@ public class KnowledgeBaseV3Service {
      */
     public Map<String, Object> lookupIndicator(String indicatorName) {
         if (indicatorName == null || indicatorName.isEmpty()) return null;
+        String normalized = normalizeIndicatorName(indicatorName);
         for (Map<String, Map<String, Object>> section : indicatorIndex.values()) {
-            Map<String, Object> result = section.get(indicatorName);
+            Map<String, Object> result = section.get(normalized);
             if (result != null) return result;
         }
         return null;
@@ -214,7 +216,7 @@ public class KnowledgeBaseV3Service {
     public Map<String, Object> lookupIndicatorInSection(String sectionName, String indicatorName) {
         Map<String, Map<String, Object>> section = indicatorIndex.get(sectionName);
         if (section == null) return null;
-        return section.get(indicatorName);
+        return section.get(normalizeIndicatorName(indicatorName));
     }
 
     /**
@@ -262,6 +264,20 @@ public class KnowledgeBaseV3Service {
         return new ArrayList<>(foodIndex.values());
     }
 
+    // ==================== 字符归一化 ====================
+
+    /**
+     * 归一化指标名称:将 Kangxi 部首等变体转为标准 CJK 统一汉字
+     * 报告提取的文本中常出现部首形式(如 ⻔ U+2ED4),而 KB 储存标准汉字(门 U+95E8)
+     */
+    private String normalizeIndicatorName(String name) {
+        if (name == null || name.isEmpty()) return name;
+        // ⻔(U+2ED4)/⻼(U+2F3C) → 门(U+95E8)
+        name = name.replace('\u2ed4', '\u95e8');
+        name = name.replace('\u2f3c', '\u95e8');
+        return name;
+    }
+
     // ==================== 原始数据 ====================
 
     /**

+ 0 - 14
cfc-backend/src/main/resources/knowledge-base/报告指标知识库.json

@@ -1408,13 +1408,6 @@
         "偏低影响": "",
         "调整建议": ""
       },
-      {
-        "名称": "幽⻔螺杆菌",
-        "说明": "与胃炎、胃溃疡和胃癌相关",
-        "偏高影响": "",
-        "偏低影响": "",
-        "调整建议": ""
-      },
       {
         "名称": "艰难梭菌",
         "说明": "抗生素相关性腹泻的主要病原菌",
@@ -1429,13 +1422,6 @@
         "偏低影响": "",
         "调整建议": ""
       },
-      {
-        "名称": "沙⻔氏菌",
-        "说明": "食物中毒和肠道感染的常见病原菌",
-        "偏高影响": "",
-        "偏低影响": "",
-        "调整建议": ""
-      },
       {
         "名称": "志贺氏菌",
         "说明": "细菌性痢疾的病原菌",

+ 0 - 14
docs/参考资料/知识库/报告指标知识库.json

@@ -1408,13 +1408,6 @@
         "偏低影响": "",
         "调整建议": ""
       },
-      {
-        "名称": "幽⻔螺杆菌",
-        "说明": "与胃炎、胃溃疡和胃癌相关",
-        "偏高影响": "",
-        "偏低影响": "",
-        "调整建议": ""
-      },
       {
         "名称": "艰难梭菌",
         "说明": "抗生素相关性腹泻的主要病原菌",
@@ -1429,13 +1422,6 @@
         "偏低影响": "",
         "调整建议": ""
       },
-      {
-        "名称": "沙⻔氏菌",
-        "说明": "食物中毒和肠道感染的常见病原菌",
-        "偏高影响": "",
-        "偏低影响": "",
-        "调整建议": ""
-      },
       {
         "名称": "志贺氏菌",
         "说明": "细菌性痢疾的病原菌",