broadfield-dev commited on
Commit
4fa7df9
·
verified ·
1 Parent(s): a4421ce

Update parser.py

Browse files
Files changed (1) hide show
  1. parser.py +17 -0
parser.py CHANGED
@@ -50,6 +50,23 @@ def is_blank_or_comment(line):
50
  stripped = line.strip()
51
  return not stripped or stripped.startswith('#')
52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
 
54
  def collect_variable_usage(tree):
55
  """Collect definitions and uses of variables, respecting scope."""
 
50
  stripped = line.strip()
51
  return not stripped or stripped.startswith('#')
52
 
53
+ def create_vector(category, level, location, total_lines, parent_path):
54
+ """Create a 6D vector optimized for role similarity, integrating variable roles into category_id."""
55
+ category_map = {
56
+ 'import': 1, 'function': 2, 'async_function': 3, 'class': 4,
57
+ 'if': 5, 'while': 6, 'for': 7, 'try': 8, 'expression': 9, 'spacer': 10,
58
+ 'other': 11, 'elif': 12, 'else': 13, 'except': 14, 'finally': 15, 'return': 16,
59
+ 'assigned_variable': 17, 'input_variable': 18, 'returned_variable': 19
60
+ }
61
+ category_id = category_map.get(category, 0) # Default to 0 for unknown categories
62
+ start_line, end_line = location
63
+ span = (end_line - start_line + 1) / total_lines
64
+ center_pos = ((start_line + end_line) / 2) / total_lines
65
+ parent_depth = len(parent_path)
66
+ parent_weight = sum(category_map.get(parent.split('[')[0].lower(), 0) * (1 / (i + 1))
67
+ for i, parent in enumerate(parent_path)) / max(1, len(category_map))
68
+ return [category_id, level, center_pos, span, parent_depth, parent_weight]
69
+
70
 
71
  def collect_variable_usage(tree):
72
  """Collect definitions and uses of variables, respecting scope."""