Class: Ast::Merge::CompositeMatchRefiner
- Inherits:
-
Object
- Object
- Ast::Merge::CompositeMatchRefiner
- Defined in:
- lib/ast/merge/composite_match_refiner.rb
Overview
Chains multiple match refiners sequentially.
Each refiner in the pipeline processes the unmatched nodes left over from the previous pass. This allows combining refiners that target different node types or use different scoring strategies (e.g., Levenshtein for paragraphs + Jaccard for comments).
Implements the same #call(template_nodes, dest_nodes, context) interface
as MatchRefinerBase, so it can be passed anywhere a single refiner is accepted.
Instance Attribute Summary collapse
-
#refiners ⇒ Array<#call>
readonly
Ordered list of refiners in the pipeline.
Instance Method Summary collapse
-
#<<(refiner) ⇒ self
Append a refiner to the pipeline.
-
#call(template_nodes, dest_nodes, context = {}) ⇒ Array<MatchRefinerBase::MatchResult>
Run all refiners sequentially.
-
#empty? ⇒ Boolean
Whether this composite has any refiners.
-
#initialize(*refiners) ⇒ CompositeMatchRefiner
constructor
Initialize with zero or more refiners.
-
#size ⇒ Integer
Number of refiners in the pipeline.
Constructor Details
#initialize(*refiners) ⇒ CompositeMatchRefiner
Initialize with zero or more refiners.
35 36 37 |
# File 'lib/ast/merge/composite_match_refiner.rb', line 35 def initialize(*refiners) @refiners = refiners.flatten.compact end |
Instance Attribute Details
#refiners ⇒ Array<#call> (readonly)
Returns Ordered list of refiners in the pipeline.
30 31 32 |
# File 'lib/ast/merge/composite_match_refiner.rb', line 30 def refiners @refiners end |
Instance Method Details
#<<(refiner) ⇒ self
Append a refiner to the pipeline.
43 44 45 46 |
# File 'lib/ast/merge/composite_match_refiner.rb', line 43 def <<(refiner) @refiners << refiner self end |
#call(template_nodes, dest_nodes, context = {}) ⇒ Array<MatchRefinerBase::MatchResult>
Run all refiners sequentially.
Each refiner receives the unmatched nodes remaining after previous refiners have consumed their matches. All matches are accumulated and returned as a single flat array.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/ast/merge/composite_match_refiner.rb', line 58 def call(template_nodes, dest_nodes, context = {}) all_matches = [] remaining_template = template_nodes.dup remaining_dest = dest_nodes.dup refiners.each do |refiner| next if remaining_template.empty? || remaining_dest.empty? matches = Array(refiner.call(remaining_template, remaining_dest, context)) next if matches.empty? matched_template = matches.map(&:template_node) matched_dest = matches.map(&:dest_node) remaining_template -= matched_template remaining_dest -= matched_dest all_matches.concat(matches) end all_matches end |
#empty? ⇒ Boolean
Whether this composite has any refiners.
83 84 85 |
# File 'lib/ast/merge/composite_match_refiner.rb', line 83 def empty? refiners.empty? end |
#size ⇒ Integer
Number of refiners in the pipeline.
90 91 92 |
# File 'lib/ast/merge/composite_match_refiner.rb', line 90 def size refiners.size end |