Class: Ast::Merge::MatchRefinerBase
- Inherits:
-
Object
- Object
- Ast::Merge::MatchRefinerBase
- Defined in:
- lib/ast/merge/match_refiner_base.rb
Overview
Base class for match refiners that pair unmatched nodes after signature matching.
Match refiners run after initial signature-based matching to find additional pairings between nodes that didn’t match by signature. This is useful when you want more nuanced matching than exact signatures provide - for example, matching tables with similar (but not identical) headers, or finding the closest match among several candidates using multi-factor scoring.
By default, most node types use content-based signatures (including tables, which match on row count + header content). Refiners let you override this to implement fuzzy matching, positional matching, or any custom logic.
Refiners use a callable interface (‘#call`) so simple lambdas/procs can also be used where a full class isn’t needed.
Defined Under Namespace
Classes: MatchResult
Constant Summary collapse
- DEFAULT_THRESHOLD =
Default minimum score threshold for accepting a match
0.5
Instance Attribute Summary collapse
-
#node_types ⇒ Array<Symbol>
readonly
Node types this refiner handles (empty = all types).
-
#threshold ⇒ Float
readonly
Minimum score to accept a match.
Instance Method Summary collapse
-
#call(template_nodes, dest_nodes, context = {}) ⇒ Array<MatchResult>
Refine matches between unmatched template and destination nodes.
-
#handles_type?(node_type) ⇒ Boolean
Check if this refiner handles a given node type.
-
#initialize(threshold: DEFAULT_THRESHOLD, node_types: []) ⇒ MatchRefinerBase
constructor
Initialize a new match refiner.
Constructor Details
#initialize(threshold: DEFAULT_THRESHOLD, node_types: []) ⇒ MatchRefinerBase
Initialize a new match refiner.
171 172 173 174 |
# File 'lib/ast/merge/match_refiner_base.rb', line 171 def initialize(threshold: DEFAULT_THRESHOLD, node_types: []) @threshold = [[threshold.to_f, 0.0].max, 1.0].min @node_types = Array(node_types) end |
Instance Attribute Details
#node_types ⇒ Array<Symbol> (readonly)
Returns Node types this refiner handles (empty = all types).
165 166 167 |
# File 'lib/ast/merge/match_refiner_base.rb', line 165 def node_types @node_types end |
#threshold ⇒ Float (readonly)
Returns Minimum score to accept a match.
162 163 164 |
# File 'lib/ast/merge/match_refiner_base.rb', line 162 def threshold @threshold end |
Instance Method Details
#call(template_nodes, dest_nodes, context = {}) ⇒ Array<MatchResult>
Refine matches between unmatched template and destination nodes.
This is the main entry point. Override in subclasses to implement custom matching logic.
186 187 188 |
# File 'lib/ast/merge/match_refiner_base.rb', line 186 def call(template_nodes, dest_nodes, context = {}) raise NotImplementedError, "#{self.class}#call must be implemented" end |
#handles_type?(node_type) ⇒ Boolean
Check if this refiner handles a given node type.
194 195 196 |
# File 'lib/ast/merge/match_refiner_base.rb', line 194 def handles_type?(node_type) node_types.empty? || node_types.include?(node_type) end |