inspect-code-rule.py 1.2 KB

123456789101112131415161718192021222324252627282930
  1. import json, collections, re
  2. p='.scratch/cockpit-real-data-wayfinding/verify/artifacts/t67/geom-none.json'
  3. d=json.load(open(p,encoding='utf-8'))
  4. feats=d['data']['features']
  5. def pref(code):
  6. m=re.match(r'^([A-Za-z]{2})', str(code or ''))
  7. return m.group(1) if m else '(none)'
  8. # 前缀 × name 里出现的片区词
  9. tab=collections.defaultdict(collections.Counter)
  10. for ft in feats:
  11. pr=ft.get('properties') or {}
  12. name=str(pr.get('name') or '')
  13. words=tuple(w for w in ['城南','城北','太常'] if w in name)
  14. tab[pref(pr.get('code'))][words]+=1
  15. for k in sorted(tab): print('prefix', k, dict(tab[k]))
  16. print()
  17. # 非 TC/CN 的样本
  18. for ft in feats:
  19. pr=ft.get('properties') or {}
  20. if pref(pr.get('code')) in ('GD','YL'):
  21. print('ODD', json.dumps({kk:pr.get(kk) for kk in ('source','code','name','industry','typeCode','pointType','remark')}, ensure_ascii=False))
  22. print()
  23. # 第二段:行业字母(第 3-4 位)分布,验证"片区+行业+时间"
  24. ind=collections.Counter()
  25. for ft in feats:
  26. pr=ft.get('properties') or {}
  27. code=str(pr.get('code') or '')
  28. if len(code)>=4: ind[(pref(code), code[2:4])]+=1
  29. print('prefix+biz code:', dict(ind))