Class: Prism::Merge::MethodMatchRefiner
- Inherits:
-
Ast::Merge::MatchRefinerBase
- Object
- Ast::Merge::MatchRefinerBase
- Prism::Merge::MethodMatchRefiner
- Defined in:
- lib/prism/merge/method_match_refiner.rb
Overview
Match refiner for Ruby methods that didn't match by exact signature.
This refiner uses fuzzy matching to pair methods that have:
- Similar names (e.g.,
process_uservsprocess_users) - Same name but different parameter signatures
- Renamed methods that perform similar functions
The matching algorithm considers:
- Method name similarity (Levenshtein distance)
- Parameter count and name similarity
- Method body similarity (optional, for high-confidence matches)
Constant Summary collapse
- DEFAULT_NAME_WEIGHT =
Default weight for method name similarity
Ruby::Merge::MethodSimilarity::DEFAULT_NAME_WEIGHT
- DEFAULT_PARAMS_WEIGHT =
Default weight for parameter similarity
Ruby::Merge::MethodSimilarity::DEFAULT_PARAMS_WEIGHT
Instance Attribute Summary collapse
-
#name_weight ⇒ Float
readonly
Weight for name similarity (0.0-1.0).
-
#params_weight ⇒ Float
readonly
Weight for parameter similarity (0.0-1.0).
Instance Method Summary collapse
-
#call(template_nodes, dest_nodes, _context = {}) ⇒ Array<MatchResult>
Find matches between unmatched method definitions.
-
#initialize(threshold: DEFAULT_THRESHOLD, name_weight: DEFAULT_NAME_WEIGHT, params_weight: DEFAULT_PARAMS_WEIGHT, **options) ⇒ MethodMatchRefiner
constructor
Initialize a method match refiner.
Constructor Details
#initialize(threshold: DEFAULT_THRESHOLD, name_weight: DEFAULT_NAME_WEIGHT, params_weight: DEFAULT_PARAMS_WEIGHT, **options) ⇒ MethodMatchRefiner
Initialize a method match refiner.
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/prism/merge/method_match_refiner.rb', line 47 def initialize(threshold: DEFAULT_THRESHOLD, name_weight: DEFAULT_NAME_WEIGHT, params_weight: DEFAULT_PARAMS_WEIGHT, **) super(threshold: threshold, node_types: [:def], **) @name_weight = name_weight @params_weight = params_weight @method_similarity = Ruby::Merge::MethodSimilarity.new( name_weight: name_weight, params_weight: params_weight ) end |
Instance Attribute Details
#name_weight ⇒ Float (readonly)
Returns Weight for name similarity (0.0-1.0).
37 38 39 |
# File 'lib/prism/merge/method_match_refiner.rb', line 37 def name_weight @name_weight end |
#params_weight ⇒ Float (readonly)
Returns Weight for parameter similarity (0.0-1.0).
40 41 42 |
# File 'lib/prism/merge/method_match_refiner.rb', line 40 def params_weight @params_weight end |
Instance Method Details
#call(template_nodes, dest_nodes, _context = {}) ⇒ Array<MatchResult>
Find matches between unmatched method definitions.
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/prism/merge/method_match_refiner.rb', line 64 def call(template_nodes, dest_nodes, _context = {}) template_methods = template_nodes.select { |n| method_node?(n) } dest_methods = dest_nodes.select { |n| method_node?(n) } return [] if template_methods.empty? || dest_methods.empty? greedy_match(template_methods, dest_methods) do |t_node, d_node| compute_method_similarity(t_node, d_node) end end |