liuchengsen пре 1 месец
родитељ
комит
9b9e99fe66
1 измењених фајлова са 3 додато и 1 уклоњено
  1. 3 1
      data-pipeline/docx_ingest.py

+ 3 - 1
data-pipeline/docx_ingest.py

@@ -103,7 +103,9 @@ def _extract_images(doc, drug_name):
             if ext.lower() not in ('jpg', 'jpeg', 'png', 'gif', 'bmp'):
                 ext = 'png'
             # 用 rId hash 防止重复
-            fname = f"{drug_name}_{rId}.{ext}"
+            # 清理药名中的特殊字符,避免 URL 编码问题
+            safe_name = re.sub(r'[\s()() ]+', '_', drug_name).strip('_')
+            fname = f"{safe_name}_{rId}.{ext}"
             fpath = os.path.join(IMAGES_DIR, fname)
             if not os.path.exists(fpath):
                 with open(fpath, 'wb') as f: