audit_metadata.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. """Audit metadata consistency across all knowledge documents."""
  2. import os
  3. docs_dir = r'E:\workspace\dan\num\knowledge\research'
  4. results = []
  5. for f in sorted(os.listdir(docs_dir)):
  6. if not f.endswith('.md'):
  7. continue
  8. path = os.path.join(docs_dir, f)
  9. content = open(path, 'r', encoding='utf-8').read()
  10. lines = content.split('\n')
  11. # Check frontmatter
  12. has_frontmatter = content.startswith('---')
  13. if not has_frontmatter:
  14. results.append((f, 'NO_FRONTMATTER'))
  15. continue
  16. # Parse frontmatter
  17. in_frontmatter = False
  18. tags = []
  19. title = ''
  20. confidence = ''
  21. has_tags = False
  22. for line in lines[:40]:
  23. if line.strip() == '---':
  24. in_frontmatter = not in_frontmatter
  25. continue
  26. if in_frontmatter:
  27. if line.startswith('title:'):
  28. title = line.replace('title:', '').strip().strip('"').strip("'")
  29. elif line.startswith('confidence:'):
  30. confidence = line.split(':')[1].strip()
  31. elif line.startswith('tags:'):
  32. has_tags = True
  33. elif line.strip().startswith('- ') and in_frontmatter:
  34. tags.append(line.strip().lstrip('- ').strip())
  35. file_size = os.path.getsize(path)
  36. line_count = len(lines)
  37. # Determine which layer (A/B/C/D/E/other) the doc belongs to
  38. layer = 'OTHER'
  39. if f.startswith('A') or '命盘24位置' in f:
  40. layer = 'A'
  41. elif f.startswith('B') or '八星' in f or '联合密码' in f or '三角命盘组合' in f:
  42. layer = 'B'
  43. elif f.startswith('C') or '维度手册' in f or '五区三组' in f or '数字0与5' in f:
  44. layer = 'C'
  45. elif f.startswith('D') or '递进' in f or '组合能量' in f:
  46. layer = 'D'
  47. elif f.startswith('E') or '天赋数' in f:
  48. layer = 'E'
  49. print(f'{layer} | {f:40s} | tags={len(tags):2d} | conf={confidence:8s} | {line_count:4d}行 | {file_size:6d}B')
  50. if not has_tags:
  51. print(f' >>> WARNING: No tags found in {f}')
  52. if not confidence:
  53. print(f' >>> WARNING: No confidence in {f}')