Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions demo_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ def analyze_with_v2(code, function_name):
disharmony = engine.get_distance(intent_coords, execution_coords)

return {
'function': function_name,
'intent_concepts': intent_concepts,
'execution_concepts': execution_concepts,
'intent_coords': intent_coords,
'execution_coords': execution_coords,
'disharmony': disharmony
"function": function_name,
"intent_concepts": intent_concepts,
"execution_concepts": execution_concepts,
"intent_coords": intent_coords,
"execution_coords": execution_coords,
"disharmony": disharmony,
}


Expand All @@ -51,28 +51,32 @@ def print_analysis(result):

print(f"\nINTENT (what function claims to do):")
print(f" Concepts: {result['intent_concepts']}")
print(f" Coordinates: L={result['intent_coords'].love:.3f}, J={result['intent_coords'].justice:.3f}, "
f"P={result['intent_coords'].power:.3f}, W={result['intent_coords'].wisdom:.3f}")
print(
f" Coordinates: L={result['intent_coords'].love:.3f}, J={result['intent_coords'].justice:.3f}, "
f"P={result['intent_coords'].power:.3f}, W={result['intent_coords'].wisdom:.3f}"
)

print(f"\nEXECUTION (what function actually does):")
print(f" Concepts: {result['execution_concepts']}")
print(f" Coordinates: L={result['execution_coords'].love:.3f}, J={result['execution_coords'].justice:.3f}, "
f"P={result['execution_coords'].power:.3f}, W={result['execution_coords'].wisdom:.3f}")
print(
f" Coordinates: L={result['execution_coords'].love:.3f}, J={result['execution_coords'].justice:.3f}, "
f"P={result['execution_coords'].power:.3f}, W={result['execution_coords'].wisdom:.3f}"
)

print(f"\nDISHARMONY SCORE: {result['disharmony']:.3f}")

if result['disharmony'] < 0.5:
if result["disharmony"] < 0.5:
print("STATUS: ✅ EXCELLENT HARMONY")
elif result['disharmony'] < 1.0:
elif result["disharmony"] < 1.0:
print("STATUS: ⚠️ MEDIUM DISHARMONY")
else:
print("STATUS: 🚨 CRITICAL DISHARMONY - Likely Bug!")


# Test examples
print("="*70)
print("=" * 70)
print("ENHANCED PARSER V2 - REAL-WORLD DEMONSTRATION")
print("="*70)
print("=" * 70)

