phone.yaml 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # -*- coding: utf-8 -*-
  2. # 规则文件:电话号码提取
  3. # 源:template_extract/template_extractor.py get_phone() 第 62-72 行
  4. # assembly/role_money.py phone 编译 第 1043-1053 行
  5. # 迁移日期:2026-08-12 Phase 7
  6. # 注意:原代码在两处有高度相似但不完全相同的 phone_pattern 定义。
  7. # 本文件以 template_extractor.py 的版本为准统一,
  8. # role_money.py 的版本差异(部分分支不同)在后续迁移时评估合并。
  9. version: 1
  10. category: CONTACT
  11. description: |
  12. 电话号码提取(手机 + 座机 + 400 + 分机)。
  13. 原 template_extractor.get_phone() 使用 ^pattern$ 整串匹配验证。
  14. 原 role_money.py phone 使用 re.compile + finditer 扫描。
  15. 迁移后两处统一引用 RuleLoader.get_pattern("phone_extract")。
  16. patterns:
  17. - id: phone_extract
  18. description: |
  19. 通用电话号码提取。支持:
  20. - 手机号 1[3-9]xxxxxxxxx(含分隔符 -—-―)
  21. - +86 前缀手机
  22. - 座机 0xx-xxxxxxxx(含分机 / 转 分机)
  23. - 带前瞻的座机变体(避免误匹配)
  24. - 括号包裹的区号 (0xx)xxxxxxxx
  25. - 7-8 位号码
  26. pattern: '1[3-9][0-9][-—-―]?\d{4}[-—-―]?\d{4}|\+86.?1[3-9]\d{9}|0[1-9]\d{1,2}[-—-―][2-9]\d{6,7}/[1-9]\d{6,10}|0[1-9]\d{1,2}[-—-―][2-9]\d{6}\d?.?转\d{1,4}|0[1-9]\d{1,2}[-—-―][2-9]\d{6}\d?[-—-―]\d{1,4}|0[1-9]\d{1,2}[-—-―]?[2-9]\d{6}\d?(?=1[3-9]\d{9})|0[1-9]\d{1,2}[-—-―]?[2-9]\d{6}\d?(?=0[1-9]\d{1,2}[-—-―]?[2-9]\d{6}\d?)|0[1-9]\d{1,2}[-—-―]?[2-9]\d{6}\d?(?=[2-9]\d{6,7})|0[1-9]\d{1,2}[-—-―]?[2-9]\d{6}\d?|[\(|\(]0[1-9]\d{1,2}[\)|\)]-?[2-9]\d{6}\d?-?\d{,4}|[2-9]\d{6,7}'
  27. method: search
  28. golden_examples:
  29. - input: "13812345678"
  30. should_match: true
  31. - input: "138-1234-5678"
  32. should_match: true
  33. - input: "+8613812345678"
  34. should_match: true
  35. - input: "010-87654321"
  36. should_match: true
  37. - input: "010-87654321转1234"
  38. should_match: true
  39. - input: "(010)87654321"
  40. should_match: true
  41. - input: "87654321"
  42. should_match: true
  43. - input: "12345"
  44. should_match: false
  45. - input: "abcdefg"
  46. should_match: false