|
|
@@ -57,11 +57,14 @@ def load_env():
|
|
|
|
|
|
|
|
|
def is_cjk_name(s):
|
|
|
- """严格药名检测:2-6 个纯 CJK 字符"""
|
|
|
- if not s or len(s) < 2 or len(s) > 6:
|
|
|
+ """药名检测:2-10 字符,CJK 占 70% 以上,允许破折号/连接符/括号"""
|
|
|
+ if not s or len(s) < 2 or len(s) > 10:
|
|
|
+ return False
|
|
|
+ # Skip pure digits/punctuation
|
|
|
+ if re.match(r'^[\d\s\.\,\;\:\!\?\(\)\[\]\{\}<>@#$%^&*+=|\\/\"\']+$', s):
|
|
|
return False
|
|
|
cjk = sum(1 for c in s if ord(c) >= 0x4E00 and ord(c) <= 0x9FFF)
|
|
|
- return cjk >= 2 and cjk == len(s)
|
|
|
+ return cjk >= 2 and cjk >= len(s) * 0.7
|
|
|
|
|
|
|
|
|
def is_pinyin_line(s):
|
|
|
@@ -96,7 +99,9 @@ def extract_drug_entries(pdf_path: str) -> list[dict]:
|
|
|
if re.match(r'^[・•·]\s*\d+\s*[・•·]$', s): continue
|
|
|
clean_lines.append(s)
|
|
|
|
|
|
- # 第一遍:标记所有"已确认的药名"——CJK + 下一行是拼音或拉丁名
|
|
|
+ # 第一遍:标记所有"已确认的药名"
|
|
|
+ # 方式1:CJK + 下一行是拼音或拉丁名(药材和饮片)
|
|
|
+ # 方式2:CJK + 下一行是【处方】或【制法】(成方制剂,无拼音)
|
|
|
confirmed_names = set()
|
|
|
for i in range(len(clean_lines) - 2):
|
|
|
s = clean_lines[i]
|
|
|
@@ -104,6 +109,8 @@ def extract_drug_entries(pdf_path: str) -> list[dict]:
|
|
|
if is_cjk_name(s):
|
|
|
if is_pinyin_line(nxt) or (nxt.isupper() and len(nxt) > 5):
|
|
|
confirmed_names.add(s)
|
|
|
+ elif nxt.startswith('【处方】') or nxt.startswith('【制法】'):
|
|
|
+ confirmed_names.add(s)
|
|
|
|
|
|
print(f" 确认药名: {len(confirmed_names)} 个")
|
|
|
|