
    u^iK                    Z    d Z ddlmZ ddlZddlmZ  ej        d          Zdd
ZddZ	dS )u:  Shared helpers for recognizing document codes in text.

公文文号识别工具模块。
使用正则表达式从文本中提取符合"机构名〔年份〕第N号"格式的
政府公文文号（如"国发〔2024〕15号"），用于文档引用关系的
自动发现和知识图谱中的文档间关联构建。
    )annotationsN)IteratoruX   [\u4e00-\u9fffA-Za-z]{2,20}\s*[〔\[【(（]\s*\d{4}\s*[〕\]】)）]\s*第?\s*\d+\s*号textstrreturnIterator[str]c              #     K   t                      }t                              | pd          D ]H}|                    d                                          }|r||vr|                    |           |V  IdS )z9Yield unique document codes from text in encounter order. r   N)setDOC_CODE_REfinditergroupstripadd)r   seenmatchdoc_codes       ,D:\work\zm-rag\backend\app\utils\doc_code.pyiter_doc_codesr      s      UUD%%djb11  ;;q>>'')) 	,,HHXNNN	     
str | Nonec                <    t          t          |           d          S )z4Return the first recognized document code from text.N)nextr   )r   s    r   extract_first_doc_coder   !   s    t$$d+++r   )r   r   r   r   )r   r   r   r   )
__doc__
__future__r   recollections.abcr   compiler   r   r    r   r   <module>r!      s     # " " " " " 				 $ $ $ $ $ $bj    , , , , , ,r   