# Example 1: Harmonious function
code1 = '''
Expand Down Expand Up @@ -131,7 +135,7 @@ def fetch_validate_and_save(data_id):

print(f"\n{'='*70}")
print("DEMONSTRATION COMPLETE")
print("="*70)
print("=" * 70)
print("\n✅ Enhanced Parser V2 Features:")
print(" • 184 programming verbs (7.4x more than V1)")
print(" • Compound pattern detection (get_user, send_notification, etc.)")
Expand Down
12 changes: 8 additions & 4 deletions harmonizer/ast_semantic_parser_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,18 @@ def _split_snake_case(self, name: str) -> List[str]:

def _split_camel_case(self, name: str) -> List[str]:
"""Split 'getUserById' into ['get', 'User', 'By', 'Id']"""
return re.findall(r'[A-Z]?[a-z]+|[A-Z]+(?=[A-Z][a-z]|\d|\W|$)|\d+', name)
return re.findall(r"[A-Z]?[a-z]+|[A-Z]+(?=[A-Z][a-z]|\d|\W|$)|\d+", name)

def _split_name(self, name: str) -> List[str]:
"""Smart name splitting supporting both snake_case and camelCase"""
if '_' in name:
if "_" in name:
return self._split_snake_case(name)
else:
return self._split_camel_case(name)

def _map_word_to_concept(self, word: str, context: str = "default") -> Optional[str]:
def _map_word_to_concept(
self, word: str, context: str = "default"
) -> Optional[str]:
"""
Map a word to its semantic dimension.

Expand Down Expand Up @@ -158,7 +160,9 @@ def get_intent_concepts(

# Fallback to words in vocabulary
if not concepts and name_words:
concepts.update([word for word in name_words if word in self.known_vocabulary])
concepts.update(
[word for word in name_words if word in self.known_vocabulary]
)

return list(concepts)

Expand Down
52 changes: 14 additions & 38 deletions harmonizer/programming_constructs_vocabulary.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
# WISDOM-DOMINANT OPERATIONS (Information & Knowledge)
# Semantic signature: (L=0.1, J=0.1, P=0.1, W=0.7)
# ====================================================================

# Information retrieval
"get": "wisdom",
"fetch": "wisdom",
Expand All @@ -30,7 +29,6 @@
"search": "wisdom",
"lookup": "wisdom",
"access": "wisdom",

# Computation & analysis
"calculate": "wisdom",
"compute": "wisdom",
Expand All @@ -42,39 +40,33 @@
"sum": "wisdom",
"average": "wisdom",
"aggregate": "wisdom",

# Understanding & interpretation
"parse": "wisdom",
"interpret": "wisdom",
"decode": "wisdom",
"decipher": "wisdom",
"understand": "wisdom",
"comprehend": "wisdom",

# Knowledge representation
"represent": "wisdom",
"model": "wisdom",
"describe": "wisdom",
"define": "wisdom",
"specify": "wisdom",

# Observation & monitoring
"observe": "wisdom",
"monitor": "wisdom",
"watch": "wisdom",
"track": "wisdom",
"log": "wisdom",
"record": "wisdom",

# Returns are WISDOM (giving information back)
"return": "wisdom",
"yield": "wisdom",

# ====================================================================
# JUSTICE-DOMINANT OPERATIONS (Correctness & Validation)
# Semantic signature: (L=0.1, J=0.7, P=0.1, W=0.1)
# ====================================================================

# Validation & verification
"validate": "justice",
"verify": "justice",
Expand All @@ -83,26 +75,22 @@
"ensure": "justice",
"confirm": "justice",
"certify": "justice",

# Enforcement & rules
"enforce": "justice",
"assert": "justice",
"require": "justice",
"demand": "justice",
"mandate": "justice",

# Comparison & equality
"compare": "justice",
"equals": "justice",
"match": "justice",
"differs": "justice",

# Filtering & selection
"filter": "justice",
"select": "justice",
"reject": "justice",
"accept": "justice",

# Authorization & permission
"authorize": "justice",
"authenticate": "justice",
Expand All @@ -111,26 +99,22 @@
"deny": "justice",
"restrict": "justice",
"approve": "justice",

# Boolean predicates (is_*, has_*, can_*)
"is": "justice",
"has": "justice",
"can": "justice",
"should": "justice",
"must": "justice",

# Ordering & structuring
"order": "justice",
"sort": "justice",
"arrange": "justice",
"organize": "justice",
"structure": "justice",

# ====================================================================
# POWER-DOMINANT OPERATIONS (Execution & Transformation)
# Semantic signature: (L=0.1, J=0.1, P=0.7, W=0.1)
# ====================================================================

# Creation & generation
"create": "power",
"build": "power",
Expand All @@ -141,7 +125,6 @@
"spawn": "power",
"initialize": "power",
"instantiate": "power",

# Modification & transformation
"modify": "power",
"update": "power",
Expand All @@ -152,7 +135,6 @@
"mutate": "power",
"edit": "power",
"revise": "power",

# Destruction & removal
"delete": "power",
"remove": "power",
Expand All @@ -162,7 +144,6 @@
"purge": "power",
"drop": "power",
"truncate": "power",

# Storage operations
"save": "power",
"store": "power",
Expand All @@ -171,7 +152,6 @@
"insert": "power",
"append": "power",
"prepend": "power",

# Execution & control
"execute": "power",
"run": "power",
Expand All @@ -187,7 +167,6 @@
"pause": "power",
"resume": "power",
"restart": "power",

# State management
"set": "power",
"reset": "power",
Expand All @@ -196,23 +175,19 @@
"disable": "power",
"activate": "power",
"deactivate": "power",

# Processing
"process": "power",
"handle": "power",
"apply": "power",
"render": "power",
"compile": "power",

# Raising errors is POWER (forcing exception)
"raise": "power",
"throw": "power",

# ====================================================================
# LOVE-DOMINANT OPERATIONS (Connection & Communication)
# Semantic signature: (L=0.7, J=0.1, P=0.1, W=0.1)
# ====================================================================

# Connection & integration
"connect": "love",
"link": "love",
Expand All @@ -225,7 +200,6 @@
"combine": "love",
"unite": "love",
"integrate": "love",

# Communication & notification
"send": "love",
"notify": "love",
Expand All @@ -237,46 +211,39 @@
"signal": "love",
"alert": "love",
"message": "love",

# Composition & building relationships
"compose": "love",
"assemble": "love",
"aggregate": "love",
"collect": "love",
"gather": "love",

# Sharing & distribution
"share": "love",
"distribute": "love",
"spread": "love",
"propagate": "love",

# Synchronization & coordination
"sync": "love",
"synchronize": "love",
"coordinate": "love",
"orchestrate": "love",

# Output & display (communication to user)
"print": "love",
"display": "love",
"show": "love",
"render": "love",
"present": "love",

# API & interface operations
"expose": "love",
"provide": "love",
"serve": "love",
"offer": "love",

# Adding to collections is LOVE (community building)
# UNLESS it's to a specific technical collection like _concepts_found
# That case is handled specially in the parser
"add": "love",
"include": "love",
"incorporate": "love",

# Exception handling is LOVE (mercy, graceful degradation)
"handle": "love",
"catch": "love",
Expand All @@ -287,8 +254,18 @@
# Control flow keywords - these are recognized differently
# They are always JUSTICE (logical structure)
CONTROL_FLOW_KEYWORDS = {
"if", "else", "elif", "for", "while", "with", "try", "except",
"finally", "assert", "break", "continue"
"if",
"else",
"elif",
"for",
"while",
"with",
"try",
"except",
"finally",
"assert",
"break",
"continue",
}

# Special cases that require context
Expand All @@ -314,22 +291,19 @@
"query_database": "wisdom",
"calculate_total": "wisdom",
"compute_hash": "wisdom",

# JUSTICE patterns
"validate_input": "justice",
"check_permission": "justice",
"verify_token": "justice",
"test_condition": "justice",
"ensure_valid": "justice",

# POWER patterns
"create_user": "power",
"delete_record": "power",
"update_status": "power",
"save_file": "power",
"execute_command": "power",
"process_request": "power",

# LOVE patterns
"send_notification": "love",
"notify_user": "love",
Expand All @@ -338,6 +312,7 @@
"broadcast_event": "love",
}


def get_semantic_dimension(verb: str, context: str = "default") -> str:
"""
Get the semantic dimension for a programming verb.
Expand Down Expand Up @@ -412,6 +387,7 @@ def explain_programming_semantics():

# Show distribution
from collections import Counter

distribution = Counter(PROGRAMMING_VERBS.values())
print()
print("Distribution across dimensions:")
Expand Down
Loading