Spaces:
Running
Running
th commited on
Commit ·
c7a4b25
1
Parent(s): e4560aa
规则库扩展v5.0:新增294条紫微断诀(SC903-SC1203)
Browse files- 从622条扩展到916条规则(+47.3%)
- 新增断诀来源:03-divination-rules700-1000.md
- ID重新编号避免冲突(原SC700-SC1000 → SC903-SC1203)
- 修复JSON格式问题(中文标点、age_range等)
- 测试通过:导入正常,查询功能正常
总增长率:+816%(相比初始100条)
🦊 Generated with Sisi
- batch_05_rules_clean.json +0 -0
- integrate_batch_05_robust.py +127 -0
- merge_batch_05_final.py +243 -0
- star_combination_rules.py +0 -0
batch_05_rules_clean.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
integrate_batch_05_robust.py
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
整合新断诀 Batch 05 - 更强大的JSON清理
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import json
|
| 7 |
+
import re
|
| 8 |
+
import sys
|
| 9 |
+
|
| 10 |
+
print("=" * 80)
|
| 11 |
+
print("🎉 紫微规则库扩展 Batch 05 (Robust)")
|
| 12 |
+
print("=" * 80)
|
| 13 |
+
|
| 14 |
+
# 1. 读取新断诀文件
|
| 15 |
+
print("\n📖 Step 1: 读取新断诀文件...")
|
| 16 |
+
source_file = "/Volumes/sparksverse/agent-knowledge/mingli-knowledge/eastern/ziwei/interpretations/03-divination-rules700-1000.md"
|
| 17 |
+
|
| 18 |
+
with open(source_file, 'r', encoding='utf-8') as f:
|
| 19 |
+
content = f.read()
|
| 20 |
+
|
| 21 |
+
# 2. 提取JSON数组
|
| 22 |
+
print("📖 Step 2: 提取JSON数组...")
|
| 23 |
+
start_idx = content.find('[')
|
| 24 |
+
end_idx = content.rfind(']')
|
| 25 |
+
|
| 26 |
+
if start_idx == -1 or end_idx == -1:
|
| 27 |
+
print("❌ 无法找到JSON数组!")
|
| 28 |
+
sys.exit(1)
|
| 29 |
+
|
| 30 |
+
json_str = content[start_idx:end_idx+1]
|
| 31 |
+
|
| 32 |
+
# 3. 强力清理JSON格式
|
| 33 |
+
print("🔧 Step 3: 强力清理JSON格式...")
|
| 34 |
+
|
| 35 |
+
# 修复age_range
|
| 36 |
+
json_str = re.sub(r'"age_range"\s*:\s*,', '"age_range": [20, 70],', json_str)
|
| 37 |
+
json_str = re.sub(r'"age_range"\s*:\s*null\s*,', '"age_range": [20, 70],', json_str)
|
| 38 |
+
json_str = re.sub(r'"age_range"\s*:\s*null\s*\}', '"age_range": [20, 70]\n }', json_str)
|
| 39 |
+
|
| 40 |
+
# 修复fortune_timing
|
| 41 |
+
json_str = re.sub(r'"fortune_timing"\s*:\s*null\s*,', '"fortune_timing": null,', json_str)
|
| 42 |
+
|
| 43 |
+
# 修复空数组
|
| 44 |
+
json_str = re.sub(r'\[\s*\]', '[]', json_str)
|
| 45 |
+
|
| 46 |
+
# 修复单词拼写错误
|
| 47 |
+
json_str = json_str.replace('"carEer"', '"career"')
|
| 48 |
+
json_str = json_str.replace('",\n }', '"\n }')
|
| 49 |
+
|
| 50 |
+
# 尝试解析
|
| 51 |
+
print("🔍 Step 4: 尝试解析JSON...")
|
| 52 |
+
try:
|
| 53 |
+
new_rules = json.loads(json_str)
|
| 54 |
+
print(f"✅ 成功提取 {len(new_rules)} 条规则")
|
| 55 |
+
except json.JSONDecodeError as e:
|
| 56 |
+
print(f"❌ JSON解析失败: {e}")
|
| 57 |
+
print(f" 位置: line {e.lineno}, column {e.colno}")
|
| 58 |
+
print(f" 错误内容:")
|
| 59 |
+
lines = json_str.split('\n')
|
| 60 |
+
if e.lineno <= len(lines):
|
| 61 |
+
for i in range(max(0, e.lineno-5), min(len(lines), e.lineno+5)):
|
| 62 |
+
prefix = ">>> " if i == e.lineno-1 else " "
|
| 63 |
+
print(f"{prefix}{i+1:4d}: {lines[i]}")
|
| 64 |
+
sys.exit(1)
|
| 65 |
+
|
| 66 |
+
# 5. 检查规则完整性
|
| 67 |
+
print("\n🔍 Step 5: 检查规则完整性...")
|
| 68 |
+
valid_rules = []
|
| 69 |
+
for i, rule in enumerate(new_rules):
|
| 70 |
+
if not rule.get('id'):
|
| 71 |
+
print(f"⚠️ Rule {i} 缺少ID,跳过")
|
| 72 |
+
continue
|
| 73 |
+
if not rule.get('name'):
|
| 74 |
+
print(f"⚠️ Rule {rule['id']} 缺少name,跳过")
|
| 75 |
+
continue
|
| 76 |
+
|
| 77 |
+
# 修复age_range
|
| 78 |
+
if rule.get('age_range') is None or rule.get('age_range') == '':
|
| 79 |
+
rule['age_range'] = [20, 70]
|
| 80 |
+
|
| 81 |
+
# 确保必需字段存在
|
| 82 |
+
rule.setdefault('category', '运势走向')
|
| 83 |
+
rule.setdefault('stars_required', [])
|
| 84 |
+
rule.setdefault('palace_types', [])
|
| 85 |
+
rule.setdefault('conditions', {})
|
| 86 |
+
rule.setdefault('interpretations', {})
|
| 87 |
+
rule.setdefault('effect_level', '中')
|
| 88 |
+
rule.setdefault('compatibility_score', 50)
|
| 89 |
+
rule.setdefault('source', '南北派实战断诀')
|
| 90 |
+
|
| 91 |
+
valid_rules.append(rule)
|
| 92 |
+
|
| 93 |
+
print(f"✅ 有效规则: {len(valid_rules)} 条")
|
| 94 |
+
|
| 95 |
+
# 6. 重新编号(+203偏移)
|
| 96 |
+
print("\n🔢 Step 6: 重新编号(SC700→SC903, +203偏移)...")
|
| 97 |
+
id_offset = 203
|
| 98 |
+
|
| 99 |
+
renumbered = 0
|
| 100 |
+
for rule in valid_rules:
|
| 101 |
+
old_id = rule['id']
|
| 102 |
+
match = re.match(r'SC(\d+)', old_id)
|
| 103 |
+
if match:
|
| 104 |
+
old_num = int(match.group(1))
|
| 105 |
+
new_num = old_num + id_offset
|
| 106 |
+
new_id = f'SC{new_num}'
|
| 107 |
+
rule['id'] = new_id
|
| 108 |
+
renumbered += 1
|
| 109 |
+
if renumbered <= 5 or renumbered > len(valid_rules) - 5:
|
| 110 |
+
print(f" {old_id} → {new_id}")
|
| 111 |
+
elif renumbered == 6:
|
| 112 |
+
print(f" ... ({len(valid_rules)-10} more) ...")
|
| 113 |
+
else:
|
| 114 |
+
print(f"⚠️ 无法解析ID: {old_id}")
|
| 115 |
+
|
| 116 |
+
print(f"✅ 重新编号完成: {renumbered} 条")
|
| 117 |
+
|
| 118 |
+
# 保存中间结果用于调试
|
| 119 |
+
debug_file = '/Volumes/sparksverse/huggingface-spaces/astrology-ziwei-api/batch_05_rules_debug.json'
|
| 120 |
+
with open(debug_file, 'w', encoding='utf-8') as f:
|
| 121 |
+
json.dump(valid_rules, f, ensure_ascii=False, indent=2)
|
| 122 |
+
print(f"📝 调试文件已保存: {debug_file}")
|
| 123 |
+
|
| 124 |
+
print("\n✅ 规则提取和重编号完成!")
|
| 125 |
+
print(f" 有效规则: {len(valid_rules)} 条")
|
| 126 |
+
print(f" ID范围: {valid_rules[0]['id']} - {valid_rules[-1]['id']}")
|
| 127 |
+
print("\n📝 下一步: 运行合并脚本将这些规则添加到API")
|
merge_batch_05_final.py
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
合并Batch 05规则到star_combination_rules.py
|
| 4 |
+
版本: v5.0 - 916条规则 (622 + 294)
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import json
|
| 8 |
+
import sys
|
| 9 |
+
sys.path.insert(0, '.')
|
| 10 |
+
|
| 11 |
+
print("=" * 80)
|
| 12 |
+
print("🎉🎉🎉 规则库扩展5.0 - Batch 05合并")
|
| 13 |
+
print("=" * 80)
|
| 14 |
+
|
| 15 |
+
# 1. 读取现有规则库
|
| 16 |
+
print("\n📖 读取现有规则库...")
|
| 17 |
+
from star_combination_rules import STAR_COMBINATION_RULES, RuleCategory, EffectLevel
|
| 18 |
+
|
| 19 |
+
original_rules = STAR_COMBINATION_RULES.copy()
|
| 20 |
+
print(f"✅ 原有规则: {len(original_rules)}条")
|
| 21 |
+
|
| 22 |
+
# 2. 读取Batch 05规则
|
| 23 |
+
print("\n📖 读取Batch 05规则...")
|
| 24 |
+
with open('batch_05_rules_clean.json', 'r', encoding='utf-8') as f:
|
| 25 |
+
batch_05_rules = json.load(f)
|
| 26 |
+
|
| 27 |
+
print(f"✅ Batch 05: {len(batch_05_rules)}条 (SC903-SC1203)")
|
| 28 |
+
|
| 29 |
+
# 3. Category和EffectLevel映射
|
| 30 |
+
category_map = {
|
| 31 |
+
'性格特质': 'RuleCategory.PERSONALITY',
|
| 32 |
+
'事业财运': 'RuleCategory.CAREER',
|
| 33 |
+
'婚姻感情': 'RuleCategory.RELATIONSHIP',
|
| 34 |
+
'健康状况': 'RuleCategory.HEALTH',
|
| 35 |
+
'运势走向': 'RuleCategory.FORTUNE',
|
| 36 |
+
'才华能力': 'RuleCategory.TALENT',
|
| 37 |
+
'人际交往': 'RuleCategory.SOCIAL'
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
effect_map = {
|
| 41 |
+
'极强': 'EffectLevel.VERY_STRONG',
|
| 42 |
+
'强': 'EffectLevel.STRONG',
|
| 43 |
+
'中': 'EffectLevel.MEDIUM',
|
| 44 |
+
'弱': 'EffectLevel.WEAK',
|
| 45 |
+
'微弱': 'EffectLevel.VERY_WEAK'
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
def format_value(v):
|
| 49 |
+
"""格式化值,处理None和字符串"""
|
| 50 |
+
if v is None:
|
| 51 |
+
return 'None'
|
| 52 |
+
elif isinstance(v, str):
|
| 53 |
+
# 转义字符串中的引号和反斜杠
|
| 54 |
+
v = v.replace('\\', '\\\\').replace("'", "\\'")
|
| 55 |
+
return f"'{v}'"
|
| 56 |
+
elif isinstance(v, list):
|
| 57 |
+
if not v:
|
| 58 |
+
return '[]'
|
| 59 |
+
# 格式化列表中的每个元素
|
| 60 |
+
formatted_items = [format_value(item) for item in v]
|
| 61 |
+
return '[' + ', '.join(formatted_items) + ']'
|
| 62 |
+
elif isinstance(v, dict):
|
| 63 |
+
if not v:
|
| 64 |
+
return '{}'
|
| 65 |
+
# 格式化字典
|
| 66 |
+
items = [f"'{k}': {format_value(v)}" for k, v in v.items()]
|
| 67 |
+
return '{' + ', '.join(items) + '}'
|
| 68 |
+
else:
|
| 69 |
+
return str(v)
|
| 70 |
+
|
| 71 |
+
def format_rule_for_file(rule, is_json=False):
|
| 72 |
+
"""格式化规则为Python文件格式"""
|
| 73 |
+
if is_json:
|
| 74 |
+
# 从JSON格式转换
|
| 75 |
+
category = category_map.get(rule.get('category', '运势走向'), 'RuleCategory.FORTUNE')
|
| 76 |
+
effect = effect_map.get(rule.get('effect_level', '中'), 'EffectLevel.MEDIUM')
|
| 77 |
+
|
| 78 |
+
conditions = rule.get('conditions', {})
|
| 79 |
+
interpretations = rule.get('interpretations', {})
|
| 80 |
+
age_range = rule.get('age_range', [20, 70])
|
| 81 |
+
|
| 82 |
+
else:
|
| 83 |
+
# 从现有规则格式转换
|
| 84 |
+
category_val = rule['category'].value if hasattr(rule['category'], 'value') else rule['category']
|
| 85 |
+
category = category_map.get(category_val, 'RuleCategory.FORTUNE')
|
| 86 |
+
|
| 87 |
+
effect_val = rule['effect_level'].value if hasattr(rule['effect_level'], 'value') else rule['effect_level']
|
| 88 |
+
effect = effect_map.get(effect_val, 'EffectLevel.MEDIUM')
|
| 89 |
+
|
| 90 |
+
conditions = rule.get('conditions', {})
|
| 91 |
+
interpretations = rule.get('interpretations', {})
|
| 92 |
+
age_range = rule.get('age_range', [20, 70])
|
| 93 |
+
|
| 94 |
+
# 构建规则字符串
|
| 95 |
+
rule_str = " {\n"
|
| 96 |
+
rule_str += f" \"id\": \"{rule['id']}\",\n"
|
| 97 |
+
rule_str += f" \"name\": {format_value(rule.get('name', ''))},\n"
|
| 98 |
+
rule_str += f" \"category\": {category},\n"
|
| 99 |
+
rule_str += f" \"stars_required\": {format_value(rule.get('stars_required', []))},\n"
|
| 100 |
+
rule_str += f" \"palace_types\": {format_value(rule.get('palace_types', []))},\n"
|
| 101 |
+
|
| 102 |
+
# Conditions
|
| 103 |
+
rule_str += f" \"conditions\": {{\n"
|
| 104 |
+
rule_str += f" 'same_palace': {conditions.get('same_palace', False)},\n"
|
| 105 |
+
rule_str += f" 'transformations': {format_value(conditions.get('transformations'))},\n"
|
| 106 |
+
rule_str += f" 'brightness': {format_value(conditions.get('brightness'))},\n"
|
| 107 |
+
rule_str += f" 'palace_position': {format_value(conditions.get('palace_position'))}\n"
|
| 108 |
+
rule_str += f" }},\n"
|
| 109 |
+
|
| 110 |
+
# Interpretations
|
| 111 |
+
rule_str += f" \"interpretations\": {{\n"
|
| 112 |
+
rule_str += f" 'core_meaning': {format_value(interpretations.get('core_meaning', ''))},\n"
|
| 113 |
+
rule_str += f" 'personality': {format_value(interpretations.get('personality', []))},\n"
|
| 114 |
+
rule_str += f" 'career': {format_value(interpretations.get('career', []))},\n"
|
| 115 |
+
rule_str += f" 'relationship': {format_value(interpretations.get('relationship', []))},\n"
|
| 116 |
+
rule_str += f" 'fortune_timing': {format_value(interpretations.get('fortune_timing'))},\n"
|
| 117 |
+
rule_str += f" 'warnings': {format_value(interpretations.get('warnings', []))}\n"
|
| 118 |
+
rule_str += f" }},\n"
|
| 119 |
+
|
| 120 |
+
rule_str += f" \"effect_level\": {effect},\n"
|
| 121 |
+
rule_str += f" \"compatibility_score\": {rule.get('compatibility_score', 50)},\n"
|
| 122 |
+
rule_str += f" \"age_range\": {format_value(age_range)},\n"
|
| 123 |
+
rule_str += f" \"source\": {format_value(rule.get('source', '南北派实战断诀'))}\n"
|
| 124 |
+
rule_str += " }"
|
| 125 |
+
|
| 126 |
+
return rule_str
|
| 127 |
+
|
| 128 |
+
# 4. 格式化所有规则
|
| 129 |
+
print("\n📝 格式化规则...")
|
| 130 |
+
formatted_rules = []
|
| 131 |
+
|
| 132 |
+
# 原有规则
|
| 133 |
+
for rule in original_rules:
|
| 134 |
+
formatted_rules.append(format_rule_for_file(rule, is_json=False))
|
| 135 |
+
|
| 136 |
+
# 新规则
|
| 137 |
+
for rule in batch_05_rules:
|
| 138 |
+
formatted_rules.append(format_rule_for_file(rule, is_json=True))
|
| 139 |
+
|
| 140 |
+
rules_code = ',\n'.join(formatted_rules)
|
| 141 |
+
|
| 142 |
+
# 5. 生成新文件
|
| 143 |
+
print("\n📝 生成新的star_combination_rules.py...")
|
| 144 |
+
|
| 145 |
+
file_content = f'''"""
|
| 146 |
+
星曜组合断语库 - Star Combination Interpretation Rules
|
| 147 |
+
从138页《紫微斗数南北派断诀》提取的916条星曜组合规则。
|
| 148 |
+
|
| 149 |
+
Version: 5.0 (规则库扩展5.0:100条 → 916条!🎉🎉🎉🎉)
|
| 150 |
+
Update History:
|
| 151 |
+
- v1.0 (2025-12-08): 初始100条规则(手动精选)
|
| 152 |
+
- v2.0 (2025-12-11): 新增120条规则(Google Notebook半自动提取)SC301-SC420
|
| 153 |
+
- v3.0 (2025-12-12): 新增100条规则(Batch 03)SC501-SC600
|
| 154 |
+
- v4.0 (2025-12-13): 新增292条规则(Batch 04)SC601-SC892
|
| 155 |
+
- v5.0 (2025-12-13): 新增294条规则(Batch 05)SC903-SC1203
|
| 156 |
+
|
| 157 |
+
Last Updated: 2025-12-13
|
| 158 |
+
"""
|
| 159 |
+
|
| 160 |
+
from typing import Dict, List, Any, Optional
|
| 161 |
+
from enum import Enum
|
| 162 |
+
|
| 163 |
+
class RuleCategory(Enum):
|
| 164 |
+
"""规则分类"""
|
| 165 |
+
PERSONALITY = "性格特质"
|
| 166 |
+
CAREER = "事业财运"
|
| 167 |
+
RELATIONSHIP = "婚姻感情"
|
| 168 |
+
HEALTH = "健康状况"
|
| 169 |
+
FORTUNE = "运势走向"
|
| 170 |
+
TALENT = "才华能力"
|
| 171 |
+
SOCIAL = "人际交往"
|
| 172 |
+
|
| 173 |
+
class EffectLevel(Enum):
|
| 174 |
+
"""影响程度"""
|
| 175 |
+
VERY_STRONG = "极强"
|
| 176 |
+
STRONG = "强"
|
| 177 |
+
MEDIUM = "中"
|
| 178 |
+
WEAK = "弱"
|
| 179 |
+
VERY_WEAK = "微弱"
|
| 180 |
+
|
| 181 |
+
STAR_COMBINATION_RULES = [
|
| 182 |
+
{rules_code}
|
| 183 |
+
]
|
| 184 |
+
|
| 185 |
+
def get_rule_by_id(rule_id: str) -> Optional[Dict[str, Any]]:
|
| 186 |
+
"""根据ID获取规则"""
|
| 187 |
+
for rule in STAR_COMBINATION_RULES:
|
| 188 |
+
if rule['id'] == rule_id:
|
| 189 |
+
return rule
|
| 190 |
+
return None
|
| 191 |
+
|
| 192 |
+
def get_rules_by_category(category: RuleCategory) -> List[Dict[str, Any]]:
|
| 193 |
+
"""根据分类获取规则"""
|
| 194 |
+
return [rule for rule in STAR_COMBINATION_RULES if rule['category'] == category]
|
| 195 |
+
|
| 196 |
+
def get_rules_by_stars(stars: List[str]) -> List[Dict[str, Any]]:
|
| 197 |
+
"""根据星曜名称搜索规则"""
|
| 198 |
+
matched_rules = []
|
| 199 |
+
for rule in STAR_COMBINATION_RULES:
|
| 200 |
+
required_stars = set(rule['stars_required'])
|
| 201 |
+
input_stars = set(stars)
|
| 202 |
+
if required_stars.issubset(input_stars):
|
| 203 |
+
matched_rules.append(rule)
|
| 204 |
+
return matched_rules
|
| 205 |
+
|
| 206 |
+
def get_all_rule_ids() -> List[str]:
|
| 207 |
+
"""获取所有规则ID"""
|
| 208 |
+
return [rule['id'] for rule in STAR_COMBINATION_RULES]
|
| 209 |
+
|
| 210 |
+
def get_rules_count() -> int:
|
| 211 |
+
"""获取规则总数"""
|
| 212 |
+
return len(STAR_COMBINATION_RULES)
|
| 213 |
+
|
| 214 |
+
def get_rules_by_palace(palace_type: str) -> List[Dict[str, Any]]:
|
| 215 |
+
"""根据宫位类型获取规则"""
|
| 216 |
+
return [rule for rule in STAR_COMBINATION_RULES if palace_type in rule['palace_types']]
|
| 217 |
+
'''
|
| 218 |
+
|
| 219 |
+
# 6. 保存文件
|
| 220 |
+
with open('star_combination_rules.py', 'w', encoding='utf-8') as f:
|
| 221 |
+
f.write(file_content)
|
| 222 |
+
|
| 223 |
+
total_rules = len(original_rules) + len(batch_05_rules)
|
| 224 |
+
print(f"✅ 生成完成!")
|
| 225 |
+
print(f" 文件大小: {len(file_content) // 1024}KB")
|
| 226 |
+
print(f" 规则总数: {total_rules}条")
|
| 227 |
+
|
| 228 |
+
print("\n" + "=" * 80)
|
| 229 |
+
print("🎉🎉🎉 规则库扩展5.0完成!")
|
| 230 |
+
print("=" * 80)
|
| 231 |
+
print(f" v1.0 (2025-12-08): 100条规则")
|
| 232 |
+
print(f" v2.0 (2025-12-11): 220条规则 (+120)")
|
| 233 |
+
print(f" v3.0 (2025-12-12): 320条规则 (+100)")
|
| 234 |
+
print(f" v4.0 (2025-12-13): 622条规则 (+302)")
|
| 235 |
+
print(f" v5.0 (2025-12-13): 916条规则 (+294) ✨✨✨")
|
| 236 |
+
print()
|
| 237 |
+
print(f" 📈 总增长率: +816% (相比最初100条)")
|
| 238 |
+
print(f" 📈 本次增长: +47.3% (相比v4.0的622条)")
|
| 239 |
+
print(f" 🎯 新增ID范围: SC903-SC1203")
|
| 240 |
+
print("=" * 80)
|
| 241 |
+
|
| 242 |
+
print("\n✅ v5.0 规则库准备完成!")
|
| 243 |
+
print("📝 下一步: 测试导入,然后部署到HuggingFace")
|
star_combination_rules.py
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|