diff --git a/demo_semantic_naming.py b/demo_semantic_naming.py index e87c88b..013e296 100644 --- a/demo_semantic_naming.py +++ b/demo_semantic_naming.py @@ -4,7 +4,10 @@ Shows practical application of the validated mixing formula """ -from harmonizer.divine_invitation_engine_V2 import DivineInvitationSemanticEngine, Coordinates +from harmonizer.divine_invitation_engine_V2 import ( + DivineInvitationSemanticEngine, + Coordinates, +) from harmonizer.semantic_naming import SemanticNamingEngine @@ -31,12 +34,16 @@ def demo_1_detect_and_suggest(): print(f"\nIntent (function name): {intent_result.coordinates}") print(f"Execution (body): {execution_result.coordinates}") - distance = engine.get_distance(intent_result.coordinates, execution_result.coordinates) + distance = engine.get_distance( + intent_result.coordinates, execution_result.coordinates + ) print(f"Disharmony distance: {distance:.3f} āš ļø HIGH!") # Suggest better names based on actual execution print("\nāœ… SUGGESTED FIXES based on execution semantics:") - suggestions = namer.suggest_names(execution_result.coordinates, context="user", top_n=5) + suggestions = namer.suggest_names( + execution_result.coordinates, context="user", top_n=5 + ) for name, score in suggestions: print(f" • {name:25s} (match: {score:.1%})") @@ -68,7 +75,8 @@ def demo_2_generate_from_intent(): # Show what the function should do print("\nšŸ“‹ Generated function skeleton:") - print(f""" + print( + f""" def {suggestions[0][0]}(user_input): ''' {namer.explain_coordinates(result.coordinates)} @@ -87,7 +95,8 @@ def {suggestions[0][0]}(user_input): ) return ValidationResult(valid=True) -""") +""" + ) def demo_3_refactoring_suggestion(): @@ -101,7 +110,8 @@ def demo_3_refactoring_suggestion(): # Analyze a multi-purpose function print("\nāš ļø PROBLEMATIC CODE (does too much):") - print(""" + print( + """ def process_user(user_data): # Validation (Justice) if not user_data.is_valid: @@ -118,15 +128,16 @@ def process_user(user_data): # Analytics (Wisdom) log_user_metrics(user_data) -""") +""" + ) # Analyze each operation operations = { - 'validation': 'validate user data', - 'transformation': 'transform data', - 'storage': 'save database', - 'notification': 'send email', - 'analytics': 'log metrics' + "validation": "validate user data", + "transformation": "transform data", + "storage": "save database", + "notification": "send email", + "analytics": "log metrics", } print("\nšŸ” SEMANTIC ANALYSIS OF OPERATIONS:") @@ -143,9 +154,9 @@ def process_user(user_data): # Group by semantic similarity groups = { - 'validation': ['validation'], - 'processing': ['transformation', 'storage'], - 'notification': ['notification', 'analytics'] + "validation": ["validation"], + "processing": ["transformation", "storage"], + "notification": ["notification", "analytics"], } for group_name, ops in groups.items(): @@ -155,11 +166,11 @@ def process_user(user_data): love=sum(coords_map[op].love for op in ops) / len(ops), justice=sum(coords_map[op].justice for op in ops) / len(ops), power=sum(coords_map[op].power for op in ops) / len(ops), - wisdom=sum(coords_map[op].wisdom for op in ops) / len(ops) + wisdom=sum(coords_map[op].wisdom for op in ops) / len(ops), ) suggestions = namer.suggest_names(group_coords, context="user", top_n=3) - print(f" Suggested names:") + print(" Suggested names:") for name, score in suggestions: print(f" • {name} (match: {score:.1%})") @@ -205,7 +216,9 @@ def demo_4_code_review(): # Suggest better name suggestions = namer.suggest_names(actual.coordinates, top_n=1) if suggestions: - print(f" šŸ’” Suggest: {suggestions[0][0]} (match: {suggestions[0][1]:.1%})") + print( + f" šŸ’” Suggest: {suggestions[0][0]} (match: {suggestions[0][1]:.1%})" + ) print() diff --git a/harmonizer/semantic_naming.py b/harmonizer/semantic_naming.py index 576f174..b721835 100644 --- a/harmonizer/semantic_naming.py +++ b/harmonizer/semantic_naming.py @@ -18,265 +18,275 @@ def __init__(self): # Vocabulary of action verbs mapped to LJWP coordinates self.action_verbs = { # LOVE-dominant verbs (connection, care) - 'care_for': (0.9, 0.05, 0.05, 0.0), - 'support': (0.8, 0.1, 0.1, 0.0), - 'help': (0.8, 0.1, 0.1, 0.0), - 'nurture': (0.85, 0.1, 0.05, 0.0), - 'connect': (0.7, 0.2, 0.1, 0.0), - 'communicate': (0.7, 0.2, 0.05, 0.05), - 'share': (0.75, 0.15, 0.05, 0.05), - 'greet': (0.85, 0.05, 0.05, 0.05), - 'welcome': (0.8, 0.1, 0.05, 0.05), - 'notify': (0.6, 0.1, 0.2, 0.1), - 'inform': (0.65, 0.1, 0.15, 0.1), - 'collaborate': (0.7, 0.15, 0.1, 0.05), - 'synchronize': (0.5, 0.2, 0.2, 0.1), - 'merge': (0.4, 0.2, 0.3, 0.1), - + "care_for": (0.9, 0.05, 0.05, 0.0), + "support": (0.8, 0.1, 0.1, 0.0), + "help": (0.8, 0.1, 0.1, 0.0), + "nurture": (0.85, 0.1, 0.05, 0.0), + "connect": (0.7, 0.2, 0.1, 0.0), + "communicate": (0.7, 0.2, 0.05, 0.05), + "share": (0.75, 0.15, 0.05, 0.05), + "greet": (0.85, 0.05, 0.05, 0.05), + "welcome": (0.8, 0.1, 0.05, 0.05), + "notify": (0.6, 0.1, 0.2, 0.1), + "inform": (0.65, 0.1, 0.15, 0.1), + "collaborate": (0.7, 0.15, 0.1, 0.05), + "synchronize": (0.5, 0.2, 0.2, 0.1), + "merge": (0.4, 0.2, 0.3, 0.1), # JUSTICE-dominant verbs (validation, checking) - 'validate': (0.1, 0.8, 0.1, 0.0), - 'verify': (0.05, 0.75, 0.1, 0.1), - 'check': (0.05, 0.7, 0.15, 0.1), - 'enforce': (0.05, 0.7, 0.2, 0.05), - 'ensure': (0.1, 0.7, 0.15, 0.05), - 'audit': (0.05, 0.75, 0.05, 0.15), - 'inspect': (0.05, 0.65, 0.1, 0.2), - 'filter': (0.05, 0.7, 0.15, 0.1), - 'authorize': (0.05, 0.75, 0.15, 0.05), - 'authenticate': (0.05, 0.75, 0.15, 0.05), - 'certify': (0.05, 0.8, 0.1, 0.05), - 'confirm': (0.1, 0.75, 0.1, 0.05), - 'approve': (0.15, 0.7, 0.1, 0.05), - 'reject': (0.05, 0.75, 0.15, 0.05), - 'restrict': (0.05, 0.75, 0.15, 0.05), - 'allow': (0.15, 0.7, 0.1, 0.05), - 'deny': (0.05, 0.75, 0.15, 0.05), - 'compare': (0.05, 0.6, 0.1, 0.25), - 'match': (0.1, 0.65, 0.1, 0.15), - + "validate": (0.1, 0.8, 0.1, 0.0), + "verify": (0.05, 0.75, 0.1, 0.1), + "check": (0.05, 0.7, 0.15, 0.1), + "enforce": (0.05, 0.7, 0.2, 0.05), + "ensure": (0.1, 0.7, 0.15, 0.05), + "audit": (0.05, 0.75, 0.05, 0.15), + "inspect": (0.05, 0.65, 0.1, 0.2), + "filter": (0.05, 0.7, 0.15, 0.1), + "authorize": (0.05, 0.75, 0.15, 0.05), + "authenticate": (0.05, 0.75, 0.15, 0.05), + "certify": (0.05, 0.8, 0.1, 0.05), + "confirm": (0.1, 0.75, 0.1, 0.05), + "approve": (0.15, 0.7, 0.1, 0.05), + "reject": (0.05, 0.75, 0.15, 0.05), + "restrict": (0.05, 0.75, 0.15, 0.05), + "allow": (0.15, 0.7, 0.1, 0.05), + "deny": (0.05, 0.75, 0.15, 0.05), + "compare": (0.05, 0.6, 0.1, 0.25), + "match": (0.1, 0.65, 0.1, 0.15), # POWER-dominant verbs (action, transformation) - 'create': (0.05, 0.1, 0.8, 0.05), - 'build': (0.05, 0.1, 0.8, 0.05), - 'generate': (0.05, 0.1, 0.75, 0.1), - 'transform': (0.05, 0.1, 0.75, 0.1), - 'process': (0.05, 0.15, 0.7, 0.1), - 'execute': (0.05, 0.1, 0.8, 0.05), - 'perform': (0.05, 0.1, 0.75, 0.1), - 'modify': (0.05, 0.15, 0.7, 0.1), - 'update': (0.05, 0.15, 0.7, 0.1), - 'delete': (0.05, 0.15, 0.75, 0.05), - 'remove': (0.05, 0.15, 0.75, 0.05), - 'save': (0.05, 0.2, 0.65, 0.1), - 'store': (0.05, 0.2, 0.65, 0.1), - 'send': (0.15, 0.1, 0.65, 0.1), - 'insert': (0.05, 0.15, 0.75, 0.05), - 'append': (0.05, 0.15, 0.75, 0.05), - 'prepend': (0.05, 0.15, 0.75, 0.05), - 'replace': (0.05, 0.15, 0.75, 0.05), - 'overwrite': (0.05, 0.1, 0.8, 0.05), - 'clear': (0.05, 0.1, 0.8, 0.05), - 'reset': (0.05, 0.15, 0.75, 0.05), - 'initialize': (0.05, 0.15, 0.75, 0.05), - 'setup': (0.05, 0.15, 0.75, 0.05), - 'configure': (0.05, 0.2, 0.7, 0.05), - 'install': (0.05, 0.15, 0.75, 0.05), - 'uninstall': (0.05, 0.15, 0.75, 0.05), - 'deploy': (0.05, 0.2, 0.7, 0.05), - 'publish': (0.1, 0.15, 0.7, 0.05), - 'upload': (0.05, 0.1, 0.8, 0.05), - 'download': (0.05, 0.1, 0.8, 0.05), - 'import': (0.05, 0.1, 0.8, 0.05), - 'export': (0.05, 0.1, 0.8, 0.05), - 'render': (0.05, 0.1, 0.75, 0.1), - 'format': (0.05, 0.2, 0.7, 0.05), - 'sanitize': (0.05, 0.25, 0.65, 0.05), - 'normalize': (0.05, 0.25, 0.6, 0.1), - 'convert': (0.05, 0.15, 0.75, 0.05), - 'migrate': (0.05, 0.15, 0.75, 0.05), - 'sync': (0.1, 0.2, 0.65, 0.05), - 'refresh': (0.05, 0.1, 0.8, 0.05), - 'reload': (0.05, 0.1, 0.8, 0.05), - 'restart': (0.05, 0.1, 0.8, 0.05), - 'start': (0.05, 0.1, 0.8, 0.05), - 'stop': (0.05, 0.1, 0.8, 0.05), - 'pause': (0.05, 0.1, 0.8, 0.05), - 'resume': (0.05, 0.1, 0.8, 0.05), - 'cancel': (0.05, 0.15, 0.75, 0.05), - 'abort': (0.05, 0.15, 0.75, 0.05), - 'commit': (0.05, 0.2, 0.7, 0.05), - 'rollback': (0.05, 0.2, 0.7, 0.05), - 'backup': (0.05, 0.2, 0.7, 0.05), - 'restore': (0.05, 0.2, 0.7, 0.05), - 'archive': (0.05, 0.2, 0.7, 0.05), - 'compress': (0.05, 0.1, 0.8, 0.05), - 'decompress': (0.05, 0.1, 0.8, 0.05), - 'encrypt': (0.05, 0.2, 0.7, 0.05), - 'decrypt': (0.05, 0.2, 0.7, 0.05), - 'encode': (0.05, 0.15, 0.75, 0.05), - 'decode': (0.05, 0.15, 0.75, 0.05), - 'serialize': (0.05, 0.15, 0.75, 0.05), - 'deserialize': (0.05, 0.15, 0.75, 0.05), - 'parse': (0.05, 0.15, 0.6, 0.2), - 'compile': (0.05, 0.15, 0.7, 0.1), - 'optimize': (0.05, 0.2, 0.65, 0.1), - + "create": (0.05, 0.1, 0.8, 0.05), + "build": (0.05, 0.1, 0.8, 0.05), + "generate": (0.05, 0.1, 0.75, 0.1), + "transform": (0.05, 0.1, 0.75, 0.1), + "process": (0.05, 0.15, 0.7, 0.1), + "execute": (0.05, 0.1, 0.8, 0.05), + "perform": (0.05, 0.1, 0.75, 0.1), + "modify": (0.05, 0.15, 0.7, 0.1), + "update": (0.05, 0.15, 0.7, 0.1), + "delete": (0.05, 0.15, 0.75, 0.05), + "remove": (0.05, 0.15, 0.75, 0.05), + "save": (0.05, 0.2, 0.65, 0.1), + "store": (0.05, 0.2, 0.65, 0.1), + "send": (0.15, 0.1, 0.65, 0.1), + "insert": (0.05, 0.15, 0.75, 0.05), + "append": (0.05, 0.15, 0.75, 0.05), + "prepend": (0.05, 0.15, 0.75, 0.05), + "replace": (0.05, 0.15, 0.75, 0.05), + "overwrite": (0.05, 0.1, 0.8, 0.05), + "clear": (0.05, 0.1, 0.8, 0.05), + "reset": (0.05, 0.15, 0.75, 0.05), + "initialize": (0.05, 0.15, 0.75, 0.05), + "setup": (0.05, 0.15, 0.75, 0.05), + "configure": (0.05, 0.2, 0.7, 0.05), + "install": (0.05, 0.15, 0.75, 0.05), + "uninstall": (0.05, 0.15, 0.75, 0.05), + "deploy": (0.05, 0.2, 0.7, 0.05), + "publish": (0.1, 0.15, 0.7, 0.05), + "upload": (0.05, 0.1, 0.8, 0.05), + "download": (0.05, 0.1, 0.8, 0.05), + "import": (0.05, 0.1, 0.8, 0.05), + "export": (0.05, 0.1, 0.8, 0.05), + "render": (0.05, 0.1, 0.75, 0.1), + "format": (0.05, 0.2, 0.7, 0.05), + "sanitize": (0.05, 0.25, 0.65, 0.05), + "normalize": (0.05, 0.25, 0.6, 0.1), + "convert": (0.05, 0.15, 0.75, 0.05), + "migrate": (0.05, 0.15, 0.75, 0.05), + "sync": (0.1, 0.2, 0.65, 0.05), + "refresh": (0.05, 0.1, 0.8, 0.05), + "reload": (0.05, 0.1, 0.8, 0.05), + "restart": (0.05, 0.1, 0.8, 0.05), + "start": (0.05, 0.1, 0.8, 0.05), + "stop": (0.05, 0.1, 0.8, 0.05), + "pause": (0.05, 0.1, 0.8, 0.05), + "resume": (0.05, 0.1, 0.8, 0.05), + "cancel": (0.05, 0.15, 0.75, 0.05), + "abort": (0.05, 0.15, 0.75, 0.05), + "commit": (0.05, 0.2, 0.7, 0.05), + "rollback": (0.05, 0.2, 0.7, 0.05), + "backup": (0.05, 0.2, 0.7, 0.05), + "restore": (0.05, 0.2, 0.7, 0.05), + "archive": (0.05, 0.2, 0.7, 0.05), + "compress": (0.05, 0.1, 0.8, 0.05), + "decompress": (0.05, 0.1, 0.8, 0.05), + "encrypt": (0.05, 0.2, 0.7, 0.05), + "decrypt": (0.05, 0.2, 0.7, 0.05), + "encode": (0.05, 0.15, 0.75, 0.05), + "decode": (0.05, 0.15, 0.75, 0.05), + "serialize": (0.05, 0.15, 0.75, 0.05), + "deserialize": (0.05, 0.15, 0.75, 0.05), + "parse": (0.05, 0.15, 0.6, 0.2), + "compile": (0.05, 0.15, 0.7, 0.1), + "optimize": (0.05, 0.2, 0.65, 0.1), # WISDOM-dominant verbs (analysis, understanding) - 'analyze': (0.05, 0.1, 0.1, 0.75), - 'calculate': (0.05, 0.15, 0.1, 0.7), - 'compute': (0.05, 0.15, 0.1, 0.7), - 'evaluate': (0.05, 0.2, 0.1, 0.65), - 'assess': (0.05, 0.2, 0.1, 0.65), - 'determine': (0.05, 0.2, 0.1, 0.65), - 'classify': (0.05, 0.25, 0.1, 0.6), - 'categorize': (0.05, 0.25, 0.1, 0.6), - 'predict': (0.05, 0.1, 0.15, 0.7), - 'infer': (0.05, 0.1, 0.1, 0.75), - 'learn': (0.1, 0.1, 0.1, 0.7), - 'understand': (0.15, 0.1, 0.05, 0.7), - 'recognize': (0.05, 0.15, 0.1, 0.7), - 'discover': (0.1, 0.1, 0.1, 0.7), - 'detect': (0.05, 0.2, 0.1, 0.65), - 'identify': (0.05, 0.2, 0.1, 0.65), - 'measure': (0.05, 0.2, 0.1, 0.65), - 'monitor': (0.05, 0.2, 0.1, 0.65), - 'track': (0.05, 0.2, 0.15, 0.6), - 'observe': (0.1, 0.15, 0.1, 0.65), - 'scan': (0.05, 0.15, 0.1, 0.7), - 'search': (0.05, 0.1, 0.15, 0.7), - 'find': (0.05, 0.1, 0.15, 0.7), - 'locate': (0.05, 0.1, 0.15, 0.7), - 'lookup': (0.05, 0.1, 0.15, 0.7), - 'query': (0.05, 0.15, 0.1, 0.7), - 'retrieve': (0.05, 0.1, 0.2, 0.65), - 'fetch': (0.05, 0.1, 0.2, 0.65), - 'get': (0.05, 0.1, 0.2, 0.65), - 'read': (0.05, 0.1, 0.15, 0.7), - 'extract': (0.05, 0.15, 0.2, 0.6), - 'aggregate': (0.05, 0.15, 0.15, 0.65), - 'summarize': (0.05, 0.1, 0.15, 0.7), - 'count': (0.05, 0.15, 0.1, 0.7), - 'rank': (0.05, 0.2, 0.1, 0.65), - 'sort': (0.05, 0.25, 0.15, 0.55), - 'order': (0.05, 0.25, 0.15, 0.55), - 'group': (0.05, 0.2, 0.15, 0.6), - 'partition': (0.05, 0.2, 0.15, 0.6), - 'split': (0.05, 0.15, 0.2, 0.6), - 'join': (0.05, 0.15, 0.2, 0.6), - 'correlate': (0.05, 0.15, 0.1, 0.7), - 'interpolate': (0.05, 0.15, 0.1, 0.7), - 'extrapolate': (0.05, 0.1, 0.15, 0.7), - 'estimate': (0.05, 0.15, 0.1, 0.7), - 'approximate': (0.05, 0.15, 0.1, 0.7), - 'model': (0.05, 0.15, 0.15, 0.65), - 'simulate': (0.05, 0.1, 0.15, 0.7), - 'test': (0.05, 0.3, 0.15, 0.5), - 'debug': (0.05, 0.25, 0.15, 0.55), - 'trace': (0.05, 0.2, 0.1, 0.65), - 'profile': (0.05, 0.2, 0.1, 0.65), - 'benchmark': (0.05, 0.25, 0.15, 0.55), - + "analyze": (0.05, 0.1, 0.1, 0.75), + "calculate": (0.05, 0.15, 0.1, 0.7), + "compute": (0.05, 0.15, 0.1, 0.7), + "evaluate": (0.05, 0.2, 0.1, 0.65), + "assess": (0.05, 0.2, 0.1, 0.65), + "determine": (0.05, 0.2, 0.1, 0.65), + "classify": (0.05, 0.25, 0.1, 0.6), + "categorize": (0.05, 0.25, 0.1, 0.6), + "predict": (0.05, 0.1, 0.15, 0.7), + "infer": (0.05, 0.1, 0.1, 0.75), + "learn": (0.1, 0.1, 0.1, 0.7), + "understand": (0.15, 0.1, 0.05, 0.7), + "recognize": (0.05, 0.15, 0.1, 0.7), + "discover": (0.1, 0.1, 0.1, 0.7), + "detect": (0.05, 0.2, 0.1, 0.65), + "identify": (0.05, 0.2, 0.1, 0.65), + "measure": (0.05, 0.2, 0.1, 0.65), + "monitor": (0.05, 0.2, 0.1, 0.65), + "track": (0.05, 0.2, 0.15, 0.6), + "observe": (0.1, 0.15, 0.1, 0.65), + "scan": (0.05, 0.15, 0.1, 0.7), + "search": (0.05, 0.1, 0.15, 0.7), + "find": (0.05, 0.1, 0.15, 0.7), + "locate": (0.05, 0.1, 0.15, 0.7), + "lookup": (0.05, 0.1, 0.15, 0.7), + "query": (0.05, 0.15, 0.1, 0.7), + "retrieve": (0.05, 0.1, 0.2, 0.65), + "fetch": (0.05, 0.1, 0.2, 0.65), + "get": (0.05, 0.1, 0.2, 0.65), + "read": (0.05, 0.1, 0.15, 0.7), + "extract": (0.05, 0.15, 0.2, 0.6), + "aggregate": (0.05, 0.15, 0.15, 0.65), + "summarize": (0.05, 0.1, 0.15, 0.7), + "count": (0.05, 0.15, 0.1, 0.7), + "rank": (0.05, 0.2, 0.1, 0.65), + "sort": (0.05, 0.25, 0.15, 0.55), + "order": (0.05, 0.25, 0.15, 0.55), + "group": (0.05, 0.2, 0.15, 0.6), + "partition": (0.05, 0.2, 0.15, 0.6), + "split": (0.05, 0.15, 0.2, 0.6), + "join": (0.05, 0.15, 0.2, 0.6), + "correlate": (0.05, 0.15, 0.1, 0.7), + "interpolate": (0.05, 0.15, 0.1, 0.7), + "extrapolate": (0.05, 0.1, 0.15, 0.7), + "estimate": (0.05, 0.15, 0.1, 0.7), + "approximate": (0.05, 0.15, 0.1, 0.7), + "model": (0.05, 0.15, 0.15, 0.65), + "simulate": (0.05, 0.1, 0.15, 0.7), + "test": (0.05, 0.3, 0.15, 0.5), + "debug": (0.05, 0.25, 0.15, 0.55), + "trace": (0.05, 0.2, 0.1, 0.65), + "profile": (0.05, 0.2, 0.1, 0.65), + "benchmark": (0.05, 0.25, 0.15, 0.55), # Mixed verbs - 'handle': (0.2, 0.3, 0.4, 0.1), # Mixed: care + rules + action - 'manage': (0.15, 0.35, 0.4, 0.1), # Justice + Power - 'coordinate': (0.3, 0.3, 0.3, 0.1), # Balanced Love/Justice/Power - 'orchestrate': (0.2, 0.3, 0.4, 0.1), # Similar to handle - 'dispatch': (0.1, 0.25, 0.6, 0.05), # Power with Justice - 'route': (0.1, 0.3, 0.55, 0.05), # Power with Justice - 'schedule': (0.05, 0.35, 0.55, 0.05), # Justice + Power - 'queue': (0.05, 0.3, 0.6, 0.05), # Justice + Power - 'enqueue': (0.05, 0.25, 0.65, 0.05), # More Power - 'dequeue': (0.05, 0.25, 0.65, 0.05), # More Power - 'push': (0.05, 0.15, 0.75, 0.05), # Power dominant - 'pop': (0.05, 0.15, 0.75, 0.05), # Power dominant - 'peek': (0.05, 0.1, 0.15, 0.7), # Wisdom dominant - 'invoke': (0.05, 0.15, 0.75, 0.05), # Power dominant - 'call': (0.1, 0.15, 0.7, 0.05), # Power with Love - 'request': (0.15, 0.2, 0.6, 0.05), # Power with Love - 'respond': (0.2, 0.15, 0.6, 0.05), # Power with Love - 'reply': (0.25, 0.15, 0.55, 0.05), # More Love - 'acknowledge': (0.3, 0.2, 0.45, 0.05), # Love + Justice - 'log': (0.05, 0.2, 0.5, 0.25), # Power + Wisdom - 'record': (0.05, 0.2, 0.5, 0.25), # Power + Wisdom - 'register': (0.05, 0.25, 0.6, 0.1), # Power + Justice - 'unregister': (0.05, 0.25, 0.6, 0.1), # Power + Justice - 'subscribe': (0.15, 0.2, 0.6, 0.05), # Power with Love - 'unsubscribe': (0.1, 0.2, 0.65, 0.05), # Power dominant - 'listen': (0.2, 0.15, 0.5, 0.15), # Love + Power + Wisdom - 'watch': (0.15, 0.2, 0.5, 0.15), # Justice + Power + Wisdom - 'poll': (0.05, 0.2, 0.6, 0.15), # Power + Wisdom - 'wait': (0.1, 0.15, 0.6, 0.15), # Power + Wisdom - 'sleep': (0.05, 0.1, 0.8, 0.05), # Power dominant - 'yield': (0.15, 0.2, 0.6, 0.05), # Power with Love/Justice - 'return': (0.05, 0.15, 0.75, 0.05), # Power dominant - 'raise': (0.05, 0.2, 0.7, 0.05), # Power + Justice - 'throw': (0.05, 0.2, 0.7, 0.05), # Power + Justice - 'catch': (0.1, 0.25, 0.6, 0.05), # Power + Justice - 'resolve': (0.15, 0.3, 0.45, 0.1), # Justice + Love + Power - 'fix': (0.1, 0.25, 0.6, 0.05), # Power + Justice - 'repair': (0.15, 0.2, 0.6, 0.05), # Power + Love - 'heal': (0.6, 0.15, 0.2, 0.05), # Love dominant - 'clean': (0.05, 0.3, 0.6, 0.05), # Power + Justice - 'purge': (0.05, 0.25, 0.65, 0.05), # Power + Justice - 'flush': (0.05, 0.2, 0.7, 0.05), # Power dominant - 'drain': (0.05, 0.15, 0.75, 0.05), # Power dominant - 'fill': (0.05, 0.15, 0.75, 0.05), # Power dominant - 'load': (0.05, 0.15, 0.75, 0.05), # Power dominant - 'unload': (0.05, 0.15, 0.75, 0.05), # Power dominant - 'open': (0.05, 0.15, 0.75, 0.05), # Power dominant - 'close': (0.05, 0.15, 0.75, 0.05), # Power dominant - 'lock': (0.05, 0.3, 0.6, 0.05), # Justice + Power - 'unlock': (0.05, 0.3, 0.6, 0.05), # Justice + Power - 'acquire': (0.05, 0.2, 0.7, 0.05), # Power + Justice - 'release': (0.05, 0.2, 0.7, 0.05), # Power + Justice - 'allocate': (0.05, 0.25, 0.65, 0.05), # Power + Justice - 'deallocate': (0.05, 0.25, 0.65, 0.05), # Power + Justice - 'reserve': (0.05, 0.3, 0.6, 0.05), # Justice + Power - 'claim': (0.05, 0.3, 0.6, 0.05), # Justice + Power - 'own': (0.1, 0.3, 0.55, 0.05), # Justice + Power - 'grant': (0.2, 0.4, 0.35, 0.05), # Justice + Love - 'revoke': (0.05, 0.4, 0.5, 0.05), # Justice + Power - 'delegate': (0.2, 0.3, 0.45, 0.05), # Love + Justice + Power - 'forward': (0.15, 0.2, 0.6, 0.05), # Power with Love - 'redirect': (0.1, 0.25, 0.6, 0.05), # Power + Justice - 'proxy': (0.1, 0.25, 0.6, 0.05), # Power + Justice - 'wrap': (0.05, 0.2, 0.7, 0.05), # Power + Justice - 'unwrap': (0.05, 0.2, 0.7, 0.05), # Power + Justice - 'decorate': (0.1, 0.15, 0.7, 0.05), # Power with Love - 'extend': (0.05, 0.15, 0.75, 0.05), # Power dominant - 'implement': (0.05, 0.2, 0.7, 0.05), # Power + Justice - 'override': (0.05, 0.2, 0.7, 0.05), # Power + Justice - 'inherit': (0.1, 0.25, 0.6, 0.05), # Power + Justice - 'compose': (0.05, 0.2, 0.65, 0.1), # Power + Justice + Wisdom - 'combine': (0.1, 0.2, 0.65, 0.05), # Power with Love - 'aggregate_data': (0.05, 0.2, 0.5, 0.25), # Power + Wisdom - 'reduce': (0.05, 0.15, 0.6, 0.2), # Power + Wisdom - 'map': (0.05, 0.15, 0.6, 0.2), # Power + Wisdom - 'apply': (0.05, 0.15, 0.75, 0.05), # Power dominant - 'bind': (0.1, 0.25, 0.6, 0.05), # Power + Justice - 'unbind': (0.05, 0.25, 0.65, 0.05), # Power + Justice - 'attach': (0.1, 0.2, 0.65, 0.05), # Power with Love - 'detach': (0.05, 0.2, 0.7, 0.05), # Power + Justice - 'link': (0.15, 0.2, 0.6, 0.05), # Love + Power - 'unlink': (0.05, 0.2, 0.7, 0.05), # Power + Justice - 'associate': (0.2, 0.2, 0.55, 0.05), # Love + Justice + Power - 'dissociate': (0.05, 0.25, 0.65, 0.05), # Justice + Power - 'relate': (0.25, 0.2, 0.5, 0.05), # Love + Justice + Power - 'correlate_data': (0.05, 0.2, 0.5, 0.25), # Power + Wisdom + "handle": (0.2, 0.3, 0.4, 0.1), # Mixed: care + rules + action + "manage": (0.15, 0.35, 0.4, 0.1), # Justice + Power + "coordinate": (0.3, 0.3, 0.3, 0.1), # Balanced Love/Justice/Power + "orchestrate": (0.2, 0.3, 0.4, 0.1), # Similar to handle + "dispatch": (0.1, 0.25, 0.6, 0.05), # Power with Justice + "route": (0.1, 0.3, 0.55, 0.05), # Power with Justice + "schedule": (0.05, 0.35, 0.55, 0.05), # Justice + Power + "queue": (0.05, 0.3, 0.6, 0.05), # Justice + Power + "enqueue": (0.05, 0.25, 0.65, 0.05), # More Power + "dequeue": (0.05, 0.25, 0.65, 0.05), # More Power + "push": (0.05, 0.15, 0.75, 0.05), # Power dominant + "pop": (0.05, 0.15, 0.75, 0.05), # Power dominant + "peek": (0.05, 0.1, 0.15, 0.7), # Wisdom dominant + "invoke": (0.05, 0.15, 0.75, 0.05), # Power dominant + "call": (0.1, 0.15, 0.7, 0.05), # Power with Love + "request": (0.15, 0.2, 0.6, 0.05), # Power with Love + "respond": (0.2, 0.15, 0.6, 0.05), # Power with Love + "reply": (0.25, 0.15, 0.55, 0.05), # More Love + "acknowledge": (0.3, 0.2, 0.45, 0.05), # Love + Justice + "log": (0.05, 0.2, 0.5, 0.25), # Power + Wisdom + "record": (0.05, 0.2, 0.5, 0.25), # Power + Wisdom + "register": (0.05, 0.25, 0.6, 0.1), # Power + Justice + "unregister": (0.05, 0.25, 0.6, 0.1), # Power + Justice + "subscribe": (0.15, 0.2, 0.6, 0.05), # Power with Love + "unsubscribe": (0.1, 0.2, 0.65, 0.05), # Power dominant + "listen": (0.2, 0.15, 0.5, 0.15), # Love + Power + Wisdom + "watch": (0.15, 0.2, 0.5, 0.15), # Justice + Power + Wisdom + "poll": (0.05, 0.2, 0.6, 0.15), # Power + Wisdom + "wait": (0.1, 0.15, 0.6, 0.15), # Power + Wisdom + "sleep": (0.05, 0.1, 0.8, 0.05), # Power dominant + "yield": (0.15, 0.2, 0.6, 0.05), # Power with Love/Justice + "return": (0.05, 0.15, 0.75, 0.05), # Power dominant + "raise": (0.05, 0.2, 0.7, 0.05), # Power + Justice + "throw": (0.05, 0.2, 0.7, 0.05), # Power + Justice + "catch": (0.1, 0.25, 0.6, 0.05), # Power + Justice + "resolve": (0.15, 0.3, 0.45, 0.1), # Justice + Love + Power + "fix": (0.1, 0.25, 0.6, 0.05), # Power + Justice + "repair": (0.15, 0.2, 0.6, 0.05), # Power + Love + "heal": (0.6, 0.15, 0.2, 0.05), # Love dominant + "clean": (0.05, 0.3, 0.6, 0.05), # Power + Justice + "purge": (0.05, 0.25, 0.65, 0.05), # Power + Justice + "flush": (0.05, 0.2, 0.7, 0.05), # Power dominant + "drain": (0.05, 0.15, 0.75, 0.05), # Power dominant + "fill": (0.05, 0.15, 0.75, 0.05), # Power dominant + "load": (0.05, 0.15, 0.75, 0.05), # Power dominant + "unload": (0.05, 0.15, 0.75, 0.05), # Power dominant + "open": (0.05, 0.15, 0.75, 0.05), # Power dominant + "close": (0.05, 0.15, 0.75, 0.05), # Power dominant + "lock": (0.05, 0.3, 0.6, 0.05), # Justice + Power + "unlock": (0.05, 0.3, 0.6, 0.05), # Justice + Power + "acquire": (0.05, 0.2, 0.7, 0.05), # Power + Justice + "release": (0.05, 0.2, 0.7, 0.05), # Power + Justice + "allocate": (0.05, 0.25, 0.65, 0.05), # Power + Justice + "deallocate": (0.05, 0.25, 0.65, 0.05), # Power + Justice + "reserve": (0.05, 0.3, 0.6, 0.05), # Justice + Power + "claim": (0.05, 0.3, 0.6, 0.05), # Justice + Power + "own": (0.1, 0.3, 0.55, 0.05), # Justice + Power + "grant": (0.2, 0.4, 0.35, 0.05), # Justice + Love + "revoke": (0.05, 0.4, 0.5, 0.05), # Justice + Power + "delegate": (0.2, 0.3, 0.45, 0.05), # Love + Justice + Power + "forward": (0.15, 0.2, 0.6, 0.05), # Power with Love + "redirect": (0.1, 0.25, 0.6, 0.05), # Power + Justice + "proxy": (0.1, 0.25, 0.6, 0.05), # Power + Justice + "wrap": (0.05, 0.2, 0.7, 0.05), # Power + Justice + "unwrap": (0.05, 0.2, 0.7, 0.05), # Power + Justice + "decorate": (0.1, 0.15, 0.7, 0.05), # Power with Love + "extend": (0.05, 0.15, 0.75, 0.05), # Power dominant + "implement": (0.05, 0.2, 0.7, 0.05), # Power + Justice + "override": (0.05, 0.2, 0.7, 0.05), # Power + Justice + "inherit": (0.1, 0.25, 0.6, 0.05), # Power + Justice + "compose": (0.05, 0.2, 0.65, 0.1), # Power + Justice + Wisdom + "combine": (0.1, 0.2, 0.65, 0.05), # Power with Love + "aggregate_data": (0.05, 0.2, 0.5, 0.25), # Power + Wisdom + "reduce": (0.05, 0.15, 0.6, 0.2), # Power + Wisdom + "map": (0.05, 0.15, 0.6, 0.2), # Power + Wisdom + "apply": (0.05, 0.15, 0.75, 0.05), # Power dominant + "bind": (0.1, 0.25, 0.6, 0.05), # Power + Justice + "unbind": (0.05, 0.25, 0.65, 0.05), # Power + Justice + "attach": (0.1, 0.2, 0.65, 0.05), # Power with Love + "detach": (0.05, 0.2, 0.7, 0.05), # Power + Justice + "link": (0.15, 0.2, 0.6, 0.05), # Love + Power + "unlink": (0.05, 0.2, 0.7, 0.05), # Power + Justice + "associate": (0.2, 0.2, 0.55, 0.05), # Love + Justice + Power + "dissociate": (0.05, 0.25, 0.65, 0.05), # Justice + Power + "relate": (0.25, 0.2, 0.5, 0.05), # Love + Justice + Power + "correlate_data": (0.05, 0.2, 0.5, 0.25), # Power + Wisdom } # Common object nouns for function names self.object_nouns = [ - 'user', 'data', 'record', 'item', 'entity', 'resource', - 'file', 'document', 'message', 'request', 'response', - 'transaction', 'event', 'task', 'job', 'process', - 'config', 'settings', 'preferences', 'state', 'status' + "user", + "data", + "record", + "item", + "entity", + "resource", + "file", + "document", + "message", + "request", + "response", + "transaction", + "event", + "task", + "job", + "process", + "config", + "settings", + "preferences", + "state", + "status", ] def suggest_names( - self, - coordinates: Coordinates, - context: str = "", - top_n: int = 5 + self, coordinates: Coordinates, context: str = "", top_n: int = 5 ) -> List[Tuple[str, float]]: """ Suggest function names based on semantic coordinates. @@ -308,10 +318,7 @@ def suggest_names( return suggestions[:top_n] def suggest_with_multiple_objects( - self, - coordinates: Coordinates, - top_verbs: int = 3, - top_objects: int = 3 + self, coordinates: Coordinates, top_verbs: int = 3, top_objects: int = 3 ) -> List[Tuple[str, float, str]]: """ Suggest function names by trying multiple verb-object combinations. @@ -340,9 +347,7 @@ def suggest_with_multiple_objects( return results def _calculate_similarity( - self, - coords1: Coordinates, - coords2: Tuple[float, float, float, float] + self, coords1: Coordinates, coords2: Tuple[float, float, float, float] ) -> float: """ Calculate cosine similarity between two coordinate vectors. @@ -373,7 +378,7 @@ def _calculate_similarity( def _generate_explanation( self, execution_coords: Coordinates, - verb_coords: Tuple[float, float, float, float] + verb_coords: Tuple[float, float, float, float], ) -> str: """Generate human-readable explanation of why this verb fits""" dominant = self._get_dominant_dimension(execution_coords) @@ -387,29 +392,28 @@ def _generate_explanation( def _get_dominant_dimension(self, coords: Coordinates) -> str: """Get the dominant dimension from coordinates""" values = { - 'love': coords.love, - 'justice': coords.justice, - 'power': coords.power, - 'wisdom': coords.wisdom + "love": coords.love, + "justice": coords.justice, + "power": coords.power, + "wisdom": coords.wisdom, } return max(values, key=values.get) def _get_dominant_dimension_from_tuple( - self, - coords: Tuple[float, float, float, float] + self, coords: Tuple[float, float, float, float] ) -> str: """Get dominant dimension from tuple""" - dimensions = ['love', 'justice', 'power', 'wisdom'] + dimensions = ["love", "justice", "power", "wisdom"] max_idx = coords.index(max(coords)) return dimensions[max_idx] def explain_coordinates(self, coordinates: Coordinates) -> str: """Generate human-readable explanation of semantic coordinates""" dims = { - 'love': (coordinates.love, 'connection/care'), - 'justice': (coordinates.justice, 'validation/order'), - 'power': (coordinates.power, 'action/transformation'), - 'wisdom': (coordinates.wisdom, 'analysis/understanding') + "love": (coordinates.love, "connection/care"), + "justice": (coordinates.justice, "validation/order"), + "power": (coordinates.power, "action/transformation"), + "wisdom": (coordinates.wisdom, "analysis/understanding"), } # Sort by value @@ -442,8 +446,10 @@ def explain_coordinates(self, coordinates: Coordinates) -> str: for name, score in suggestions: print(f" {name:30s} (similarity: {score:.3f})") - print("\n" + "="*60) + print("\n" + "=" * 60) print("Suggestions with multiple objects:") - multi_suggestions = engine.suggest_with_multiple_objects(coords, top_verbs=3, top_objects=3) + multi_suggestions = engine.suggest_with_multiple_objects( + coords, top_verbs=3, top_objects=3 + ) for name, score, explanation in multi_suggestions[:10]: print(f" {name:30s} {score:.3f} - {explanation}") diff --git a/test_mixing_formula.py b/test_mixing_formula.py index c93024c..de34683 100644 --- a/test_mixing_formula.py +++ b/test_mixing_formula.py @@ -4,10 +4,9 @@ Using REAL data from the Python Code Harmonizer semantic engine. """ -import sys from harmonizer.divine_invitation_engine_V2 import ( DivineInvitationSemanticEngine, - Coordinates + Coordinates, ) import math @@ -19,20 +18,20 @@ def universal_semantic_mix(primary_weights): return Coordinates(0, 0, 0, 0) return Coordinates( - love=primary_weights.get('love', 0) / total, - justice=primary_weights.get('justice', 0) / total, - power=primary_weights.get('power', 0) / total, - wisdom=primary_weights.get('wisdom', 0) / total + love=primary_weights.get("love", 0) / total, + justice=primary_weights.get("justice", 0) / total, + power=primary_weights.get("power", 0) / total, + wisdom=primary_weights.get("wisdom", 0) / total, ) def semantic_distance(coord1, coord2): """Calculate Euclidean distance between coordinates""" return math.sqrt( - (coord1.love - coord2.love) ** 2 + - (coord1.justice - coord2.justice) ** 2 + - (coord1.power - coord2.power) ** 2 + - (coord1.wisdom - coord2.wisdom) ** 2 + (coord1.love - coord2.love) ** 2 + + (coord1.justice - coord2.justice) ** 2 + + (coord1.power - coord2.power) ** 2 + + (coord1.wisdom - coord2.wisdom) ** 2 ) @@ -45,10 +44,10 @@ def test_basic_primaries(): engine = DivineInvitationSemanticEngine() primary_tests = { - 'love': ['love', 'compassion', 'mercy', 'kindness'], - 'justice': ['justice', 'truth', 'fairness', 'rights'], - 'power': ['power', 'strength', 'authority', 'control'], - 'wisdom': ['wisdom', 'knowledge', 'understanding', 'insight'] + "love": ["love", "compassion", "mercy", "kindness"], + "justice": ["justice", "truth", "fairness", "rights"], + "power": ["power", "strength", "authority", "control"], + "wisdom": ["wisdom", "knowledge", "understanding", "insight"], } results = {} @@ -68,8 +67,8 @@ def test_basic_primaries(): avg_purity = sum(dimension_results) / len(dimension_results) results[dimension] = { - 'avg_purity': avg_purity, - 'status': 'PURE' if avg_purity > 0.7 else 'MIXED' + "avg_purity": avg_purity, + "status": "PURE" if avg_purity > 0.7 else "MIXED", } print(f" Average Purity: {avg_purity:.3f} [{results[dimension]['status']}]") @@ -87,29 +86,37 @@ def test_simple_mixtures(): # Test simple 50/50 mixtures mixture_tests = [ { - 'name': 'love + justice', - 'concepts': ['compassion fairness', 'mercy justice', 'kindness rights'], - 'recipe': {'love': 1, 'justice': 1}, - 'expected': Coordinates(0.5, 0.5, 0.0, 0.0) + "name": "love + justice", + "concepts": ["compassion fairness", "mercy justice", "kindness rights"], + "recipe": {"love": 1, "justice": 1}, + "expected": Coordinates(0.5, 0.5, 0.0, 0.0), }, { - 'name': 'power + wisdom', - 'concepts': ['strength knowledge', 'authority understanding', 'control insight'], - 'recipe': {'power': 1, 'wisdom': 1}, - 'expected': Coordinates(0.0, 0.0, 0.5, 0.5) + "name": "power + wisdom", + "concepts": [ + "strength knowledge", + "authority understanding", + "control insight", + ], + "recipe": {"power": 1, "wisdom": 1}, + "expected": Coordinates(0.0, 0.0, 0.5, 0.5), }, { - 'name': 'love + wisdom', - 'concepts': ['compassion understanding', 'mercy knowledge', 'kindness wisdom'], - 'recipe': {'love': 1, 'wisdom': 1}, - 'expected': Coordinates(0.5, 0.0, 0.0, 0.5) + "name": "love + wisdom", + "concepts": [ + "compassion understanding", + "mercy knowledge", + "kindness wisdom", + ], + "recipe": {"love": 1, "wisdom": 1}, + "expected": Coordinates(0.5, 0.0, 0.0, 0.5), }, { - 'name': 'justice + power', - 'concepts': ['law enforcement', 'legal authority', 'rights control'], - 'recipe': {'justice': 1, 'power': 1}, - 'expected': Coordinates(0.0, 0.5, 0.5, 0.0) - } + "name": "justice + power", + "concepts": ["law enforcement", "legal authority", "rights control"], + "recipe": {"justice": 1, "power": 1}, + "expected": Coordinates(0.0, 0.5, 0.5, 0.0), + }, ] results = [] @@ -118,10 +125,10 @@ def test_simple_mixtures(): print(f" Recipe: {test['recipe']}") print(f" Predicted: {test['expected']}") - predicted = universal_semantic_mix(test['recipe']) + predicted = universal_semantic_mix(test["recipe"]) errors = [] - for concept in test['concepts']: + for concept in test["concepts"]: result = engine.analyze_text(concept) actual = result.coordinates error = semantic_distance(predicted, actual) @@ -133,13 +140,13 @@ def test_simple_mixtures(): avg_error = sum(errors) / len(errors) success = avg_error < 0.3 - results.append({ - 'name': test['name'], - 'avg_error': avg_error, - 'success': success - }) + results.append( + {"name": test["name"], "avg_error": avg_error, "success": success} + ) - print(f" Average Error: {avg_error:.3f} {'āœ… SUCCESS' if success else 'āŒ FAILED'}") + print( + f" Average Error: {avg_error:.3f} {'āœ… SUCCESS' if success else 'āŒ FAILED'}" + ) return results @@ -154,23 +161,31 @@ def test_complex_mixtures(): weighted_tests = [ { - 'name': '2:1 love:wisdom', - 'concepts': ['compassionate understanding', 'merciful knowledge', 'kind wisdom'], - 'recipe': {'love': 2, 'wisdom': 1}, - 'expected': Coordinates(0.667, 0.0, 0.0, 0.333) + "name": "2:1 love:wisdom", + "concepts": [ + "compassionate understanding", + "merciful knowledge", + "kind wisdom", + ], + "recipe": {"love": 2, "wisdom": 1}, + "expected": Coordinates(0.667, 0.0, 0.0, 0.333), }, { - 'name': '2:1 justice:power', - 'concepts': ['legal authority', 'law enforcement', 'fair control'], - 'recipe': {'justice': 2, 'power': 1}, - 'expected': Coordinates(0.0, 0.667, 0.333, 0.0) + "name": "2:1 justice:power", + "concepts": ["legal authority", "law enforcement", "fair control"], + "recipe": {"justice": 2, "power": 1}, + "expected": Coordinates(0.0, 0.667, 0.333, 0.0), }, { - 'name': '3:1 wisdom:power', - 'concepts': ['strategic knowledge', 'wise authority', 'understanding control'], - 'recipe': {'wisdom': 3, 'power': 1}, - 'expected': Coordinates(0.0, 0.0, 0.25, 0.75) - } + "name": "3:1 wisdom:power", + "concepts": [ + "strategic knowledge", + "wise authority", + "understanding control", + ], + "recipe": {"wisdom": 3, "power": 1}, + "expected": Coordinates(0.0, 0.0, 0.25, 0.75), + }, ] results = [] @@ -178,11 +193,11 @@ def test_complex_mixtures(): print(f"\n{test['name'].upper()}:") print(f" Recipe: {test['recipe']}") - predicted = universal_semantic_mix(test['recipe']) + predicted = universal_semantic_mix(test["recipe"]) print(f" Predicted: {predicted}") errors = [] - for concept in test['concepts']: + for concept in test["concepts"]: result = engine.analyze_text(concept) actual = result.coordinates error = semantic_distance(predicted, actual) @@ -194,13 +209,13 @@ def test_complex_mixtures(): avg_error = sum(errors) / len(errors) success = avg_error < 0.4 # More lenient threshold for weighted mixtures - results.append({ - 'name': test['name'], - 'avg_error': avg_error, - 'success': success - }) + results.append( + {"name": test["name"], "avg_error": avg_error, "success": success} + ) - print(f" Average Error: {avg_error:.3f} {'āœ… SUCCESS' if success else 'āŒ FAILED'}") + print( + f" Average Error: {avg_error:.3f} {'āœ… SUCCESS' if success else 'āŒ FAILED'}" + ) return results @@ -214,16 +229,16 @@ def test_balanced_mixture(): engine = DivineInvitationSemanticEngine() print("\nTesting equal mixture of all four primaries:") - recipe = {'love': 1, 'justice': 1, 'power': 1, 'wisdom': 1} + recipe = {"love": 1, "justice": 1, "power": 1, "wisdom": 1} predicted = universal_semantic_mix(recipe) print(f" Recipe: {recipe}") print(f" Predicted: {predicted}") # Test concepts that should represent balance balanced_concepts = [ - 'compassionate wise just leadership', - 'merciful fair strong understanding', - 'kind righteous powerful knowledgeable' + "compassionate wise just leadership", + "merciful fair strong understanding", + "kind righteous powerful knowledgeable", ] errors = [] @@ -240,52 +255,63 @@ def test_balanced_mixture(): avg_error = sum(errors) / len(errors) success = avg_error < 0.3 - print(f"\n Average Error: {avg_error:.3f} {'āœ… SUCCESS' if success else 'āŒ FAILED'}") + print( + f"\n Average Error: {avg_error:.3f} {'āœ… SUCCESS' if success else 'āŒ FAILED'}" + ) - return { - 'avg_error': avg_error, - 'success': success - } + return {"avg_error": avg_error, "success": success} -def generate_summary(primary_results, simple_results, weighted_results, balanced_result): +def generate_summary( + primary_results, simple_results, weighted_results, balanced_result +): """Generate final summary of all tests""" print("\n" + "=" * 70) print("FINAL SUMMARY") print("=" * 70) # Primary purity - avg_purity = sum(r['avg_purity'] for r in primary_results.values()) / len(primary_results) + avg_purity = sum(r["avg_purity"] for r in primary_results.values()) / len( + primary_results + ) print(f"\n1. Primary Purity: {avg_purity:.3f}") - print(f" {'āœ… PASS' if avg_purity > 0.7 else 'āŒ FAIL'} - Primaries are {'pure enough' if avg_purity > 0.7 else 'too mixed'}") + print( + f" {'āœ… PASS' if avg_purity > 0.7 else 'āŒ FAIL'} - Primaries are {'pure enough' if avg_purity > 0.7 else 'too mixed'}" + ) # Simple mixtures - simple_success_rate = sum(1 for r in simple_results if r['success']) / len(simple_results) - avg_simple_error = sum(r['avg_error'] for r in simple_results) / len(simple_results) - print(f"\n2. Simple Mixtures:") + simple_success_rate = sum(1 for r in simple_results if r["success"]) / len( + simple_results + ) + avg_simple_error = sum(r["avg_error"] for r in simple_results) / len(simple_results) + print("\n2. Simple Mixtures:") print(f" Success Rate: {simple_success_rate:.1%}") print(f" Average Error: {avg_simple_error:.3f}") print(f" {'āœ… PASS' if simple_success_rate >= 0.5 else 'āŒ FAIL'}") # Weighted mixtures - weighted_success_rate = sum(1 for r in weighted_results if r['success']) / len(weighted_results) - avg_weighted_error = sum(r['avg_error'] for r in weighted_results) / len(weighted_results) - print(f"\n3. Weighted Mixtures:") + weighted_success_rate = sum(1 for r in weighted_results if r["success"]) / len( + weighted_results + ) + avg_weighted_error = sum(r["avg_error"] for r in weighted_results) / len( + weighted_results + ) + print("\n3. Weighted Mixtures:") print(f" Success Rate: {weighted_success_rate:.1%}") print(f" Average Error: {avg_weighted_error:.3f}") print(f" {'āœ… PASS' if weighted_success_rate >= 0.5 else 'āŒ FAIL'}") # Balanced mixture - print(f"\n4. Balanced Mixture:") + print("\n4. Balanced Mixture:") print(f" Error: {balanced_result['avg_error']:.3f}") print(f" {'āœ… PASS' if balanced_result['success'] else 'āŒ FAIL'}") # Overall assessment overall_pass = ( - avg_purity > 0.7 and - simple_success_rate >= 0.5 and - weighted_success_rate >= 0.5 and - balanced_result['success'] + avg_purity > 0.7 + and simple_success_rate >= 0.5 + and weighted_success_rate >= 0.5 + and balanced_result["success"] ) print("\n" + "=" * 70) diff --git a/tests/test_harmonizer.py b/tests/test_harmonizer.py index d046c3e..0b20754 100644 --- a/tests/test_harmonizer.py +++ b/tests/test_harmonizer.py @@ -3,7 +3,6 @@ import argparse import os import tempfile -import argparse import pytest from harmonizer.main import ( diff --git a/tests/test_parser.py b/tests/test_parser.py index 2d7a7bc..b52a7d1 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -3,7 +3,6 @@ import ast import pytest -import ast from harmonizer.ast_semantic_parser import AST_Semantic_Parser from harmonizer.divine_invitation_engine_V2 import DivineInvitationSemanticEngine diff --git a/tests/test_semantic_naming.py b/tests/test_semantic_naming.py index 6124c8e..fd7d2cd 100644 --- a/tests/test_semantic_naming.py +++ b/tests/test_semantic_naming.py @@ -22,21 +22,21 @@ class TestInitialization: def test_engine_initialization(self, naming_engine): """Verify the naming engine initializes correctly""" assert naming_engine is not None - assert hasattr(naming_engine, 'action_verbs') - assert hasattr(naming_engine, 'object_nouns') + assert hasattr(naming_engine, "action_verbs") + assert hasattr(naming_engine, "object_nouns") def test_action_verbs_loaded(self, naming_engine): """Verify action verbs dictionary is populated""" assert len(naming_engine.action_verbs) > 0 - assert 'validate' in naming_engine.action_verbs - assert 'create' in naming_engine.action_verbs - assert 'analyze' in naming_engine.action_verbs + assert "validate" in naming_engine.action_verbs + assert "create" in naming_engine.action_verbs + assert "analyze" in naming_engine.action_verbs def test_object_nouns_loaded(self, naming_engine): """Verify object nouns list is populated""" assert len(naming_engine.object_nouns) > 0 - assert 'user' in naming_engine.object_nouns - assert 'data' in naming_engine.object_nouns + assert "user" in naming_engine.object_nouns + assert "data" in naming_engine.object_nouns class TestSuggestionGeneration: @@ -71,8 +71,11 @@ def test_suggest_names_justice_dominant(self, naming_engine): # Should suggest justice verbs like validate, verify, check names = [s[0] for s in suggestions] - assert any(verb in name for verb in ['validate', 'verify', 'check', 'ensure'] - for name in names) + assert any( + verb in name + for verb in ["validate", "verify", "check", "ensure"] + for name in names + ) def test_suggest_names_wisdom_dominant(self, naming_engine): """Test suggestions for a wisdom-dominant function""" @@ -82,8 +85,11 @@ def test_suggest_names_wisdom_dominant(self, naming_engine): # Should suggest wisdom verbs like analyze, calculate, evaluate names = [s[0] for s in suggestions] - assert any(verb in name for verb in ['analyze', 'calculate', 'evaluate', 'compute'] - for name in names) + assert any( + verb in name + for verb in ["analyze", "calculate", "evaluate", "compute"] + for name in names + ) def test_suggest_names_love_dominant(self, naming_engine): """Test suggestions for a love-dominant function""" @@ -217,7 +223,9 @@ def test_explain_coordinates_power_dominant(self, naming_engine): explanation = naming_engine.explain_coordinates(coords) assert "power" in explanation.lower() - assert "action" in explanation.lower() or "transformation" in explanation.lower() + assert ( + "action" in explanation.lower() or "transformation" in explanation.lower() + ) def test_explain_coordinates_balanced(self, naming_engine): """Test explanation for balanced coordinates""" @@ -253,31 +261,31 @@ def test_get_dominant_dimension_power(self, naming_engine): """Test dominant dimension detection for power""" coords = Coordinates(love=0.1, justice=0.1, power=0.7, wisdom=0.1) dominant = naming_engine._get_dominant_dimension(coords) - assert dominant == 'power' + assert dominant == "power" def test_get_dominant_dimension_justice(self, naming_engine): """Test dominant dimension detection for justice""" coords = Coordinates(love=0.1, justice=0.7, power=0.1, wisdom=0.1) dominant = naming_engine._get_dominant_dimension(coords) - assert dominant == 'justice' + assert dominant == "justice" def test_get_dominant_dimension_wisdom(self, naming_engine): """Test dominant dimension detection for wisdom""" coords = Coordinates(love=0.1, justice=0.1, power=0.1, wisdom=0.7) dominant = naming_engine._get_dominant_dimension(coords) - assert dominant == 'wisdom' + assert dominant == "wisdom" def test_get_dominant_dimension_love(self, naming_engine): """Test dominant dimension detection for love""" coords = Coordinates(love=0.7, justice=0.1, power=0.1, wisdom=0.1) dominant = naming_engine._get_dominant_dimension(coords) - assert dominant == 'love' + assert dominant == "love" def test_get_dominant_dimension_from_tuple(self, naming_engine): """Test dominant dimension detection from tuple""" vec = (0.1, 0.7, 0.1, 0.1) dominant = naming_engine._get_dominant_dimension_from_tuple(vec) - assert dominant == 'justice' + assert dominant == "justice" class TestEdgeCases: @@ -315,28 +323,28 @@ class TestVerbCoordinateAccuracy: def test_validate_verb_is_justice_dominant(self, naming_engine): """Verify 'validate' is primarily Justice""" - coords = naming_engine.action_verbs['validate'] + coords = naming_engine.action_verbs["validate"] assert coords[1] > coords[0] # Justice > Love assert coords[1] > coords[2] # Justice > Power assert coords[1] > coords[3] # Justice > Wisdom def test_create_verb_is_power_dominant(self, naming_engine): """Verify 'create' is primarily Power""" - coords = naming_engine.action_verbs['create'] + coords = naming_engine.action_verbs["create"] assert coords[2] > coords[0] # Power > Love assert coords[2] > coords[1] # Power > Justice assert coords[2] > coords[3] # Power > Wisdom def test_analyze_verb_is_wisdom_dominant(self, naming_engine): """Verify 'analyze' is primarily Wisdom""" - coords = naming_engine.action_verbs['analyze'] + coords = naming_engine.action_verbs["analyze"] assert coords[3] > coords[0] # Wisdom > Love assert coords[3] > coords[1] # Wisdom > Justice assert coords[3] > coords[2] # Wisdom > Power def test_care_for_verb_is_love_dominant(self, naming_engine): """Verify 'care_for' is primarily Love""" - coords = naming_engine.action_verbs['care_for'] + coords = naming_engine.action_verbs["care_for"] assert coords[0] > coords[1] # Love > Justice assert coords[0] > coords[2] # Love > Power assert coords[0] > coords[3] # Love > Wisdom @@ -345,8 +353,9 @@ def test_all_verb_coordinates_sum_to_one(self, naming_engine): """Verify all verb coordinates are normalized (sum to ~1.0)""" for verb, coords in naming_engine.action_verbs.items(): total = sum(coords) - assert total == pytest.approx(1.0, abs=0.01), \ - f"Verb '{verb}' coordinates sum to {total}, expected ~1.0" + assert total == pytest.approx( + 1.0, abs=0.01 + ), f"Verb '{verb}' coordinates sum to {total}, expected ~1.0" class TestIntegrationWithDIVE: @@ -354,7 +363,9 @@ class TestIntegrationWithDIVE: def test_suggest_names_with_dive_coordinates(self, naming_engine): """Test that suggestions work with actual DIVE-generated coordinates""" - from harmonizer.divine_invitation_engine_V2 import DivineInvitationSemanticEngine + from harmonizer.divine_invitation_engine_V2 import ( + DivineInvitationSemanticEngine, + ) dive_engine = DivineInvitationSemanticEngine() result = dive_engine.analyze_text("validate user input")