Class: Canon::TreeDiff::TreeDiffIntegrator
- Inherits:
-
Object
- Object
- Canon::TreeDiff::TreeDiffIntegrator
- Defined in:
- lib/canon/tree_diff/tree_diff_integrator.rb
Overview
TreeDiffIntegrator provides integration between Canon’s DOM diff system and the new semantic tree diff system.
This class orchestrates:
-
Format-specific adapter selection
-
Tree conversion from parsed documents
-
Tree matching via UniversalMatcher
-
Operation detection
-
Results formatting
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#match_options ⇒ Object
readonly
Returns the value of attribute match_options.
-
#matcher ⇒ Object
readonly
Returns the value of attribute matcher.
Instance Method Summary collapse
-
#diff(doc1, doc2) ⇒ Hash
Perform tree diff on two documents.
-
#equivalent?(doc1, doc2) ⇒ Boolean
Check if two documents are semantically equivalent.
-
#initialize(format:, options: {}) ⇒ TreeDiffIntegrator
constructor
Initialize integrator for a specific format.
Constructor Details
#initialize(format:, options: {}) ⇒ TreeDiffIntegrator
Initialize integrator for a specific format
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/canon/tree_diff/tree_diff_integrator.rb', line 33 def initialize(format:, options: {}) @format = format @options = @match_options = # Store full match options for downstream use # Initialize format-specific adapter WITH match options @adapter = create_adapter(format, ) # Initialize matcher with options = { similarity_threshold: [:similarity_threshold] || 0.95, hash_matching: .fetch(:hash_matching, true), similarity_matching: .fetch(:similarity_matching, true), propagation: .fetch(:propagation, true), attribute_order: [:attribute_order] || :ignore, } @matcher = Matchers::UniversalMatcher.new() end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
21 22 23 |
# File 'lib/canon/tree_diff/tree_diff_integrator.rb', line 21 def adapter @adapter end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
21 22 23 |
# File 'lib/canon/tree_diff/tree_diff_integrator.rb', line 21 def format @format end |
#match_options ⇒ Object (readonly)
Returns the value of attribute match_options.
21 22 23 |
# File 'lib/canon/tree_diff/tree_diff_integrator.rb', line 21 def @match_options end |
#matcher ⇒ Object (readonly)
Returns the value of attribute matcher.
21 22 23 |
# File 'lib/canon/tree_diff/tree_diff_integrator.rb', line 21 def matcher @matcher end |
Instance Method Details
#diff(doc1, doc2) ⇒ Hash
Perform tree diff on two documents
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/canon/tree_diff/tree_diff_integrator.rb', line 57 def diff(doc1, doc2) tree1 = @adapter.to_tree(doc1) tree2 = @adapter.to_tree(doc2) # Filter comment nodes when comments are ignored to prevent # them from disrupting sibling alignment in the matcher if @match_options[:comments] == :ignore filter_comments_from_tree!(tree1) filter_comments_from_tree!(tree2) end check_node_count_limit(tree1) check_node_count_limit(tree2) # Match trees matching = @matcher.match(tree1, tree2) # Detect operations with match_options for proper normalization detector = Operations::OperationDetector.new(tree1, tree2, matching, @match_options) operations = detector.detect # Return comprehensive results { operations: operations, matching: matching, statistics: @matcher.statistics, trees: { tree1: tree1, tree2: tree2 }, } end |
#equivalent?(doc1, doc2) ⇒ Boolean
Check if two documents are semantically equivalent
93 94 95 96 |
# File 'lib/canon/tree_diff/tree_diff_integrator.rb', line 93 def equivalent?(doc1, doc2) result = diff(doc1, doc2) result[:operations].empty? end |