Spaces:
Running
Running
Download geju_patterns.py from sisithefox/astrology-ziwei-api: direct link, hf CLI and curl.
- Browser
- Download file 55.8 kB
-
https://huggingface.co/spaces/sisithefox/astrology-ziwei-api/resolve/main/geju_patterns.py
- Command line
-
hf download hf://spaces/sisithefox/astrology-ziwei-api/geju_patterns.py
-
curl -L -o geju_patterns.py https://huggingface.co/spaces/sisithefox/astrology-ziwei-api/resolve/main/geju_patterns.py
55.8 kB
"""
格局识别规则库 - Pattern Recognition Rules Database
紫微斗数格局(吉格、凶格、特殊格局)
格局是紫微斗数分析的核心,由特定星曜组合在特定宫位形成。
格局优先级:格局 > 单星 > 宫位
数据来源:
- /Volumes/sparksverse/agent-knowledge/mingli-knowledge/eastern/ziwei/interpretations/01-practical-divination.md
- 南北派断诀(朱云山)138页实战经验
Created: 2025-12-12
Author: Sisi 🦊
Version: 1.0 - 初版(30+核心格局)
"""
from typing import Dict, List, Any, Optional
from enum import Enum
class PatternType(Enum):
"""格局类型"""
AUSPICIOUS = "吉格" # 吉格
INAUSPICIOUS = "凶格" # 凶格
SPECIAL = "特殊格" # 特殊格(半吉半凶)
CAREER = "事业格" # 事业成就格
WEALTH = "财富格" # 财富格
PEACH_BLOSSOM = "桃花格" # 桃花感情格
POWER = "权贵格" # 权力地位格
class PatternLevel(Enum):
"""格局等级"""
TOP = "上上格" # 极品格局(90-100分)
UPPER = "上格" # 优良格局(80-89分)
MEDIUM = "中格" # 中等格局(60-79分)
LOWER = "下格" # 较差格局(40-59分)
POOR = "破格" # 破格(0-39分)
# ============================================================================
# 核心格局数据库(30+经典格局)
# ============================================================================
GEJU_PATTERNS = {
# ========== 吉格(高贵格局)==========
"府相朝垣格": {
"type": PatternType.AUSPICIOUS,
"level": PatternLevel.UPPER,
"score_range": (80, 95),
"description": "府相朝垣格,一生衣食无缺,六亲好,有口福,东作西成",
"conditions": {'any_conditions': [{'palace_requirements': [{'palace': '财帛', 'required_stars': ['天府']},
{'palace': '官禄', 'required_stars': ['天相']}]},
{'palace_requirements': [{'palace': '财帛', 'required_stars': ['天相']},
{'palace': '官禄', 'required_stars': ['天府']}]}]},
"effects": {
"positive": [
"一生衣食无缺",
"六亲关系和睦",
"有口福,常得人请客",
"东作西成,付出有回报",
"不怕火鈴,遇之不能衝破"
],
"negative": [
"甚忌擎羊,会破格"
]
},
"suitable_careers": ["公职人员", "管理层", "服务业", "餐饮业"],
"fortune_timing": "稳步上升,中年后更佳",
"notes": "流年行抵府相朝垣,会有合作、合夥事发生"
},
"紫府夹命格": {
"type": PatternType.POWER,
"level": PatternLevel.UPPER,
"score_range": (85, 98),
"description": '命宫在寅或申,天机太阴同坐,紫微与天府分居前后两宫相夹。',
"conditions": {'required_stars': ['天机', '太阴'], 'palace_positions': ['寅', '申'], 'flanking_stars': ['紫微', '天府']},
"effects": {
"positive": [
"权贵之命,地位崇高",
"统御才能,一呼百诺",
"会吉星主大富大贵",
"领导能力强,部属众多"
],
"negative": [
"无吉星会合,仅为常人"
]
},
"suitable_careers": ["政治家", "企业高管", "军官", "董事长"],
"fortune_timing": "早年显贵,终身享福",
"birth_year_preferences": ["甲", "丙", "戊"]
},
"机月同梁格": {
"type": PatternType.AUSPICIOUS,
"level": PatternLevel.MEDIUM,
"score_range": (70, 85),
"description": "机月同梁格,平稳发展,安于现实,宜研究工作",
"conditions": {'san_fang_stars': {'center': '命宫', 'must_have_all': ['天机', '太阴', '天同', '天梁']}},
"effects": {
"positive": [
"平稳发展,少风波",
"安于现实,知足常乐",
"适合研究工作",
"偏向脑力工作"
],
"negative": [
"性格保守",
"不宜大起大落的行业"
]
},
"suitable_careers": ["研究员", "教授", "技术专家", "中间商", "代理人"],
"fortune_timing": "一生平稳,晚年安逸"
},
"机巨同临格": {
"type": PatternType.CAREER,
"level": PatternLevel.UPPER,
"score_range": (82, 93),
"description": "机巨同临格,位至公卿,适合男命",
"conditions": {
"required_stars": ["天机", "巨门"],
"palace_positions": ["卯"], # 在卯宫最佳
"required_birth_years": ["乙", "辛", "己", "丙"],
"auspicious_stars": ["祿存", "文曲", "天魁"],
"avoid_stars": ["擎羊", "陀罗"],
"description": "天机巨门同宫在卯,会祿存文昌为极品之贵"
},
"effects": {
"positive": [
"位至公卿,官运亨通",
"会吉方论,富贵双全",
"乙生人双祿入命为上格",
"不依靠祖业,自己打拼"
],
"negative": [
"见羊陀男女淫邪",
"三方殺湊必遭大厄",
"女命雖富貴不免淫佚"
]
},
"suitable_careers": ["政府官员", "法官", "企业高管"],
"fortune_timing": "早年辛苦奔波,中年后兴旺",
"gender_preference": "男命为佳"
},
"日照雷门格": {
"type": PatternType.POWER,
"level": PatternLevel.TOP,
"score_range": (88, 96),
"description": '太阳天梁在卯位同守命宫,太阳庙旺;本库按白天出生、同会吉曜的严格条件识别。',
"conditions": {'required_stars': ['太阳', '天梁'],
'palace_positions': ['卯'],
'brightness': {'太阳': ['庙', '旺']},
'birth_hours': [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],
'auspicious_stars': ['左辅', '右弼', '文昌', '文曲', '天魁', '天钺']},
"effects": {
"positive": [
"白天生人见诸吉守照必大贵",
"生平福寿双全",
"名聲好,社會評價高",
"昌曲魁鉞会,早發青雲",
"左右昌曲加会,出将入相"
],
"negative": [
"夜生人力量减弱",
"太阳落陷则破格"
]
},
"suitable_careers": ["政治家", "高级公务员", "将军", "企业家"],
"fortune_timing": "早年即显贵,终身荣华"
},
"贪武同行格": {
"type": PatternType.WEALTH,
"level": PatternLevel.UPPER,
"score_range": (78, 88),
"description": "贪武同行格,早年辛苦,30岁后开始发达",
"conditions": {
"required_stars": ["武曲", "贪狼"],
"palace_positions": ["丑", "未"],
"description": "武曲贪狼同宫在丑未"
},
"effects": {
"positive": [
"早年辛苦经营,30岁以后开始发达",
"不喜欢继承祖业,自己创业",
"爱好自由,不吃低头饭",
"会火鈴主横发暴富"
],
"negative": [
"会桃花星则桃花特重",
"女命神邪淫"
]
},
"suitable_careers": ["创业", "金融", "投资", "贸易"],
"fortune_timing": "30岁前辛苦,30岁后发达"
},
"火贪格": {
"type": PatternType.WEALTH,
"level": PatternLevel.UPPER,
"score_range": (75, 90),
"description": "火贪格,突发横财,有意料之外的机遇",
"conditions": {'required_stars': ['贪狼'],
'palace_positions': ['寅', '午', '戌'],
'san_fang_stars': {'center': '命宫', 'must_have_all': ['火星']}},
"effects": {
"positive": [
"有机运,料想不到的突发事",
"横发暴富的可能",
"会权祿主管老闆,发展不错",
"中晚年名利好"
],
"negative": [
"来得快去得也快",
"需把握机会"
]
},
"suitable_careers": ["投资", "股票", "房地产", "投机行业"],
"fortune_timing": "突发横财,时机不定"
},
"铃贪格": {
"type": PatternType.WEALTH,
"level": PatternLevel.MEDIUM,
"score_range": (72, 88),
"description": "铃贪格,横发之命,财运突发",
"conditions": {'required_stars': ['贪狼'], 'san_fang_stars': {'center': '命宫', 'must_have_all': ['铃星']}},
"effects": {
"positive": [
"横发之财,突然发达",
"有意料之外的机遇",
"会权祿发展相当好"
],
"negative": [
"不如火贪稳定"
]
},
"suitable_careers": ["投资", "贸易", "创业"],
"fortune_timing": "突发横财"
},
"壽星入廟格": {
"type": PatternType.AUSPICIOUS,
"level": PatternLevel.UPPER,
"score_range": (82, 92),
"description": "壽星入廟格,官资清显,福寿双全",
"conditions": {'required_stars': ['天梁'],
'palace_positions': ['午'],
'required_birth_years': ['丁', '己', '癸'],
'description': '天梁在午宫入庙,逢吉星',
'brightness': {'天梁': ['庙']}},
"effects": {
"positive": [
"官资清显,地位崇高",
"生平福寿双全",
"左右昌曲会,出将入相格",
"昌祿会,臚传第一名"
],
"negative": []
},
"suitable_careers": ["政府高官", "法官", "医生", "学者"],
"fortune_timing": "中老年尤佳,长寿"
},
"仰鬥格": {
"type": PatternType.CAREER,
"level": PatternLevel.UPPER,
"score_range": (80, 92),
"description": "仰鬥格,成就大,多因得人提携而有成",
"conditions": {
"required_stars": ["七杀"],
"palace_positions": ["子", "寅"],
"description": "七杀在子宫或寅宫"
},
"effects": {
"positive": [
"成就大,事业有成",
"多因得贵人提携而有成",
"不依赖祖业,白手起家"
],
"negative": [
"早年历尽艰辛"
]
},
"suitable_careers": ["军职", "警察", "企业家", "开创性事业"],
"fortune_timing": "早年辛苦,中年后成就大"
},
# ========== 凶格/特殊格局 ==========
"刑囚夹印格": {
"type": PatternType.INAUSPICIOUS,
"level": PatternLevel.POOR,
"score_range": (20, 40),
"description": "刑囚夹印格,一生有訴訟刑罰之事",
"conditions": {'required_stars': ['廉贞', '天相'],
'palace_positions': ['子', '午'],
'any_conditions': [{'required_stars': ['擎羊']}, {'flanking_stars': ['擎羊', '陀罗']}]},
"effects": {
"positive": [],
"negative": [
"一生有訴訟之事,从大限参详",
"女命尤其不好:丈夫早亡、流产、开刀",
"本身廉贞化忌更严重",
"刑罚、监狱、官司不断"
]
},
"suitable_careers": ["法律相关(律师、法官)"],
"fortune_timing": "一生多波折,需谨慎",
"warning": "女命此格大凶,需特别注意",
"resolution": "多行善事,远离是非"
},
"泛水桃花格": {
"type": PatternType.PEACH_BLOSSOM,
"level": PatternLevel.POOR,
"score_range": (25, 45),
"description": '贪狼在子位与擎羊同坐命宫,或在亥位与陀罗同坐命宫;感情与欲望的取舍需结合全盘。',
"conditions": {'required_stars': ['贪狼'],
'any_conditions': [{'palace_positions': ['子'], 'required_stars': ['擎羊']},
{'palace_positions': ['亥'], 'required_stars': ['陀罗']}]},
"effects": {
"positive": [],
"negative": [
"感情複雜,桃花氾濫",
"加羊陀更厲害",
"女命会咸池天姚紅鸞,感情很不好",
"不会羊陀也好幻想,感情複雜"
]
},
"suitable_careers": ["娱乐业", "演艺圈"],
"fortune_timing": "感情多波折",
"warning": "需克制情欲,远离酒色"
},
"桃花犯主格": {
"type": PatternType.PEACH_BLOSSOM,
"level": PatternLevel.LOWER,
"score_range": (35, 55),
"description": "桃花犯主格,紫微逢桃花星,感情纠葛",
"conditions": {'required_stars': ['紫微', '贪狼'],
'palace_positions': ['卯', '酉'],
'any_conditions': [{'flanking_stars': ['左辅', '右弼']},
{'flanking_stars': ['文昌', '文曲']},
{'required_stars': ['天姚', '咸池', '文曲']}]},
"effects": {
"positive": [],
"negative": [
"紫贪卯酉要防患感情色欲問題起糾葛",
"加桃花星更厲害",
"会有一段明显繽紛的感情糾纏"
]
},
"suitable_careers": ["艺术", "娱乐"],
"fortune_timing": "感情多纠葛",
"warning": "需注意感情问题"
},
"跋涉他鄉格": {
"type": PatternType.SPECIAL,
"level": PatternLevel.MEDIUM,
"score_range": (60, 75),
"description": "跋涉他鄉格,一生远行,适合海外发展",
"conditions": {'required_stars': ['天机', '太阴'],
'palace_positions': ['寅', '申'],
'san_fang_stars': {'center': '命宫', 'must_have_all': ['天马']}},
"effects": {
"positive": [
"适合海外发展",
"远行机会多",
"会马主远行,限逢環境有變動"
],
"negative": [
"一生奔波劳碌",
"难以安定"
]
},
"suitable_careers": ["外贸", "航空", "旅游", "海外工作"],
"fortune_timing": "远方发展更佳"
},
"破蕩格": {
"type": PatternType.SPECIAL,
"level": PatternLevel.LOWER,
"score_range": (40, 60),
"description": "破蕩格,先破砠業而後興,大起大落",
"conditions": {
"required_stars": ["巨门"],
"palace_positions": ["卯", "酉"],
"description": "巨门在卯酉宫(卯吉,酉差)"
},
"effects": {
"positive": [
"在艺术方面有特殊才能",
"中年后发达",
"先破后兴,终有成就"
],
"negative": [
"早年辛勞奔波",
"成败起伏大",
"绝对多数不继祖业"
]
},
"suitable_careers": ["艺术", "自由职业", "技术"],
"fortune_timing": "早年辛苦,中年后发达"
},
# ========== v3.1: 新增格局(来源: iztro.com/learn/pattern.html) ==========
# --- 紫微系列 ---
"君臣庆会格": {
"type": PatternType.POWER,
"level": PatternLevel.TOP,
"score_range": (88, 98),
"description": "君臣庆会格,紫微得辅弼同守命宫,材善经邦,得道多助",
"conditions": {
"required_stars": ["紫微", "左辅", "右弼"],
"san_fang_stars": {
"center": "命宫",
"must_not_have": ["擎羊", "陀罗", "火星", "铃星", "地空", "地劫"],
"no_huaji_in_san_fang": True,
"description": "三方四正无煞忌才成格(最严格条件)"
},
"description": "紫微左右同守命宫(全书原文),三方四正无煞忌"
},
"effects": {
"positive": ["位极人臣,材善经邦", "得道多助,众人辅佐", "谦逊有远见,易被提拔", "善于发现和解决问题"],
"negative": ["三方四正有煞忌则不成格", "需紫微与辅弼同宫方论"]
},
"suitable_careers": ["企业管理层", "政府官员", "组织领导"],
"fortune_timing": "职业规划清晰,稳步上升"
},
"紫府同宫格": {
"type": PatternType.POWER,
"level": PatternLevel.UPPER,
"score_range": (82, 94),
"description": "紫府同宫格,帝星与财库同宫,富贵双全",
"conditions": {
"required_stars": ["紫微", "天府"],
"palace_positions": ["寅", "申"],
"description": "紫微天府同在寅宫或申宫"
},
"effects": {
"positive": ["富贵双全", "领导力+理财力兼备", "一生衣食无忧"],
"negative": ["无煞方论,有煞减力"]
},
"suitable_careers": ["管理层", "金融", "企业家"],
"fortune_timing": "稳步上升,一生富贵"
},
"极向离明格": {
"type": PatternType.POWER,
"level": PatternLevel.TOP,
"score_range": (90, 98),
"description": "极向离明格,紫微在午宫独坐,位居至尊",
"conditions": {
"required_stars": ["紫微"],
"palace_positions": ["午"],
"san_fang_stars": {
"center": "命宫",
"must_not_have": ["擎羊", "陀罗", "火星", "铃星", "地空", "地劫"],
"no_huaji_in_san_fang": True,
"description": "三方四正无煞星、无化忌方成格"
},
"description": "紫微在午宫守命,三方四正无煞忌"
},
"effects": {
"positive": ["至尊之位,权贵极品", "百官朝拱,众星捧月", "加左右昌曲更佳"],
"negative": ["有刑忌煞星则破格", "午宫地劫同宫也减力"]
},
"suitable_careers": ["国家领导", "大企业家", "将军"],
"fortune_timing": "早年即显贵"
},
"极居卯酉格": {
"type": PatternType.SPECIAL,
"level": PatternLevel.MEDIUM,
"score_range": (55, 75),
"description": "极居卯酉格,紫微贪狼同宫,物欲与尊贵交织",
"conditions": {
"required_stars": ["紫微", "贪狼"],
"palace_positions": ["卯", "酉"],
"description": "紫微贪狼在卯宫或酉宫同宫"
},
"effects": {
"positive": ["多才多艺", "有领袖魅力", "加火铃主横发"],
"negative": ["桃花重", "容易沉迷享乐", "加桃花星感情纠葛"]
},
"suitable_careers": ["娱乐业", "艺术", "公关", "外交"],
"fortune_timing": "中年后渐入佳境"
},
"金舆扶驾格": {
"type": PatternType.POWER,
"level": PatternLevel.UPPER,
"score_range": (82, 92),
"description": '天府坐命,太阳与太阴分居前后两宫相夹;是资源与支持关系的结构参考。',
"conditions": {'required_stars': ['天府'], 'flanking_stars': ['太阳', '太阴']},
"effects": {
"positive": ["贵人助力极强", "日月辅佐帝星", "富贵长久"],
"negative": ["无日月会合则不成格"]
},
"suitable_careers": ["政界", "管理层", "大企业"],
"fortune_timing": "一生贵人不断"
},
# --- 日月系列 ---
"日月同宫格": {
"type": PatternType.AUSPICIOUS,
"level": PatternLevel.MEDIUM,
"score_range": (65, 80),
"description": "日月同宫格,太阳太阴同在丑未,阴阳调和",
"conditions": {
"required_stars": ["太阳", "太阴"],
"palace_positions": ["丑", "未"],
"description": "太阳太阴在丑宫或未宫同宫"
},
"effects": {
"positive": ["性格温和", "善于协调", "人缘好"],
"negative": ["丑宫日月反背偏暗", "未宫日月并明偏吉"]
},
"suitable_careers": ["外交", "协调", "服务业"],
"fortune_timing": "一生平稳"
},
"巨日同宫格": {
"type": PatternType.AUSPICIOUS,
"level": PatternLevel.UPPER,
"score_range": (75, 88),
"description": "巨日同宫格,太阳巨门同宫,明日驱暗,化暗为明",
"conditions": {
"required_stars": ["巨门", "太阳"],
"palace_positions": ["寅", "申"],
"description": "巨门太阳在寅宫或申宫同宫"
},
"effects": {
"positive": ["口才极佳", "化暗为明,化解小人", "寅宫尤佳(旭日升天)"],
"negative": ["申宫较弱(日落西山)"]
},
"suitable_careers": ["律师", "教师", "演说家", "外交官"],
"fortune_timing": "早年显才,中年有成"
},
"日月并明格": {
"type": PatternType.AUSPICIOUS,
"level": PatternLevel.UPPER,
"score_range": (80, 93),
"description": '太阳、太阴均在命宫三方四正,且两星亮度均为庙或旺。',
"conditions": {'san_fang_stars': {'center': '命宫',
'must_have_all': ['太阳', '太阴'],
'brightness': {'太阳': ['庙', '旺'], '太阴': ['庙', '旺']}}},
"effects": {
"positive": ["光明磊落", "一生顺遂", "官运亨通", "男女皆吉"],
"negative": ["需日月均在庙旺方成格"]
},
"suitable_careers": ["政府", "大企业", "管理层"],
"fortune_timing": "一生光明"
},
"日月反背格": {
"type": PatternType.INAUSPICIOUS,
"level": PatternLevel.LOWER,
"score_range": (30, 50),
"description": '太阳、太阴均在命宫三方四正,且两星均为陷;这表示发挥较费力,不等于一生失意。',
"conditions": {'san_fang_stars': {'center': '命宫',
'must_have_all': ['太阳', '太阴'],
'brightness': {'太阳': ['陷'], '太阴': ['陷']}}},
'effects': {'positive': ['靠积累建立实力', '适合循序推进'], 'negative': ['推进较费力', '需主动争取支持']},
'suitable_careers': ['需结合官禄、财帛宫判断'],
'fortune_timing': '结合大限流年与吉曜支持看发挥',
},
"月朗天门格": {
"type": PatternType.AUSPICIOUS,
"level": PatternLevel.UPPER,
"score_range": (80, 92),
"description": "月朗天门格,太阴在亥宫入庙守命,夜生人大贵",
"conditions": {
"required_stars": ["太阴"],
"palace_positions": ["亥"],
"description": "太阴在亥宫守命"
},
"effects": {
"positive": ["夜生人大贵", "才华出众", "女命尤佳", "加左右昌曲极品"],
"negative": ["日生人力量减半"]
},
"suitable_careers": ["文学", "艺术", "设计", "金融"],
"fortune_timing": "中年后大发"
},
"月生沧海格": {
"type": PatternType.AUSPICIOUS,
"level": PatternLevel.UPPER,
"score_range": (78, 90),
"description": "月生沧海格(水澄桂萼),太阴天同在子宫,清贵之格",
"conditions": {
"required_stars": ["太阴", "天同"],
"palace_positions": ["子"],
"description": "太阴天同在子宫"
},
"effects": {
"positive": ["清贵温和", "文学才华高", "福气深厚", "晚年尤佳"],
"negative": ["早年平淡"]
},
"suitable_careers": ["学者", "文人", "教育", "艺术"],
"fortune_timing": "晚年福厚"
},
"明珠出海格": {
"type": PatternType.AUSPICIOUS,
"level": PatternLevel.UPPER,
"score_range": (80, 92),
"description": '命宫在未且无本命主星,太阳在卯、太阴在亥,均以庙旺来照命宫。',
"conditions": {'palace_positions': ['未'],
'empty_major_stars': True,
'star_positions': {'太阳': ['卯'], '太阴': ['亥']},
'san_fang_stars': {'center': '命宫',
'must_have_all': ['太阳', '太阴'],
'brightness': {'太阳': ['庙', '旺'], '太阴': ['庙', '旺']}}},
"effects": {
"positive": ["光彩夺目", "才华横溢", "名利双收"],
"negative": ["需日月均在庙旺"]
},
"suitable_careers": ["文化", "教育", "艺术", "外交"],
"fortune_timing": "中年后发达"
},
"金灿光辉格": {
"type": PatternType.POWER,
"level": PatternLevel.UPPER,
"score_range": (82, 94),
"description": "金灿光辉格(日丽中天),太阳在午宫独守,光芒万丈",
"conditions": {'required_stars': ['太阳'],
'palace_positions': ['午'],
'san_fang_stars': {'center': '命宫',
'must_not_have': ['擎羊', '陀罗', '火星', '铃星', '地空', '地劫'],
'no_huaji_in_san_fang': True,
'description': '三合逢煞忌为破格'},
'description': '太阳在午宫守命,三方四正无煞忌',
'brightness': {'太阳': ['庙', '旺']}},
"effects": {
"positive": ["光明磊落", "贵人多助", "白天生人更佳", "官运亨通"],
"negative": ["三合逢煞忌则破格"]
},
"suitable_careers": ["政界", "管理", "公关"],
"fortune_timing": "早年即显"
},
"日月夹命格": {
"type": PatternType.AUSPICIOUS,
"level": PatternLevel.UPPER,
"score_range": (80, 92),
"description": "日月夹命格,太阳太阴在命宫前后宫夹,得日月庇佑",
"conditions": {'palace_positions': ['丑', '未'],
'flanking_stars': ['太阳', '太阴'],
'auspicious_stars': ['左辅', '右弼', '文昌', '文曲', '天魁', '天钺']},
"effects": {
"positive": ["日月庇佑", "贵人极多", "一生受人爱戴"],
"negative": ["无空亡方成格", "需有吉星同度"]
},
"suitable_careers": ["政界", "大企业", "外交"],
"fortune_timing": "一生平顺"
},
"善荫朝纲格": {
"type": PatternType.AUSPICIOUS,
"level": PatternLevel.MEDIUM,
"score_range": (65, 80),
"description": "善荫朝纲格,天机天梁同宫,善于谋划、有荫庇",
"conditions": {
"required_stars": ["天机", "天梁"],
"description": "天机天梁同宫守命"
},
"effects": {
"positive": ["善于谋划", "有长辈荫庇", "适合幕僚"],
"negative": ["酉宫机梁不佳", "过于保守"]
},
"suitable_careers": ["顾问", "幕僚", "策划", "研究"],
"fortune_timing": "得人提携,中年有成"
},
# --- 杀破狼系列 ---
"杀破狼格": {
"type": PatternType.SPECIAL,
"level": PatternLevel.MEDIUM,
"score_range": (60, 80),
"description": "杀破狼格,七杀破军贪狼三方会照,开创变革之命",
"conditions": {'any_stars': ['七杀', '破军', '贪狼'],
'san_fang_stars': {'center': '命宫', 'must_have_all': ['七杀', '破军', '贪狼']}},
"effects": {
"positive": ["开创力强", "变革先锋", "不安于现状", "适合外出发展"],
"negative": ["一生多变动", "宜出外不宜守家", "波折较多"]
},
"suitable_careers": ["创业", "军警", "探险", "改革先锋"],
"fortune_timing": "大起大落,中年后稳定"
},
"七杀朝斗格": {
"type": PatternType.CAREER,
"level": PatternLevel.UPPER,
"score_range": (82, 95),
"description": "七杀朝斗格,七杀在子午寅申守命,威镇边疆",
"conditions": {
"required_stars": ["七杀"],
"palace_positions": ["子", "午", "寅", "申"],
"description": "七杀在子午寅申守命,子午为仰斗朝斗,寅申有紫府来朝"
},
"effects": {
"positive": ["威镇一方", "将军之命", "白手兴家", "中年后大发"],
"negative": ["早年历尽艰辛", "有煞则偏武"]
},
"suitable_careers": ["军警", "企业家", "竞争性行业"],
"fortune_timing": "早年辛苦,30后发达"
},
"英星入庙格": {
"type": PatternType.CAREER,
"level": PatternLevel.UPPER,
"score_range": (80, 92),
"description": "英星入庙格,破军在子午守命入庙,开创有成",
"conditions": {'required_stars': ['破军'],
'palace_positions': ['子', '午'],
'avoid_stars': ['擎羊', '陀罗', '火星', '铃星'],
'description': '破军在子宫或午宫守命入庙,无煞星',
'brightness': {'破军': ['庙']}},
"effects": {
"positive": ["开创有成", "先破后立", "英雄本色", "加吉主大贵"],
"negative": ["有煞则破格", "早年多波折"]
},
"suitable_careers": ["军警", "开创事业", "改革"],
"fortune_timing": "先难后易"
},
"众水朝东格": {
"type": PatternType.CAREER,
"level": PatternLevel.MEDIUM,
"score_range": (70, 85),
"description": "众水朝东格,破军文曲在寅卯,文武双全",
"conditions": {
"required_stars": ["破军"],
"palace_positions": ["寅", "卯"],
"auspicious_stars": ["文曲", "文昌"],
"description": "破军在寅或卯,加文曲或文昌"
},
"effects": {
"positive": ["文武双全", "有开创才华"],
"negative": ["需有文星方成格"]
},
"suitable_careers": ["军事文职", "策划", "创意"],
"fortune_timing": "中年有成"
},
# --- 禄马系列 ---
"三奇加会格": {
"type": PatternType.AUSPICIOUS,
"level": PatternLevel.UPPER,
"score_range": (82, 95),
"description": "三奇加会格,化禄化权化科三方四正集齐,三化同辉",
"conditions": {
"san_fang_stars": {
"center": "命宫",
"must_have_mutagens": ["化禄", "化权", "化科"],
"description": "化禄化权化科在命宫三方四正集齐"
},
"description": "三化(禄权科)汇聚三方四正"
},
"effects": {
"positive": ["名利双收", "一生有贵人", "事业顺遂", "才华受认可"],
"negative": ["后人所创,非古书格局"]
},
"suitable_careers": ["管理", "学术", "政界"],
"fortune_timing": "一生机遇多"
},
"禄马交驰格": {
"type": PatternType.WEALTH,
"level": PatternLevel.UPPER,
"score_range": (78, 90),
"description": "禄马交驰格,禄存天马同宫,财来自远方",
"conditions": {
"required_stars": ["禄存", "天马"],
"description": "禄存天马同宫,主财运极佳"
},
"effects": {
"positive": ["财运极佳", "财来自远方", "动中得财", "经商大利"],
"negative": ["遇煞羊火截路空亡主劳苦"]
},
"suitable_careers": ["贸易", "物流", "海外生意"],
"fortune_timing": "动中得财"
},
"禄合鸳鸯格": {
"type": PatternType.WEALTH,
"level": PatternLevel.UPPER,
"score_range": (78, 88),
"description": '禄存在命宫,且命宫同时见生年化禄,构成双禄同宫的资源组合。',
"conditions": {'required_stars': ['禄存'], 'required_mutagens': ['禄']},
"effects": {
"positive": ["双禄交辉", "一生荣华", "财官双美"],
"negative": ["需注意化忌冲破"]
},
"suitable_careers": ["金融", "企业", "管理"],
"fortune_timing": "一生富贵"
},
# --- 其他经典格局 ---
"石中隐玉格": {
"type": PatternType.SPECIAL,
"level": PatternLevel.MEDIUM,
"score_range": (65, 82),
"description": "石中隐玉格,巨门在子午守命,外粗内秀",
"conditions": {
"required_stars": ["巨门"],
"palace_positions": ["子", "午"],
"san_fang_stars": {
"center": "命宫",
"must_not_have": ["擎羊", "陀罗", "火星", "铃星", "地空", "地劫"],
"no_huaji_in_san_fang": True,
"description": "加煞忌则破格(古书原文极严厉)"
},
"description": "巨门在子或午守命,三方四正无煞忌"
},
"effects": {
"positive": ["外表平凡内藏才华", "子宫日月并明偏开朗", "越老越有味道"],
"negative": ["午宫日月反背偏消极", "有煞则破格"]
},
"suitable_careers": ["研究", "学术", "深度专业"],
"fortune_timing": "大器晚成"
},
"阳梁昌禄格": {
"type": PatternType.CAREER,
"level": PatternLevel.TOP,
"score_range": (88, 98),
"description": "阳梁昌禄格,太阳天梁文昌禄存三方四正集齐,古代状元格",
"conditions": {
"san_fang_stars": {
"center": "命宫",
"must_have_all": ["太阳", "天梁", "文昌", "禄存"],
"description": "太阳天梁文昌禄存在三方四正集齐"
},
"description": "四星在三方四正会齐"
},
"effects": {
"positive": ["古代状元格", "学业超群", "考试运极佳", "适合公职"],
"negative": ["现代适合学术/公务员"]
},
"suitable_careers": ["学者", "公务员", "法官", "高级顾问"],
"fortune_timing": "学业早成,仕途顺利"
},
"雄宿朝元格": {
"type": PatternType.CAREER,
"level": PatternLevel.UPPER,
"score_range": (78, 90),
"description": "雄宿朝元格,廉贞在寅申守命庙旺,威武雄壮",
"conditions": {
"required_stars": ["廉贞"],
"palace_positions": ["寅", "申"],
"avoid_stars": ["擎羊", "陀罗", "火星", "铃星"],
"description": "廉贞在寅或申守命,无煞星"
},
"effects": {
"positive": ["威武雄壮", "胆识过人", "无煞主富贵"],
"negative": ["有煞则平常"]
},
"suitable_careers": ["军警", "政界", "竞技"],
"fortune_timing": "早年成就"
},
"梁马飘荡格": {
"type": PatternType.SPECIAL,
"level": PatternLevel.MEDIUM,
"score_range": (55, 70),
"description": "梁马飘荡格,天梁天马同宫,一生漂泊不定",
"conditions": {
"required_stars": ["天梁", "天马"],
"description": "天梁天马同宫守命"
},
"effects": {
"positive": ["适合海外发展", "见多识广", "现代社会不算凶"],
"negative": ["古代主漂泊", "难以安定"]
},
"suitable_careers": ["航空", "旅游", "外贸", "自媒体"],
"fortune_timing": "远方有机遇"
},
"铃昌陀武格": {
"type": PatternType.INAUSPICIOUS,
"level": PatternLevel.POOR,
"score_range": (15, 35),
"description": "铃昌陀武格,武曲文昌铃星陀罗同宫或会照,限运逢之不利",
"conditions": {
"san_fang_stars": {
"center": "命宫",
"must_have_all": ["武曲", "文昌", "铃星", "陀罗"],
"description": "武曲文昌铃星陀罗在三方四正会齐"
},
"description": "四星在三方四正会齐"
},
"effects": {
"positive": [],
"negative": ["古书主大凶", "限运逢之不利", "投资损失", "注意安全"]
},
"suitable_careers": [],
"fortune_timing": "流年大限逢之需谨慎"
},
"生不逢时格": {
"type": PatternType.INAUSPICIOUS,
"level": PatternLevel.LOWER,
"score_range": (30, 50),
"description": "生不逢时格,廉贞与空劫同守命宫,怀才不遇",
"conditions": {
"required_stars": ["廉贞"],
"auspicious_stars": ["地空", "地劫"],
"description": "廉贞与地空或地劫同宫守命"
},
"effects": {
"positive": ["内心世界丰富"],
"negative": ["怀才不遇", "志大才疏", "不得时机"]
},
"suitable_careers": ["哲学", "宗教", "艺术"],
"fortune_timing": "一生时运不济"
},
"马头带箭格": {
"type": PatternType.SPECIAL,
"level": PatternLevel.MEDIUM,
"score_range": (60, 78),
"description": "马头带箭格,擎羊在午守命,武将之命",
"conditions": {
"required_stars": ["擎羊"],
"palace_positions": ["午"],
"description": "擎羊在午宫守命"
},
"effects": {
"positive": ["武将之命", "适合军警", "果敢刚毅", "午宫擎羊入庙有力"],
"negative": ["性格暴躁", "易有伤灾"]
},
"suitable_careers": ["军警", "运动员", "外科医生"],
"fortune_timing": "从武吉,从文凶"
},
"羊陀夹命格": {
"type": PatternType.INAUSPICIOUS,
"level": PatternLevel.LOWER,
"score_range": (25, 45),
'description': '命宫见禄存,擎羊与陀罗分居前后两宫,传统上形容资源在手、选择和推进却容易受牵制;这是应对压力的提示,并非全盘成败的结论。',
"conditions": {'required_stars': ['禄存'], 'flanking_stars': ['擎羊', '陀罗']},
'effects': {'positive': ['禄存可作资源基础', '稳步执行有利积累'], 'negative': ['选择时易有拉扯', '推进需留出回旋']},
"suitable_careers": [],
'fortune_timing': '在大限流年触动相关宫位时再看强弱',
},
"魁钺夹命格": {
"type": PatternType.AUSPICIOUS,
"level": PatternLevel.UPPER,
"score_range": (78, 90),
"description": '天魁与天钺分别位于命宫前后两宫,构成夹命;仅在三方会照不算此格。',
"conditions": {'flanking_stars': ['天魁', '天钺']},
"effects": {
"positive": ["一生贵人不断", "逢凶化吉", "遇难呈祥"],
"negative": []
},
"suitable_careers": ["政界", "管理", "任何行业"],
"fortune_timing": "终身有贵人"
},
"文星朝命格": {
"type": PatternType.AUSPICIOUS,
"level": PatternLevel.MEDIUM,
"score_range": (68, 82),
"description": "文星朝命格,文昌文曲在命宫三方四正会照",
"conditions": {
"san_fang_stars": {
"center": "命宫",
"must_have_all": ["文昌", "文曲"],
"description": "文昌文曲在命宫三方四正"
},
"description": "文昌文曲会照命宫"
},
"effects": {
"positive": ["才华横溢", "文采出众", "考试运佳", "适合文职"],
"negative": ["逢煞或化忌则减力"]
},
"suitable_careers": ["文学", "教育", "新闻", "出版"],
"fortune_timing": "学业有成"
},
"左右同宫格": {
"type": PatternType.AUSPICIOUS,
"level": PatternLevel.MEDIUM,
"score_range": (70, 82),
"description": "左右同宫格,左辅右弼同宫守命,助力极强",
"conditions": {
"required_stars": ["左辅", "右弼"],
"description": "左辅右弼同宫守命"
},
"effects": {
"positive": ["贵人助力极强", "得众人拥护", "适合管理"],
"negative": ["需有主星方显"]
},
"suitable_careers": ["管理层", "团队领导"],
"fortune_timing": "一生有助力"
},
# ══════════════════════════════════════════════════════════════
# 以下格局来源:ziwei-doushu 开源项目 patterns.ts(倪海夏体系)
# ══════════════════════════════════════════════════════════════
# ─── 吉格补充 ─────────────────────────────────────────────────
"廉贞天相格": {
"type": PatternType.AUSPICIOUS,
"level": PatternLevel.MEDIUM,
"score_range": (65, 80),
"description": "廉贞天相同宫,印绶格局,主秉公处事、清廉之名,宜任公职、行政管理、法务、企划。怕见擎羊化忌,则反主官非。",
"conditions": {'required_stars': ['廉贞', '天相'], 'avoid_stars': ['擎羊'], 'avoid_star_mutagens': {'廉贞': ['忌']}},
"effects": {
"positive": ["适合公职行政", "清廉之名", "法务企划有成"],
"negative": ["遇擎羊化忌则反主官非缠身"]
},
"suitable_careers": ["公务员", "法务", "行政管理", "企划"],
"fortune_timing": "中年稳步晋升",
"source": "《紫微斗数全书》"
},
"武曲七杀格": {
"type": PatternType.SPECIAL,
"level": PatternLevel.MEDIUM,
"score_range": (55, 78),
"description": "武曲七杀同宫,将星配财星,主果决刚毅、理财能力强,适合金融、军警、创业。但忌见化忌煞星,否则凶险。一生奋斗、积财但操心。",
"conditions": {'required_stars': ['武曲', '七杀'], 'avoid_star_mutagens': {'武曲': ['忌']}},
"effects": {
"positive": ["财务决断力强", "适合金融军警", "创业有魄力"],
"negative": ["武曲化忌财劫", "一生劳碌操心"]
},
"suitable_careers": ["金融", "军警", "创业", "工程"],
"fortune_timing": "中年打拼,晚年见收",
"source": "《紫微斗数全书》"
},
"天同天梁格": {
"type": PatternType.AUSPICIOUS,
"level": PatternLevel.MEDIUM,
"score_range": (60, 75),
"description": "天同天梁同宫,福星与荫星共会,主宽厚和善、乐于助人,宜医疗、教育、宗教、社会公益。但偏温和保守,难成大富大贵之局。",
"conditions": {
"required_stars": ["天同", "天梁"],
"description": "天同天梁同宫",
},
"effects": {
"positive": ["宽厚善良", "贵人缘佳", "适合助人行业"],
"negative": ["偏保守温和", "难成大富大贵"]
},
"suitable_careers": ["医疗", "教育", "宗教", "社工", "公益"],
"fortune_timing": "一生平稳,贵在积累",
"source": "《紫微斗数全书》"
},
"辅弼夹命格": {
"type": PatternType.AUSPICIOUS,
"level": PatternLevel.TOP,
"score_range": (85, 95),
"description": "左辅右弼夹命,一生贵人不断、逢凶化吉。适合走仕途、大企业管理,有贵人提携之命。古书云「左辅右弼,终身福厚」。",
"conditions": {'flanking_stars': ['左辅', '右弼']},
"effects": {
"positive": ["一生贵人不断", "逢凶化吉", "适合仕途管理"],
"negative": ["需有主星配合方为大格"]
},
"suitable_careers": ["仕途", "大企业管理", "政商要职"],
"fortune_timing": "一生有贵人提携",
"source": "《紫微斗数全书·辅弼夹命》"
},
"昌曲夹命格": {
"type": PatternType.AUSPICIOUS,
"level": PatternLevel.TOP,
"score_range": (83, 93),
"description": "文昌文曲夹命宫,主聪明俊秀、文采斐然,宜走文教、学术、艺术、写作。古书云「昌曲夹命主科甲」,最利考运。",
"conditions": {'flanking_stars': ['文昌', '文曲']},
"effects": {
"positive": ["聪明俊秀", "文采出众", "考运极佳", "科甲有望"],
"negative": ["重文轻武,不宜粗重体力工作"]
},
"suitable_careers": ["文教", "学术", "艺术", "写作", "传媒"],
"fortune_timing": "学业考试节节高升",
"source": "《紫微斗数全书》"
},
"双禄朝垣格": {
"type": PatternType.WEALTH,
"level": PatternLevel.TOP,
"score_range": (88, 98),
'description': '生年化禄与禄存同会命宫三方四正,传统上视为资源与财务机会较易汇聚的组合;能否留住成果,仍要结合其他星曜与实际经营。',
"conditions": {'san_fang_stars': {'center': '命宫', 'must_have_all': ['禄存'], 'must_have_mutagens': ['化禄']},
'avoid_stars': ['地空', '地劫']},
'effects': {'positive': ['资源与收入机会较易汇聚', '适合经营既有资源', '可留意正财及合作收益'], 'negative': ['机会不等于稳定收入', '遇空劫或化忌仍需控制损耗']},
"suitable_careers": ["实业", "金融", "投资", "商业"],
'fortune_timing': '以大限流年验证机会能否落实',
"source": "《紫微斗数全书·双禄朝垣》"
},
"机月同梁三星会格": {
"type": PatternType.SPECIAL,
"level": PatternLevel.MEDIUM,
"score_range": (58, 72),
"description": "机月同梁四星中有三星会照三方,不全格。文质带谋,但稳定度不如四星齐。仍宜公职、教研、医疗、服务等需要积累与稳定的行业。",
"conditions": {'san_fang_stars': {'center': '命宫',
'star_count': {'stars': ['天机', '太阴', '天同', '天梁'], 'exactly': 3}}},
"effects": {
"positive": ["文质彬彬", "稳重踏实", "服务业有成"],
"negative": ["格局不全,能量减弱"]
},
"suitable_careers": ["公职", "教研", "医疗", "服务业"],
"fortune_timing": "稳步发展",
"source": "《紫微斗数全书·机月同梁格》(不全版)"
},
# ─── 凶格补充 ─────────────────────────────────────────────────
"羊陀夹忌格": {
"type": PatternType.INAUSPICIOUS,
"level": PatternLevel.POOR,
"score_range": (10, 30),
"description": "化忌坐命,左右擎羊陀罗夹命,古书云「羊陀夹忌为败局」,主一生劳碌奔波、坎坷不顺、身心俱疲。需以德行修养与积极做事化解,凡事谨慎为上。",
"conditions": {'required_mutagens': ['忌'], 'flanking_stars': ['擎羊', '陀罗']},
"effects": {
"positive": ["逆境历练心性", "中晚年可改善"],
"negative": ["劳碌奔波", "坎坷不顺", "身心俱疲", "诸事阻碍"]
},
"suitable_careers": ["技术类", "专业自雇"],
"fortune_timing": "中晚年方有转机",
"source": "《紫微斗数骨髓赋·羊陀夹忌》"
},
"火铃夹命格": {
"type": PatternType.INAUSPICIOUS,
"level": PatternLevel.LOWER,
"score_range": (25, 45),
"description": "火星铃星分居命宫前后两宫夹命,主性急、易冲动、突发意外或纠纷。需培养耐性、避免冲动决策。",
"conditions": {'flanking_stars': ['火星', '铃星']},
"effects": {
"positive": ["行动力强", "执行力佳"],
"negative": ["性急冲动", "易招意外", "突发纠纷"]
},
"suitable_careers": ["需配合其他星曜判断"],
"fortune_timing": "需修身养性方可化解",
"source": "《紫微斗数全书》"
},
"空劫夹命格": {
"type": PatternType.INAUSPICIOUS,
"level": PatternLevel.LOWER,
"score_range": (25, 45),
"description": "地空地劫夹命,主财来财去、思想脱俗、易遁入宗教哲学。古书云「空劫夹命,财不聚」。宜技艺、宗教、研究等不重物质之业。",
"conditions": {'flanking_stars': ['地空', '地劫']},
"effects": {
"positive": ["思想超脱", "宗教哲学有悟", "技艺出众"],
"negative": ["财不聚", "财来财去", "物质匮乏感"]
},
"suitable_careers": ["宗教", "哲学", "艺术", "技艺", "研究"],
"fortune_timing": "须放下物质执着方得心安",
"source": "《紫微斗数全书》"
},
"廉杀羊格": {
"type": PatternType.INAUSPICIOUS,
"level": PatternLevel.POOR,
"score_range": (5, 25),
"description": "廉贞、七杀、擎羊三星会照命宫三方,古书警示之凶格。主血光、官非、意外。本命有此格不必惊慌,但流年大限再触发时需特别谨慎驾驶、避免冲突、注意手术风险。",
"conditions": {'san_fang_stars': {'center': '命宫', 'must_have_all': ['廉贞', '七杀', '擎羊']}},
"effects": {
"positive": ["极端逆境中可磨砺坚韧心性"],
"negative": ["血光之灾", "官非缠身", "意外风险", "流年触发尤凶"]
},
"suitable_careers": ["军警(反而可化解)", "外科医生"],
"fortune_timing": "流年大限触发时最需谨慎",
"source": "《紫微斗数全书·廉杀羊》"
},
"巨火羊格": {
"type": PatternType.INAUSPICIOUS,
"level": PatternLevel.POOR,
"score_range": (5, 25),
"description": "巨门、火星、擎羊三星会照,古书云「巨火羊,终身缢死」——古时凶格。现代理解为:易因口舌、激烈冲突而招大祸。需修身养性、慎言慎行,避免极端情绪。",
"conditions": {'san_fang_stars': {'center': '命宫', 'must_have_all': ['巨门', '火星', '擎羊']}},
"effects": {
"positive": ["慎言修行可化"],
"negative": ["口舌招祸", "激烈冲突", "情绪极端", "古凶格"]
},
"suitable_careers": ["需谨慎口舌之业"],
"fortune_timing": "须慎言慎行方可化解",
"source": "《紫微斗数骨髓赋·巨火羊》"
},
}
# ============================================================================
# 辅助函数
# ============================================================================
def get_pattern_by_name(pattern_name: str) -> Optional[Dict[str, Any]]:
"""
根据格局名称获取格局详情
Args:
pattern_name: 格局名称(如:府相朝垣格)
Returns:
dict: 格局详情,如果不存在返回None
"""
return GEJU_PATTERNS.get(pattern_name)
def get_patterns_by_type(pattern_type: PatternType) -> List[Dict[str, Any]]:
"""
根据格局类型获取格局列表
Args:
pattern_type: 格局类型(如:PatternType.AUSPICIOUS)
Returns:
list: 符合类型的格局列表
"""
return [
{**pattern, 'name': name}
for name, pattern in GEJU_PATTERNS.items()
if pattern['type'] == pattern_type
]
def get_auspicious_patterns() -> List[Dict[str, Any]]:
"""获取所有吉格"""
return get_patterns_by_type(PatternType.AUSPICIOUS)
def get_inauspicious_patterns() -> List[Dict[str, Any]]:
"""获取所有凶格"""
return get_patterns_by_type(PatternType.INAUSPICIOUS)
def get_all_pattern_names() -> List[str]:
"""获取所有格局名称列表"""
return list(GEJU_PATTERNS.keys())
def search_patterns_by_stars(stars: List[str]) -> List[str]:
"""
根据星曜组合搜索可能的格局
Args:
stars: 星曜列表(如:['紫微', '天府'])
Returns:
list: 可能匹配的格局名称列表
"""
matching_patterns = []
for pattern_name, pattern_data in GEJU_PATTERNS.items():
conditions = pattern_data.get('conditions', {})
required_stars = conditions.get('required_stars', [])
# 简单匹配:检查是否包含所需星曜
if all(star in stars for star in required_stars):
matching_patterns.append(pattern_name)
return matching_patterns
# ============================================================================
# 示例用法
# ============================================================================
if __name__ == '__main__':
print("=" * 70)
print("紫微斗数格局识别规则库 v1.0")
print("=" * 70)
# 1. 查询单个格局
print("\n【示例1】查询'府相朝垣格':")
pattern = get_pattern_by_name("府相朝垣格")
if pattern:
print(f" 类型: {pattern['type'].value}")
print(f" 等级: {pattern['level'].value}")
print(f" 描述: {pattern['description']}")
print(f" 吉利影响: {', '.join(pattern['effects']['positive'])}")
# 2. 获取所有吉格
print("\n【示例2】所有吉格列表:")
auspicious = get_auspicious_patterns()
for i, p in enumerate(auspicious, 1):
print(f" {i}. {p['name']} - {p['description'][:30]}...")
# 3. 搜索星曜组合
print("\n【示例3】搜索包含'武曲'+'贪狼'的格局:")
matches = search_patterns_by_stars(['武曲', '贪狼'])
for pattern_name in matches:
print(f" - {pattern_name}")
# 4. 统计信息
print("\n【统计信息】:")
print(f" 总格局数: {len(GEJU_PATTERNS)}")
print(f" 吉格数: {len(get_auspicious_patterns())}")
print(f" 凶格数: {len(get_inauspicious_patterns())}")
print("\n格局库初始化完成!🔮✨")
"""
格局识别规则库 - Pattern Recognition Rules Database
紫微斗数格局(吉格、凶格、特殊格局)
格局是紫微斗数分析的核心,由特定星曜组合在特定宫位形成。
格局优先级:格局 > 单星 > 宫位
数据来源:
- /Volumes/sparksverse/agent-knowledge/mingli-knowledge/eastern/ziwei/interpretations/01-practical-divination.md
- 南北派断诀(朱云山)138页实战经验
Created: 2025-12-12
Author: Sisi 🦊
Version: 1.0 - 初版(30+核心格局)
"""
from typing import Dict, List, Any, Optional
from enum import Enum
class PatternType(Enum):
"""格局类型"""
AUSPICIOUS = "吉格" # 吉格
INAUSPICIOUS = "凶格" # 凶格
SPECIAL = "特殊格" # 特殊格(半吉半凶)
CAREER = "事业格" # 事业成就格
WEALTH = "财富格" # 财富格
PEACH_BLOSSOM = "桃花格" # 桃花感情格
POWER = "权贵格" # 权力地位格
class PatternLevel(Enum):
"""格局等级"""
TOP = "上上格" # 极品格局(90-100分)
UPPER = "上格" # 优良格局(80-89分)
MEDIUM = "中格" # 中等格局(60-79分)
LOWER = "下格" # 较差格局(40-59分)
POOR = "破格" # 破格(0-39分)
# ============================================================================
# 核心格局数据库(30+经典格局)
# ============================================================================
GEJU_PATTERNS = {
# ========== 吉格(高贵格局)==========
"府相朝垣格": {
"type": PatternType.AUSPICIOUS,
"level": PatternLevel.UPPER,
"score_range": (80, 95),
"description": "府相朝垣格,一生衣食无缺,六亲好,有口福,东作西成",
"conditions": {'any_conditions': [{'palace_requirements': [{'palace': '财帛', 'required_stars': ['天府']},
{'palace': '官禄', 'required_stars': ['天相']}]},
{'palace_requirements': [{'palace': '财帛', 'required_stars': ['天相']},
{'palace': '官禄', 'required_stars': ['天府']}]}]},
"effects": {
"positive": [
"一生衣食无缺",
"六亲关系和睦",
"有口福,常得人请客",
"东作西成,付出有回报",
"不怕火鈴,遇之不能衝破"
],
"negative": [
"甚忌擎羊,会破格"
]
},
"suitable_careers": ["公职人员", "管理层", "服务业", "餐饮业"],
"fortune_timing": "稳步上升,中年后更佳",
"notes": "流年行抵府相朝垣,会有合作、合夥事发生"
},
"紫府夹命格": {
"type": PatternType.POWER,
"level": PatternLevel.UPPER,
"score_range": (85, 98),
"description": '命宫在寅或申,天机太阴同坐,紫微与天府分居前后两宫相夹。',
"conditions": {'required_stars': ['天机', '太阴'], 'palace_positions': ['寅', '申'], 'flanking_stars': ['紫微', '天府']},
"effects": {
"positive": [
"权贵之命,地位崇高",
"统御才能,一呼百诺",
"会吉星主大富大贵",
"领导能力强,部属众多"
],
"negative": [
"无吉星会合,仅为常人"
]
},
"suitable_careers": ["政治家", "企业高管", "军官", "董事长"],
"fortune_timing": "早年显贵,终身享福",
"birth_year_preferences": ["甲", "丙", "戊"]
},
"机月同梁格": {
"type": PatternType.AUSPICIOUS,
"level": PatternLevel.MEDIUM,
"score_range": (70, 85),
"description": "机月同梁格,平稳发展,安于现实,宜研究工作",