-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodality_classifier.py
More file actions
112 lines (96 loc) · 5.51 KB
/
Copy pathmodality_classifier.py
File metadata and controls
112 lines (96 loc) · 5.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# =============================================================
# MYTHOS-SYNC FRAMEWORK — MODULE 1: MODALITY CLASSIFIER
# Tags every character with their operational "mode" so the
# engine knows what rules apply to them.
# =============================================================
from console import use_utf8_output
# The Master Registry — defines every known character's modality
CHARACTER_REGISTRY = {
# --- LEGACY: Real historical/cultural figures (human limits only) ---
"Yasuke": {"modality": "LEGACY", "tags": ["warrior", "historical", "resilience"], "trait": "Honorary Samurai", "element": "Steel"},
"Bruce Lee": {"modality": "LEGACY", "tags": ["martial_arts", "philosophy", "kinetic"], "trait": "Fluid Philosopher", "element": "Water"},
"Nikola Tesla": {"modality": "LEGACY", "tags": ["inventor", "electromagnetic", "visionary"], "trait": "Mad Scientist", "element": "Lightning"},
"Malcolm X": {"modality": "LEGACY", "tags": ["rhetoric", "strategy", "legacy"], "trait": "Revolutionary Firebrand", "element": "Fire"},
"Tookie Williams": {"modality": "LEGACY", "tags": ["street_legend", "redemption", "influence"], "trait": "Redeemed Architect", "element": "Earth"},
"Bumpy Johnson": {"modality": "LEGACY", "tags": ["street_legend", "tactical", "underworld", "strategy"], "trait": "Harlem Underworld Strategist", "element": "Shadow"},
# --- GROUNDED: Cinematic/fictional but physically realistic ---
"James Bond": {"modality": "GROUNDED", "tags": ["espionage", "tactical", "resourceful"], "trait": "Suave Operative", "element": "Shadow"},
"Kino": {"modality": "GROUNDED", "tags": ["traveler", "observer", "survivalist"], "trait": "Nomadic Witness", "element": "Wind"},
# --- HIGH_CONCEPT: Physics-bending, supernatural powers ---
"The Medicine Seller": {"modality": "HIGH_CONCEPT", "tags": ["spiritual", "cursed", "ancient"], "trait": "Exorcist Merchant", "element": "Void"},
"Re-l Mayer": {"modality": "HIGH_CONCEPT", "tags": ["cyberpunk", "investigator", "android_adjacent"], "trait": "Synthetic Sleuth", "element": "Code"},
"Vash": {"modality": "HIGH_CONCEPT", "tags": ["pacifist", "gunslinger", "angelic_power"], "trait": "Humanoid Typhoon", "element": "Light"},
"Maka": {"modality": "HIGH_CONCEPT", "tags": ["soul_resonance", "meister", "anti_demon"], "trait": "Grigori Meister", "element": "Soul"},
}
def classify(character_name: str) -> dict:
profile = CHARACTER_REGISTRY.get(character_name)
if profile:
return {"name": character_name, **profile}
else:
# Ruling 001 §4: resolve-then-proceed, never silently default. No
# normalization resolver exists in this codebase yet, so an
# unrecognized character is CAUTIONARY — pending, not GROUNDED.
print(f" [CLASSIFIER] ⚠️ '{character_name}' not in registry. CAUTIONARY — normalization required, no fusion output generated.")
return {
"name": character_name,
"state": "CAUTIONARY",
"modality": None,
"tags": ["unknown"],
"trait": "Unknown Entity",
"element": "Neutral"
}
def classify_fusion(alpha_name: str, beta_name: str, dominance: int = 50) -> dict:
"""
Classifies a FUSION of two characters.
dominance = 0–100, where 100 means Alpha fully dominates.
Returns a blended modality profile.
Per Ruling 001 §4, if either input is CAUTIONARY (unresolved), no
modality can be honestly computed — the fusion carries CAUTIONARY
forward rather than fabricating a modality or raising on the lookup.
"""
alpha = classify(alpha_name)
beta = classify(beta_name)
if alpha.get("state") == "CAUTIONARY" or beta.get("state") == "CAUTIONARY":
return {
"fusion_name": f"{alpha_name} x {beta_name}",
"state": "CAUTIONARY",
"modality": None,
"dominant": None,
"tags": [],
}
# Modality priority ranking (higher = more "powerful" classification)
rank = {"LEGACY": 1, "GROUNDED": 2, "HIGH_CONCEPT": 3}
alpha_rank = rank[alpha["modality"]]
beta_rank = rank[beta["modality"]]
# The dominant character's modality wins IF dominance > 70
if dominance >= 70:
final_modality = alpha["modality"]
dominant_label = f"{alpha_name} (dominant)"
elif dominance <= 30:
final_modality = beta["modality"]
dominant_label = f"{beta_name} (dominant)"
else:
# Balanced blend — take the HIGHER modality rank
if alpha_rank >= beta_rank:
final_modality = alpha["modality"]
else:
final_modality = beta["modality"]
dominant_label = "balanced blend"
blended_tags = list(set(alpha["tags"] + beta["tags"]))
return {
"fusion_name": f"{alpha_name} x {beta_name}",
"modality": final_modality,
"dominant": dominant_label,
"tags": blended_tags,
}
# --- Quick test when run directly ---
if __name__ == "__main__":
use_utf8_output()
print("\n🔬 CLASSIFIER TEST\n" + "─" * 40)
print(classify("Bruce Lee"))
print(classify("Vash"))
print(classify("Unknown Hero"))
print("\n🔬 FUSION TEST (dominance=80 → Alpha wins)\n" + "─" * 40)
print(classify_fusion("Malcolm X", "Vash", dominance=80))
print("\n🔬 FUSION TEST (dominance=50 → balanced)\n" + "─" * 40)
print(classify_fusion("Bruce Lee", "Maka", dominance=50))