Class: Lutaml::Qea::Verification::ComparisonResult
- Inherits:
-
Object
- Object
- Lutaml::Qea::Verification::ComparisonResult
- Defined in:
- lib/lutaml/qea/verification/comparison_result.rb
Overview
Holds comparison results between XMI and QEA documents
Instance Attribute Summary collapse
-
#differences ⇒ Object
readonly
Returns the value of attribute differences.
-
#matches ⇒ Object
readonly
Returns the value of attribute matches.
-
#property_differences ⇒ Object
readonly
Returns the value of attribute property_differences.
-
#qea_only ⇒ Object
readonly
Returns the value of attribute qea_only.
-
#xmi_only ⇒ Object
readonly
Returns the value of attribute xmi_only.
Instance Method Summary collapse
-
#acceptable_differences ⇒ Array<String>
Get acceptable differences (QEA has more).
-
#add_difference(description) ⇒ Object
Record a difference.
-
#add_matches(type, count) ⇒ Object
Record matched elements.
-
#add_property_difference(element_type, element_name, differences) ⇒ Object
Record property-level difference.
-
#add_qea_only(type, elements) ⇒ Object
Record QEA-only elements.
-
#add_xmi_only(type, elements) ⇒ Object
Record XMI-only elements.
-
#critical_issues ⇒ Array<String>
Get critical issues (information loss).
-
#equivalent? ⇒ Boolean
Check if documents are equivalent QEA is considered equivalent if it has >= information compared to XMI.
-
#has_issues? ⇒ Boolean
Check if there are any issues.
-
#initialize ⇒ ComparisonResult
constructor
rubocop:disable Metrics/MethodLength.
-
#statistics ⇒ Hash
Generate statistics.
-
#summary ⇒ String
Generate human-readable summary.
-
#to_report ⇒ Hash
Generate detailed report.
Constructor Details
#initialize ⇒ ComparisonResult
rubocop:disable Metrics/MethodLength
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/lutaml/qea/verification/comparison_result.rb', line 11 def initialize # rubocop:disable Metrics/MethodLength @matches = { packages: 0, classes: 0, enums: 0, data_types: 0, associations: 0, attributes: 0, operations: 0, } @differences = [] @xmi_only = { packages: [], classes: [], enums: [], data_types: [], associations: [], } @qea_only = { packages: [], classes: [], enums: [], data_types: [], associations: [], } @property_differences = [] end |
Instance Attribute Details
#differences ⇒ Object (readonly)
Returns the value of attribute differences.
8 9 10 |
# File 'lib/lutaml/qea/verification/comparison_result.rb', line 8 def differences @differences end |
#matches ⇒ Object (readonly)
Returns the value of attribute matches.
8 9 10 |
# File 'lib/lutaml/qea/verification/comparison_result.rb', line 8 def matches @matches end |
#property_differences ⇒ Object (readonly)
Returns the value of attribute property_differences.
8 9 10 |
# File 'lib/lutaml/qea/verification/comparison_result.rb', line 8 def property_differences @property_differences end |
#qea_only ⇒ Object (readonly)
Returns the value of attribute qea_only.
8 9 10 |
# File 'lib/lutaml/qea/verification/comparison_result.rb', line 8 def qea_only @qea_only end |
#xmi_only ⇒ Object (readonly)
Returns the value of attribute xmi_only.
8 9 10 |
# File 'lib/lutaml/qea/verification/comparison_result.rb', line 8 def xmi_only @xmi_only end |
Instance Method Details
#acceptable_differences ⇒ Array<String>
Get acceptable differences (QEA has more)
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
# File 'lib/lutaml/qea/verification/comparison_result.rb', line 240 def acceptable_differences # rubocop:disable Metrics/MethodLength acceptable = [] # QEA-only elements qea_only.each do |type, elements| next if elements.empty? acceptable << "QEA has #{elements.size} additional #{type}" end # Property differences where QEA has more property_differences.each do |diff| diff[:differences].each do |d| next unless d.include?("QEA has more") acceptable << "#{diff[:name]}: #{d}" end end acceptable end |
#add_difference(description) ⇒ Object
Record a difference
66 67 68 |
# File 'lib/lutaml/qea/verification/comparison_result.rb', line 66 def add_difference(description) @differences << description end |
#add_matches(type, count) ⇒ Object
Record matched elements
43 44 45 |
# File 'lib/lutaml/qea/verification/comparison_result.rb', line 43 def add_matches(type, count) @matches[type] = count end |
#add_property_difference(element_type, element_name, differences) ⇒ Object
Record property-level difference
75 76 77 78 79 80 81 |
# File 'lib/lutaml/qea/verification/comparison_result.rb', line 75 def add_property_difference(element_type, element_name, differences) @property_differences << { type: element_type, name: element_name, differences: differences, } end |
#add_qea_only(type, elements) ⇒ Object
Record QEA-only elements
59 60 61 |
# File 'lib/lutaml/qea/verification/comparison_result.rb', line 59 def add_qea_only(type, elements) @qea_only[type] = elements end |
#add_xmi_only(type, elements) ⇒ Object
Record XMI-only elements
51 52 53 |
# File 'lib/lutaml/qea/verification/comparison_result.rb', line 51 def add_xmi_only(type, elements) @xmi_only[type] = elements end |
#critical_issues ⇒ Array<String>
Get critical issues (information loss)
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/lutaml/qea/verification/comparison_result.rb', line 212 def critical_issues # rubocop:disable Metrics/AbcSize,Metrics/MethodLength issues = [] # Missing packages if xmi_only[:packages].any? issues << "Missing #{xmi_only[:packages].size} packages in QEA" end # Missing classes if xmi_only[:classes].any? issues << "Missing #{xmi_only[:classes].size} classes in QEA" end # Property differences with information loss property_differences.each do |diff| diff[:differences].each do |d| next unless d.include?("QEA has fewer") issues << "#{diff[:name]}: #{d}" end end issues end |
#equivalent? ⇒ Boolean
Check if documents are equivalent QEA is considered equivalent if it has >= information compared to XMI
87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/lutaml/qea/verification/comparison_result.rb', line 87 def equivalent? # No critical XMI-only elements (some are acceptable) critical_xmi_only = xmi_only[:classes].any? || xmi_only[:packages].any? # No property differences that indicate information loss critical_property_diffs = property_differences.any? do |diff| diff[:differences].any? { |d| d.include?("QEA has fewer") } end !critical_xmi_only && !critical_property_diffs end |
#has_issues? ⇒ Boolean
Check if there are any issues
205 206 207 |
# File 'lib/lutaml/qea/verification/comparison_result.rb', line 205 def has_issues? !equivalent? end |
#statistics ⇒ Hash
Generate statistics
192 193 194 195 196 197 198 199 200 |
# File 'lib/lutaml/qea/verification/comparison_result.rb', line 192 def statistics { total_matches: matches.values.sum, total_xmi_only: xmi_only.values.sum(&:size), total_qea_only: qea_only.values.sum(&:size), total_property_diffs: property_differences.size, equivalent: equivalent?, } end |
#summary ⇒ String
Generate human-readable summary
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/lutaml/qea/verification/comparison_result.rb', line 103 def summary # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity lines = [] lines << "=== Verification Summary ===" lines << "" # Matches lines << "Matched Elements:" matches.each do |type, count| next if count.zero? lines << " ✓ #{type.to_s.capitalize}: #{count}" end lines << "" # XMI-only elements if xmi_only.values.any?(&:any?) lines << "XMI-Only Elements (missing in QEA):" xmi_only.each do |type, elements| next if elements.empty? lines << " ✗ #{type.to_s.capitalize}: #{elements.size}" elements.first(5).each do |elem| lines << " - #{elem}" end if elements.size > 5 lines << " ... and #{elements.size - 5} more" end end lines << "" end # QEA-only elements (acceptable, shows QEA richness) if qea_only.values.any?(&:any?) lines << "QEA-Only Elements (additional in QEA - acceptable):" qea_only.each do |type, elements| next if elements.empty? lines << " + #{type.to_s.capitalize}: #{elements.size}" end lines << "" end # Property differences if property_differences.any? lines << "Property Differences:" property_differences.first(10).each do |diff| lines << " #{diff[:type]}: #{diff[:name]}" diff[:differences].each do |d| lines << " - #{d}" end end if property_differences.size > 10 lines << " ... and #{property_differences.size - 10} more" end lines << "" end # Result lines << "Result: " \ "#{equivalent? ? '✓ EQUIVALENT' : '✗ NOT EQUIVALENT'}" lines << "" lines << if equivalent? "QEA contains all XMI information (possibly more)." else "Information loss detected - " \ "QEA missing critical elements." end lines.join("\n") end |
#to_report ⇒ Hash
Generate detailed report
178 179 180 181 182 183 184 185 186 187 |
# File 'lib/lutaml/qea/verification/comparison_result.rb', line 178 def to_report { equivalent: equivalent?, matches: matches, xmi_only: xmi_only, qea_only: qea_only, property_differences: property_differences, summary: summary, } end |