Class: Canon::TreeDiff::Operations::OperationDetector

Inherits:
Object
  • Object
show all
Defined in:
lib/canon/tree_diff/operations/operation_detector.rb

Overview

OperationDetector analyzes tree matching results to detect high-level semantic operations.

Based on research from XDiff, XyDiff, and JATS-diff, this detector identifies operations in three levels:

Level 1: Basic operations (INSERT, DELETE, UPDATE) Level 2: Structural operations (MOVE) Level 3: Semantic operations (MERGE, SPLIT, UPGRADE, DOWNGRADE)

Examples:

detector = OperationDetector.new(tree1, tree2, matching)
operations = detector.detect
operations.each { |op| puts op.inspect }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tree1, tree2, matching, match_options = {}) ⇒ OperationDetector

Initialize a new operation detector

Parameters:

  • tree1 (TreeNode)

    First tree root

  • tree2 (TreeNode)

    Second tree root

  • matching (Matching)

    Matching between trees

  • match_options (Hash) (defaults to: {})

    Match options for comparison



32
33
34
35
36
37
38
# File 'lib/canon/tree_diff/operations/operation_detector.rb', line 32

def initialize(tree1, tree2, matching, match_options = {})
  @tree1 = tree1
  @tree2 = tree2
  @matching = matching
  @match_options = match_options || {}
  @operations = []
end

Instance Attribute Details

#match_optionsObject (readonly)

Returns the value of attribute match_options.



24
25
26
# File 'lib/canon/tree_diff/operations/operation_detector.rb', line 24

def match_options
  @match_options
end

#matchingObject (readonly)

Returns the value of attribute matching.



24
25
26
# File 'lib/canon/tree_diff/operations/operation_detector.rb', line 24

def matching
  @matching
end

#operationsObject (readonly)

Returns the value of attribute operations.



24
25
26
# File 'lib/canon/tree_diff/operations/operation_detector.rb', line 24

def operations
  @operations
end

#tree1Object (readonly)

Returns the value of attribute tree1.



24
25
26
# File 'lib/canon/tree_diff/operations/operation_detector.rb', line 24

def tree1
  @tree1
end

#tree2Object (readonly)

Returns the value of attribute tree2.



24
25
26
# File 'lib/canon/tree_diff/operations/operation_detector.rb', line 24

def tree2
  @tree2
end

Instance Method Details

#detectArray<Operation>

Detect all operations

Returns:



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/canon/tree_diff/operations/operation_detector.rb', line 43

def detect
  @operations = []

  # Level 1: Basic operations
  detect_inserts
  detect_deletes
  detect_updates

  # Level 2: Structural operations
  detect_moves

  # Level 3: Semantic operations
  # These require more sophisticated pattern analysis
  detect_merges
  detect_splits
  detect_upgrades
  detect_downgrades

  @operations
end