Class: Json::Merge::ObjectMatchRefiner
- Inherits:
-
Ast::Merge::MatchRefinerBase
- Object
- Ast::Merge::MatchRefinerBase
- Json::Merge::ObjectMatchRefiner
- Defined in:
- lib/json/merge/object_match_refiner.rb
Overview
Match refiner for JSON objects and array elements that didn’t match by exact signature.
This refiner uses fuzzy matching to pair JSON nodes that have:
- Similar key names in objects (e.g.,
databaseUrlvsdatabase_url) - Array elements with similar structure or content
- Objects with overlapping keys but different values
The matching algorithm considers:
- Key name similarity for object pairs (Levenshtein distance)
- Value type and content similarity
- Structural overlap for nested objects
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 JSON nodes.
-
#initialize(threshold: DEFAULT_THRESHOLD, key_weight: DEFAULT_KEY_WEIGHT, value_weight: DEFAULT_VALUE_WEIGHT, **options) ⇒ ObjectMatchRefiner
constructor
Initialize an object match refiner.
Constructor Details
#initialize(threshold: DEFAULT_THRESHOLD, key_weight: DEFAULT_KEY_WEIGHT, value_weight: DEFAULT_VALUE_WEIGHT, **options) ⇒ ObjectMatchRefiner
Initialize an object match refiner.
47 48 49 50 51 |
# File 'lib/json/merge/object_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/json/merge/object_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/json/merge/object_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 JSON nodes.
Handles both object key-value pairs and array elements.
61 62 63 64 65 66 67 68 69 |
# File 'lib/json/merge/object_match_refiner.rb', line 61 def call(template_nodes, dest_nodes, context = {}) # Match object pairs (key-value entries) pair_matches = match_pairs(template_nodes, dest_nodes) # Match array elements (objects within arrays) array_matches = match_array_objects(template_nodes, dest_nodes) pair_matches + array_matches end |