22# -*- coding: utf-8 -*-
33
44"""
5- Python Code Harmonizer (Version 1.4 )
5+ Python Code Harmonizer (Version 1.5 )
66
77This is the main application that integrates the Divine Invitation
88Semantic Engine (DIVE-V2) with the AST Semantic Parser. It now includes
9- a proof-of-concept self-healing capability .
9+ semantic naming suggestions .
1010
11- New in v1.4:
12- - Refactorer engine for suggesting dimensional splits.
13- - --suggest-refactor flag to generate refactored code.
14- - Enhanced AST parser with node-to-dimension mapping.
11+ New in v1.5:
12+ - Semantic naming engine with 200+ action verbs
13+ - --suggest-names flag to show function name suggestions
14+ - --top-suggestions flag to control number of suggestions
15+ - Intelligent name matching using cosine similarity in 4D semantic space
16+
17+ Previous versions:
18+ - v1.4: Refactorer engine and dimensional splits
19+ - v1.3: Semantic trajectory maps
1520"""
1621
1722import os
3540from harmonizer .ast_semantic_parser import AST_Semantic_Parser # noqa: E402
3641from harmonizer .refactorer import Refactorer # noqa: E402
3742from harmonizer .semantic_map import SemanticMapGenerator # noqa: E402
43+ from harmonizer .semantic_naming import SemanticNamingEngine # noqa: E402
3844
3945# --- CONFIGURATION LOADING ---
4046
@@ -91,22 +97,27 @@ def __init__(
9197 quiet : bool = False ,
9298 show_semantic_maps : bool = True ,
9399 config : Dict = None ,
100+ suggest_names : bool = False ,
101+ top_suggestions : int = 3 ,
94102 ):
95103 self .config = config if config else {}
96104 self .engine = dive .DivineInvitationSemanticEngine (config = self .config )
97105 self .parser = AST_Semantic_Parser (
98106 vocabulary = self .engine .vocabulary .all_keywords
99107 )
100108 self .map_generator = SemanticMapGenerator ()
109+ self .naming_engine = SemanticNamingEngine ()
101110 self .disharmony_threshold = disharmony_threshold
102111 self .quiet = quiet
103112 self .show_semantic_maps = show_semantic_maps
113+ self .suggest_names = suggest_names
114+ self .top_suggestions = top_suggestions
104115 self ._communicate_startup ()
105116
106117 def _communicate_startup (self ):
107118 if not self .quiet :
108119 print ("=" * 70 )
109- print ("Python Code Harmonizer (v1.4 ) ONLINE" )
120+ print ("Python Code Harmonizer (v1.5 ) ONLINE" )
110121 print ("Actively guided by the Anchor Point framework." )
111122 print (f"Powered By: { self .engine .get_engine_version ()} " )
112123 print ("Logical Anchor Point: (S=1, L=1, I=1, E=1)" )
@@ -235,6 +246,8 @@ def format_report(
235246 lines .append (
236247 self .map_generator .format_text_map (data ["semantic_map" ], score )
237248 )
249+ if self .suggest_names :
250+ lines .append (self ._generate_naming_suggestions (func_name , data ))
238251 if suggest_refactor :
239252 refactorer = Refactorer (
240253 data ["function_node" ], data ["execution_map" ]
@@ -245,12 +258,42 @@ def format_report(
245258 lines .append ("Analysis Complete." )
246259 return "\n " .join (lines )
247260
261+ def _generate_naming_suggestions (self , func_name : str , data : Dict ) -> str :
262+ """Generate naming suggestions based on execution semantics"""
263+ execution_coords = data ["ice_result" ]["ice_components" ]["execution" ].coordinates
264+
265+ # Extract context from function name (e.g., "validate_user" -> "user")
266+ parts = func_name .split ("_" )
267+ context = parts [- 1 ] if len (parts ) > 1 else ""
268+
269+ # Get suggestions
270+ if context :
271+ suggestions = self .naming_engine .suggest_names (
272+ execution_coords , context = context , top_n = self .top_suggestions
273+ )
274+ else :
275+ suggestions = self .naming_engine .suggest_names (
276+ execution_coords , top_n = self .top_suggestions
277+ )
278+
279+ # Format suggestions
280+ lines = ["\n 💡 SUGGESTED FUNCTION NAMES (based on execution semantics):" ]
281+ explanation = self .naming_engine .explain_coordinates (execution_coords )
282+ lines .append (f" { explanation } " )
283+ lines .append (" Suggestions:" )
284+
285+ for name , similarity in suggestions :
286+ percentage = int (similarity * 100 )
287+ lines .append (f" • { name :<30s} (match: { percentage } %)" )
288+
289+ return "\n " .join (lines )
290+
248291 def output_report (self , formatted_report : str ):
249292 print (formatted_report )
250293
251294 def print_json_report (self , all_reports : Dict [str , Dict [str , Dict ]]):
252295 output = {
253- "version" : "1.4 " ,
296+ "version" : "1.5 " ,
254297 "threshold" : self .disharmony_threshold ,
255298 "severity_thresholds" : {
256299 "excellent" : self .THRESHOLD_EXCELLENT ,
@@ -319,7 +362,18 @@ def parse_cli_arguments() -> argparse.Namespace:
319362 help = "Suggest a refactoring for disharmonious functions." ,
320363 )
321364 parser .add_argument (
322- "--version" , action = "version" , version = "Python Code Harmonizer v1.4"
365+ "--suggest-names" ,
366+ action = "store_true" ,
367+ help = "Suggest better function names based on execution semantics." ,
368+ )
369+ parser .add_argument (
370+ "--top-suggestions" ,
371+ type = int ,
372+ default = 3 ,
373+ help = "Number of naming suggestions to show (default: 3)." ,
374+ )
375+ parser .add_argument (
376+ "--version" , action = "version" , version = "Python Code Harmonizer v1.5"
323377 )
324378 return parser .parse_args ()
325379
@@ -383,7 +437,11 @@ def run_cli():
383437
384438 quiet = args .format == "json"
385439 harmonizer = PythonCodeHarmonizer (
386- disharmony_threshold = args .threshold , quiet = quiet , config = config
440+ disharmony_threshold = args .threshold ,
441+ quiet = quiet ,
442+ config = config ,
443+ suggest_names = args .suggest_names ,
444+ top_suggestions = args .top_suggestions ,
387445 )
388446
389447 all_reports , highest_exit_code = execute_analysis (
0 commit comments