Spaces:
Running
Running
th commited on
Commit ·
682729e
1
Parent(s): e6024b0
fix: 修复府相朝垣格匹配条件 + 宫名兼容
Browse files1. 府相朝垣格:改为联合宫位检查(天府天相分居财帛/官禄不限顺序)
原条件太死:要求天府固定在财帛+天相固定在官禄
实际可以反过来,关键是两星分居三方四正来朝
2. 宫名兼容:palace_map 同时注册带/不带"宫"字的别名
解决 iztro 返回"财帛"但条件写"财帛宫"找不到的问题
3. 新增 combined_palace_check 条件类型,支持多宫联合星曜检查
🦊 Generated with Sisi
- geju_matcher.py +60 -2
- geju_patterns.py +7 -10
geju_matcher.py
CHANGED
|
@@ -110,6 +110,9 @@ class GejuMatcher:
|
|
| 110 |
'palace_requirements': self._check_palace_requirements(
|
| 111 |
conditions, palace_map
|
| 112 |
),
|
|
|
|
|
|
|
|
|
|
| 113 |
'birth_year': self._check_birth_year(
|
| 114 |
conditions, birth_year_stem
|
| 115 |
),
|
|
@@ -158,9 +161,25 @@ class GejuMatcher:
|
|
| 158 |
'missing_conditions': missing_conditions
|
| 159 |
}
|
| 160 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
def _create_palace_map(self, palaces: List[dict]) -> Dict[str, dict]:
|
| 162 |
-
"""创建宫位名称到数据的映射"""
|
| 163 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
|
| 165 |
def _get_palace_stars(self, palace_data: dict) -> List[str]:
|
| 166 |
"""获取宫位的所有星曜名称"""
|
|
@@ -264,6 +283,45 @@ class GejuMatcher:
|
|
| 264 |
|
| 265 |
return {'checked': True, 'passed': True}
|
| 266 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 267 |
def _check_birth_year(
|
| 268 |
self,
|
| 269 |
conditions: dict,
|
|
|
|
| 110 |
'palace_requirements': self._check_palace_requirements(
|
| 111 |
conditions, palace_map
|
| 112 |
),
|
| 113 |
+
'combined_palace_check': self._check_combined_palaces(
|
| 114 |
+
conditions, palace_map
|
| 115 |
+
),
|
| 116 |
'birth_year': self._check_birth_year(
|
| 117 |
conditions, birth_year_stem
|
| 118 |
),
|
|
|
|
| 161 |
'missing_conditions': missing_conditions
|
| 162 |
}
|
| 163 |
|
| 164 |
+
def _normalize_palace_name(self, name: str) -> str:
|
| 165 |
+
"""标准化宫位名称,兼容带/不带'宫'字"""
|
| 166 |
+
aliases = {'奴仆': '仆役', '奴仆宫': '仆役', '交友': '仆役', '交友宫': '仆役'}
|
| 167 |
+
if name in aliases:
|
| 168 |
+
return aliases[name]
|
| 169 |
+
if name != '命宫' and name.endswith('宫'):
|
| 170 |
+
return name[:-1]
|
| 171 |
+
return name
|
| 172 |
+
|
| 173 |
def _create_palace_map(self, palaces: List[dict]) -> Dict[str, dict]:
|
| 174 |
+
"""创建宫位名称到数据的映射(支持带/不带宫字查询)"""
|
| 175 |
+
palace_map = {}
|
| 176 |
+
for palace in palaces:
|
| 177 |
+
name = palace.get('name', '')
|
| 178 |
+
palace_map[name] = palace
|
| 179 |
+
# 同时添加带宫字的别名
|
| 180 |
+
if name and name != '命宫' and not name.endswith('宫'):
|
| 181 |
+
palace_map[name + '宫'] = palace
|
| 182 |
+
return palace_map
|
| 183 |
|
| 184 |
def _get_palace_stars(self, palace_data: dict) -> List[str]:
|
| 185 |
"""获取宫位的所有星曜名称"""
|
|
|
|
| 283 |
|
| 284 |
return {'checked': True, 'passed': True}
|
| 285 |
|
| 286 |
+
def _check_combined_palaces(
|
| 287 |
+
self,
|
| 288 |
+
conditions: dict,
|
| 289 |
+
palace_map: dict
|
| 290 |
+
) -> Dict[str, Any]:
|
| 291 |
+
"""
|
| 292 |
+
检查多宫位联合星曜条件
|
| 293 |
+
|
| 294 |
+
用于府相朝垣格等格局:天府天相分居两宫,不限定哪颗在哪宫
|
| 295 |
+
"""
|
| 296 |
+
combined = conditions.get('combined_palace_check')
|
| 297 |
+
if not combined:
|
| 298 |
+
return {'checked': False, 'passed': True}
|
| 299 |
+
|
| 300 |
+
target_palaces = combined.get('palaces', [])
|
| 301 |
+
must_have = set(combined.get('must_have_stars', []))
|
| 302 |
+
|
| 303 |
+
# 收集所有目标宫位的主星
|
| 304 |
+
all_stars_in_palaces = set()
|
| 305 |
+
for p_name in target_palaces:
|
| 306 |
+
# 尝试多种宫名格式
|
| 307 |
+
palace = palace_map.get(p_name) or palace_map.get(p_name + '宫')
|
| 308 |
+
if palace:
|
| 309 |
+
for star in palace.get('major_stars', []):
|
| 310 |
+
name = star.get('name') if isinstance(star, dict) else star
|
| 311 |
+
if name:
|
| 312 |
+
all_stars_in_palaces.add(name)
|
| 313 |
+
|
| 314 |
+
# 检查必需的星是否都在这些宫位中
|
| 315 |
+
missing = must_have - all_stars_in_palaces
|
| 316 |
+
if missing:
|
| 317 |
+
return {
|
| 318 |
+
'checked': True,
|
| 319 |
+
'passed': False,
|
| 320 |
+
'reason': f'{"、".join(target_palaces)}中缺少:{"、".join(missing)}'
|
| 321 |
+
}
|
| 322 |
+
|
| 323 |
+
return {'checked': True, 'passed': True}
|
| 324 |
+
|
| 325 |
def _check_birth_year(
|
| 326 |
self,
|
| 327 |
conditions: dict,
|
geju_patterns.py
CHANGED
|
@@ -52,16 +52,13 @@ GEJU_PATTERNS = {
|
|
| 52 |
"description": "府相朝垣格,一生衣食无缺,六亲好,有口福,东作西成",
|
| 53 |
"conditions": {
|
| 54 |
"required_stars": [], # 命宫无需特定主星
|
| 55 |
-
"
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
}
|
| 63 |
-
],
|
| 64 |
-
"description": "命宫无主星,天府在财帛宫,天相在官禄宫来朝"
|
| 65 |
},
|
| 66 |
"effects": {
|
| 67 |
"positive": [
|
|
|
|
| 52 |
"description": "府相朝垣格,一生衣食无缺,六亲好,有口福,东作西成",
|
| 53 |
"conditions": {
|
| 54 |
"required_stars": [], # 命宫无需特定主星
|
| 55 |
+
"combined_palace_check": {
|
| 56 |
+
# 天府天相分居财帛、官禄来朝命宫(不限定哪颗在哪个宫)
|
| 57 |
+
"palaces": ["财帛", "官禄"],
|
| 58 |
+
"must_have_stars": ["天府", "天相"],
|
| 59 |
+
"description": "天府、天相二星一居财帛宫一居官禄宫,来合照命宫"
|
| 60 |
+
},
|
| 61 |
+
"description": "天府天相分居财帛官禄来朝命宫,或天府坐命加会天相"
|
|
|
|
|
|
|
|
|
|
| 62 |
},
|
| 63 |
"effects": {
|
| 64 |
"positive": [
|