Class: Psych::Merge::MappingMatchRefiner
- Inherits:
-
Ast::Merge::MatchRefinerBase
- Object
- Ast::Merge::MatchRefinerBase
- Psych::Merge::MappingMatchRefiner
- Defined in:
- lib/psych/merge/mapping_match_refiner.rb
Overview
Match refiner for YAML mapping entries that didn’t match by exact signature.
This refiner uses fuzzy matching to pair mapping entries (key-value pairs) that have:
- Similar keys (e.g.,
database_urlvsdb_url) - Keys with typos or naming convention differences
- Renamed keys that contain similar values
The matching algorithm considers:
- Key name similarity (Levenshtein distance)
- Value type similarity (both scalars, both mappings, etc.)
- Value content similarity for scalars
Constant Summary collapse
- DEFAULT_KEY_WEIGHT =
Default weight for key similarity
0.7- DEFAULT_VALUE_WEIGHT =
Default weight for value similarity
0.3
Instance Attribute Summary collapse
-
#key_weight ⇒ Float
readonly
Weight for key similarity (0.0-1.0).
-
#value_weight ⇒ Float
readonly
Weight for value similarity (0.0-1.0).
Instance Method Summary collapse
-
#call(template_nodes, dest_nodes, context = {}) ⇒ Array<MatchResult>
Find matches between unmatched mapping entries.
-
#initialize(threshold: DEFAULT_THRESHOLD, key_weight: DEFAULT_KEY_WEIGHT, value_weight: DEFAULT_VALUE_WEIGHT, **options) ⇒ MappingMatchRefiner
constructor
Initialize a mapping match refiner.
Constructor Details
#initialize(threshold: DEFAULT_THRESHOLD, key_weight: DEFAULT_KEY_WEIGHT, value_weight: DEFAULT_VALUE_WEIGHT, **options) ⇒ MappingMatchRefiner
Initialize a mapping match refiner.
47 48 49 50 51 |
# File 'lib/psych/merge/mapping_match_refiner.rb', line 47 def initialize(threshold: DEFAULT_THRESHOLD, key_weight: DEFAULT_KEY_WEIGHT, value_weight: DEFAULT_VALUE_WEIGHT, **) super(threshold: threshold, **) @key_weight = key_weight @value_weight = value_weight end |
Instance Attribute Details
#key_weight ⇒ Float (readonly)
Returns Weight for key similarity (0.0-1.0).
37 38 39 |
# File 'lib/psych/merge/mapping_match_refiner.rb', line 37 def key_weight @key_weight end |
#value_weight ⇒ Float (readonly)
Returns Weight for value similarity (0.0-1.0).
40 41 42 |
# File 'lib/psych/merge/mapping_match_refiner.rb', line 40 def value_weight @value_weight end |
Instance Method Details
#call(template_nodes, dest_nodes, context = {}) ⇒ Array<MatchResult>
Find matches between unmatched mapping entries.
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/psych/merge/mapping_match_refiner.rb', line 59 def call(template_nodes, dest_nodes, context = {}) template_entries = template_nodes.select { |n| mapping_entry?(n) } dest_entries = dest_nodes.select { |n| mapping_entry?(n) } return [] if template_entries.empty? || dest_entries.empty? greedy_match(template_entries, dest_entries) do |t_node, d_node| compute_entry_similarity(t_node, d_node) end end |