ea 0.6.148 → 0.6.149

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d2395d5ef03b627d02de55c09f65eff28984a512919ed75b39d8b1cbe110dc20
4
- data.tar.gz: ff25b771f4134f453882054a6921eba3e0ffbbb2fe07347292ffdb1ade43e9b2
3
+ metadata.gz: d143a80d034a606fa2dedae83b531d86efdb32c2787fdf23c2cf964c8a234329
4
+ data.tar.gz: d385a7270b77210a912b6a176d3d2dfc0a8c28b0cc109b09b1f9516bd95746c3
5
5
  SHA512:
6
- metadata.gz: 3c0e61969712ad88fc8d9ccc9da3a034ce5877f880738271935a192eff7219d15927f609134b1f6d956f2abb15d9191492bddf14085372068b1b3bb9544d37fe
7
- data.tar.gz: fa6306f9f66d3e3192c921127710d365f3a53a64fac9a3498011a9f7c0c632ccb04c8777a5da45bbc78386fc0ba8f8cad18f7c3e5d6fa9597bd4b147cb2391e9
6
+ metadata.gz: 84270956322f9417de60234cb5ab7b0f3150c98452c2398eb50f5d08788030f4a05ec01ea2811afac143ba2d7ae71fe5814e731fa0d2d7ee58b385bfa753090f
7
+ data.tar.gz: 5acca009a511334a1a2b9cd027877bf59e3dfc3715b61b5f5079e2800126c16c02bc961567ba6ef304f91b4a8fd8720c083d55f6e1ca4feeee695a753e1cc4ce
@@ -62,12 +62,19 @@ module Ea
62
62
  def build_enum_value(ea_attr)
63
63
  Lutaml::Uml::Value.new.tap do |value|
64
64
  value.name = ea_attr.name
65
+ value.initial = present_text(ea_attr.default)
65
66
  value.id = normalize_guid_to_xmi_format(ea_attr.ea_guid, "EAID")
66
- value.definition = ea_attr.notes unless
67
- ea_attr.notes.nil? || ea_attr.notes.empty?
67
+ value.definition = present_text(ea_attr.notes)
68
68
  end
69
69
  end
70
70
 
71
+ # @return [String, nil] the text when non-blank, otherwise nil
72
+ def present_text(text)
73
+ return nil if text.nil? || text.empty?
74
+
75
+ text
76
+ end
77
+
71
78
  end
72
79
  end
73
80
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "json"
4
+ require "yaml"
4
5
 
5
6
  module Ea
6
7
  module Svg
@@ -35,8 +36,41 @@ module Ea
35
36
  result
36
37
  end
37
38
 
39
+ # YAML uses plain string keys so gate consumers can safe-load it.
40
+ # Include clean diagrams with zero counts; omit unreferenced diagrams
41
+ # exactly as Suite does. Counts use Suite's default tolerances.
42
+ def run_baseline(output_path:, io: $stdout)
43
+ suite = Suite.new(document, ref_dir).measure
44
+ rows = baseline_rows(suite)
45
+ result = { "totals" => baseline_totals(rows), "diagrams" => rows }
46
+ File.write(output_path, YAML.dump(result))
47
+ print_baseline(suite, rows, io)
48
+ result
49
+ end
50
+
38
51
  private
39
52
 
53
+ def baseline_rows(suite)
54
+ suite.per_diagram.map do |diagram|
55
+ { "id" => diagram.id, "name" => diagram.name,
56
+ "deltas" => diagram.delta_summary.transform_keys(&:to_s) }
57
+ end
58
+ end
59
+
60
+ def baseline_totals(rows)
61
+ rows.each_with_object(Hash.new(0)) do |row, sum|
62
+ row.fetch("deltas").each { |key, count| sum[key] += count }
63
+ end
64
+ end
65
+
66
+ def print_baseline(suite, rows, io)
67
+ io.puts "Diagrams: #{suite.total} (failures: #{suite.failures.size})"
68
+ rows.each do |row|
69
+ deltas = row.fetch("deltas").map { |key, count| "#{key}=#{count}" }.join(" ")
70
+ io.puts " #{row.fetch("id")} (#{row.fetch("name")}): #{deltas}"
71
+ end
72
+ end
73
+
40
74
  def diagrams_with_references
41
75
  document.diagrams.select { |d| reference_path_for(d) }
42
76
  end
@@ -45,7 +79,7 @@ module Ea
45
79
  # fall back to the raw diagram id for non-QEA sources.
46
80
  def reference_path_for(diagram)
47
81
  [
48
- File.join(ref_dir, "EAID_#{diagram.id.tr('-', '_')}.svg"),
82
+ File.join(ref_dir, "EAID_#{diagram.id.tr("-", "_")}.svg"),
49
83
  File.join(ref_dir, "#{Ea::Sources::Qea::IdNormalizer.to_eaid(diagram.id)}.svg"),
50
84
  File.join(ref_dir, "#{diagram.id}.svg")
51
85
  ].find { |p| File.exist?(p) }
@@ -55,9 +89,7 @@ module Ea
55
89
  ref_path = reference_path_for(diagram)
56
90
  return nil unless ref_path
57
91
 
58
- ours = Ea::Svg::EaEmitter::Document.new(
59
- diagram, model_index: index, document: document
60
- ).render
92
+ ours = render_diagram(diagram, index)
61
93
  differ = Differ.new(ours: ours, reference: File.read(ref_path))
62
94
  deltas = differ.text_deltas
63
95
 
@@ -68,6 +100,12 @@ module Ea
68
100
  }
69
101
  end
70
102
 
103
+ def render_diagram(diagram, index)
104
+ Ea::Svg::EaEmitter::Document.new(
105
+ diagram, model_index: index, document: document
106
+ ).render
107
+ end
108
+
71
109
  def totals(rows)
72
110
  sum = DELTA_KEYS.to_h { |k| [k, 0] }
73
111
  shapes = { matched: 0, missing: 0, extra: 0 }
@@ -5,12 +5,14 @@ require "nokogiri"
5
5
  module Ea
6
6
  module Svg
7
7
  module Parity
8
- # Drives Parity::Checker across every diagram in a Document
8
+ # Drives Checker and Differ across every diagram in a Document
9
9
  # that has a matching reference SVG. Drives from any source
10
10
  # the Document supports (qea or xmi) since the Document is
11
11
  # format-agnostic.
12
12
  class Suite
13
13
  ELEMENT_TYPES = %i[rect polygon path text].freeze
14
+ TEXT_DELTAS = %i[moved_text missing_text extra_text wrong_font wrong_size wrong_weight].freeze
15
+ GEOMETRY_DELTAS = %i[dx dy dwidth dheight max_point_delta].freeze
14
16
 
15
17
  attr_reader :document, :ref_dir
16
18
 
@@ -47,10 +49,54 @@ module Ea
47
49
  document: document).render
48
50
  reference = File.read(ref_path)
49
51
  checker = Checker.new(ours: ours, reference: reference)
50
- DiagramReport.new(diagram: diagram, report: checker.report)
52
+ DiagramReport.new(diagram: diagram, report: checker.report,
53
+ differ: Differ.new(ours: ours, reference: reference))
51
54
  end
52
55
 
53
- DiagramReport = Struct.new(:diagram, :report, keyword_init: true) do
56
+ # Epsilon applies to measured geometry; text/font mismatches retain
57
+ # Differ's classification (including its text movement threshold).
58
+ Tolerances = Data.define(:epsilon) do
59
+ def initialize(epsilon: Differ::EPSILON)
60
+ raise ArgumentError, "epsilon must be finite and non-negative" unless epsilon.finite? && epsilon >= 0
61
+
62
+ super
63
+ end
64
+ end
65
+
66
+ DiagramReport = Struct.new(:diagram, :report, :differ, keyword_init: true) do
67
+ def delta_summary(tolerances = Tolerances.new)
68
+ texts = differ.text_deltas
69
+ TEXT_DELTAS.to_h { |key| [key, texts[key].size] }.merge(
70
+ missing_shapes: differ.shape_summary[:missing],
71
+ extra_shapes: differ.shape_summary[:extra],
72
+ shape_geometry: geometry_count(tolerances),
73
+ **connector_summary(tolerances)
74
+ )
75
+ end
76
+
77
+ def clean?(tolerances = Tolerances.new)
78
+ delta_summary(tolerances).values.all?(&:zero?)
79
+ end
80
+
81
+ def geometry_count(tolerances)
82
+ differ.shape_deltas.count do |delta|
83
+ delta.slice(*GEOMETRY_DELTAS).values.any? { |value| value.abs > tolerances.epsilon }
84
+ end
85
+ end
86
+ private :geometry_count
87
+
88
+ def connector_summary(tolerances)
89
+ deltas = differ.connector_deltas
90
+ {
91
+ source_endpoints: deltas.count { |delta| delta[:source_delta] > tolerances.epsilon },
92
+ target_endpoints: deltas.count { |delta| delta[:target_delta] > tolerances.epsilon },
93
+ arrowhead_tips: deltas.sum do |delta|
94
+ delta[:arrowhead_deltas].count { |head| head[:tip_delta] > tolerances.epsilon }
95
+ end
96
+ }
97
+ end
98
+ private :connector_summary
99
+
54
100
  def id
55
101
  diagram.id
56
102
  end
@@ -64,6 +110,7 @@ module Ea
64
110
  end
65
111
  end
66
112
 
113
+ # Collects diagram results and aggregates counts across the suite.
67
114
  class Report
68
115
  attr_reader :per_diagram
69
116
 
@@ -71,6 +118,10 @@ module Ea
71
118
  @per_diagram = per_diagram
72
119
  end
73
120
 
121
+ def failures(tolerances = Tolerances.new)
122
+ per_diagram.reject { |diagram| diagram.clean?(tolerances) }
123
+ end
124
+
74
125
  def total
75
126
  per_diagram.size
76
127
  end
@@ -80,19 +131,12 @@ module Ea
80
131
  end
81
132
 
82
133
  def aggregate_shape_counts
83
- ours = { rect: 0, polygon: 0, path: 0, text: 0 }
84
- ref = { rect: 0, polygon: 0, path: 0, text: 0 }
85
- per_diagram.each do |dr|
86
- ours[:rect] += dr.report.rect.ours
87
- ours[:polygon] += dr.report.polygon.ours
88
- ours[:path] += dr.report.path.ours
89
- ours[:text] += dr.report.text.ours
90
- ref[:rect] += dr.report.rect.reference
91
- ref[:polygon] += dr.report.polygon.reference
92
- ref[:path] += dr.report.path.reference
93
- ref[:text] += dr.report.text.reference
134
+ %i[ours reference].to_h do |side|
135
+ counts = ELEMENT_TYPES.to_h do |type|
136
+ [type, per_diagram.sum { |dr| dr.report.public_send(type).public_send(side) }]
137
+ end
138
+ [side, counts]
94
139
  end
95
- { ours: ours, reference: ref }
96
140
  end
97
141
 
98
142
  def text_overlap_avg
data/lib/ea/version.rb CHANGED
@@ -4,5 +4,5 @@ module Ea
4
4
  # Gem release version. Extracted to its own file so the
5
5
  # `gem-release` tool's `gem bump` can find and update it via the
6
6
  # standard `lib/<gem>/version.rb` convention.
7
- VERSION = "0.6.148"
7
+ VERSION = "0.6.149"
8
8
  end
data/lib/ea/xmi/parser.rb CHANGED
@@ -601,6 +601,8 @@ module Ea
601
601
 
602
602
  ::Lutaml::Uml::Value.new.tap do |value|
603
603
  value.name = owned_literal.name
604
+ ext_attr = fetch_attribute_node(owned_literal.id)
605
+ value.initial = ext_attr.initial if ext_attr&.initial
604
606
  value.type = lookup_entity_name(uml_type_id) || uml_type_id
605
607
  value.definition = lookup_attribute_documentation(owned_literal.id)
606
608
  end
@@ -3,85 +3,105 @@
3
3
  require "ea"
4
4
  require "ea/svg/parity"
5
5
 
6
- namespace :svg do
7
- desc "Score rendered SVG against EA reference SVGs (SOURCE.xmi or .qea + REF_DIR)"
8
- task :bench, %i[source ref_dir tolerance] do |_t, args|
9
- source = args[:source] || ENV["EA_BENCH_SOURCE"] ||
10
- File.expand_path("~/src/mn/mn-samples-plateau/sources/xmi/plateau_all_packages_export.xmi")
11
- ref_dir = args[:ref_dir] || ENV["EA_BENCH_REF_DIR"] ||
12
- File.expand_path("~/src/mn/mn-samples-plateau/sources/001-mds/xmi-images")
13
- tolerance = (args[:tolerance] || ENV["EA_BENCH_TOLERANCE"] || "5").to_i
14
-
15
- abort "source not found: #{source}" unless File.exist?(source)
16
- abort "ref_dir not found: #{ref_dir}" unless Dir.exist?(ref_dir)
17
-
18
- doc = Ea::Svg::Parity::Source.new(source).load
19
- suite = Ea::Svg::Parity::Suite.new(doc, ref_dir).measure
20
- agg = suite.aggregate_shape_counts
6
+ module Ea
7
+ module Svg
8
+ module Parity
9
+ # Formatting shared by the benchmark tasks; parity baselines use CorpusReport.
10
+ module BenchOutput
11
+ def self.shape_counts(counts, width:)
12
+ %i[rect path polygon text].each do |key|
13
+ ours = counts[:ours][key]
14
+ reference = counts[:reference][key]
15
+ delta = ours - reference
16
+ puts " #{key.to_s.ljust(7)} ours=#{ours.to_s.rjust(width)} ref=#{reference.to_s.rjust(width)} " \
17
+ "delta=#{delta.to_s.rjust(5)} (#{percentage(delta, reference)}%)"
18
+ end
19
+ end
21
20
 
22
- puts "Source: #{source}"
23
- puts "Refs: #{ref_dir}"
24
- puts "Diagrams: #{suite.total} (matched: #{suite.matched(shape_tolerance: tolerance)})"
25
- %i[rect path polygon text].each do |k|
26
- o = agg[:ours][k]
27
- r = agg[:reference][k]
28
- d = o - r
29
- pct = r.zero? ? 0.0 : (d.to_f / r * 100).round(1)
30
- puts " #{k.to_s.ljust(7)} ours=#{o.to_s.rjust(6)} ref=#{r.to_s.rjust(6)} delta=#{d.to_s.rjust(5)} (#{pct}%)"
31
- end
32
- puts "Text overlap avg: #{(suite.text_overlap_avg * 100).round(1)}%"
33
-
34
- outliers = suite.outliers(shape_tolerance: tolerance)
35
- unless outliers.empty?
36
- puts "\nOutliers (#{outliers.size}):"
37
- outliers.first(20).each do |dr|
38
- r = dr.report
39
- puts " #{dr.id} (#{dr.name}): shape_delta=#{r.shape_delta_total} text=#{r.text_delta}"
21
+ def self.percentage(delta, reference)
22
+ reference.zero? ? 0.0 : (delta.to_f / reference * 100).round(1)
23
+ end
24
+
25
+ def self.reference_dir(exports_dir, name)
26
+ # EA export folders may omit a QEA version suffix such as ".1".
27
+ names = [name, name.sub(/\.\d+$/, "")]
28
+ paths = names.product(%w[images Images]).map do |base, images|
29
+ File.join(exports_dir, base, images)
30
+ end
31
+ paths.find { |path| Dir.exist?(path) }
32
+ end
40
33
  end
41
34
  end
42
35
  end
36
+ end
43
37
 
44
- desc "Bench every example QEA in examples/qea against its exports/Images"
45
- task :examples do
46
- project_root = File.expand_path("../..", __dir__)
47
- qea_dir = File.join(project_root, "examples", "qea")
48
- exports_dir = File.join(project_root, "examples", "exports")
49
-
50
- abort "examples/qea not found at #{qea_dir}" unless Dir.exist?(qea_dir)
51
-
52
- Dir.glob("#{qea_dir}/*.qea").sort.each do |qea_path|
53
- name = File.basename(qea_path, ".qea")
54
- # Strip version suffixes like ".1" from names like
55
- # "20251010_current_plateau_v5.1" to match the exports
56
- # directory "20251010_current_plateau_v5".
57
- stripped_name = name.sub(/\.\d+$/, "")
58
- # Reference images live in examples/exports/<name>/images or Images
59
- candidates = [
60
- File.join(exports_dir, name, "images"),
61
- File.join(exports_dir, name, "Images"),
62
- File.join(exports_dir, stripped_name, "images"),
63
- File.join(exports_dir, stripped_name, "Images")
64
- ]
65
- ref_dir = candidates.find { |p| Dir.exist?(p) }
66
- if ref_dir.nil?
67
- puts "#{name}: SKIP (no exports/images directory)"
68
- next
69
- end
38
+ desc "Report Suite deltas and write a YAML baseline (SOURCE, REF_DIR, OUTPUT_PATH=parity-baseline.yml)"
39
+ task "svg:parity_report", %i[source ref_dir output_path] do |_t, args|
40
+ source = args[:source]
41
+ ref_dir = args[:ref_dir]
42
+ abort "usage: rake svg:parity_report[source,ref_dir,output_path]" unless source && ref_dir
43
+ abort "source not found: #{source}" unless File.exist?(source)
44
+ abort "ref_dir not found: #{ref_dir}" unless Dir.exist?(ref_dir)
70
45
 
71
- doc = Ea::Sources::Qea::Adapter.from_path(qea_path)
72
- suite = Ea::Svg::Parity::Suite.new(doc, ref_dir).measure
73
- agg = suite.aggregate_shape_counts
74
-
75
- matched = suite.matched(shape_tolerance: 5)
76
- puts "#{name.ljust(40)} #{matched}/#{suite.total} matched"
77
- %i[rect path polygon text].each do |k|
78
- o = agg[:ours][k]
79
- r = agg[:reference][k]
80
- d = o - r
81
- pct = r.zero? ? 0.0 : (d.to_f / r * 100).round(1)
82
- puts " #{k.to_s.ljust(7)} ours=#{o.to_s.rjust(5)} ref=#{r.to_s.rjust(5)} delta=#{d.to_s.rjust(5)} (#{pct}%)"
83
- end
84
- puts ""
46
+ doc = Ea::Svg::Parity::Source.new(source).load
47
+ Ea::Svg::Parity::CorpusReport.new(document: doc, ref_dir: ref_dir)
48
+ .run_baseline(output_path: args[:output_path] || "parity-baseline.yml")
49
+ end
50
+
51
+ desc "Score rendered SVG against EA reference SVGs (SOURCE.xmi or .qea + REF_DIR)"
52
+ task "svg:bench", %i[source ref_dir tolerance] do |_t, args|
53
+ source = args[:source] || ENV["EA_BENCH_SOURCE"] ||
54
+ File.expand_path("~/src/mn/mn-samples-plateau/sources/xmi/plateau_all_packages_export.xmi")
55
+ ref_dir = args[:ref_dir] || ENV["EA_BENCH_REF_DIR"] ||
56
+ File.expand_path("~/src/mn/mn-samples-plateau/sources/001-mds/xmi-images")
57
+ tolerance = (args[:tolerance] || ENV["EA_BENCH_TOLERANCE"] || "5").to_i
58
+
59
+ abort "source not found: #{source}" unless File.exist?(source)
60
+ abort "ref_dir not found: #{ref_dir}" unless Dir.exist?(ref_dir)
61
+
62
+ doc = Ea::Svg::Parity::Source.new(source).load
63
+ suite = Ea::Svg::Parity::Suite.new(doc, ref_dir).measure
64
+ agg = suite.aggregate_shape_counts
65
+
66
+ puts "Source: #{source}"
67
+ puts "Refs: #{ref_dir}"
68
+ puts "Diagrams: #{suite.total} (matched: #{suite.matched(shape_tolerance: tolerance)})"
69
+ Ea::Svg::Parity::BenchOutput.shape_counts(agg, width: 6)
70
+ puts "Text overlap avg: #{(suite.text_overlap_avg * 100).round(1)}%"
71
+
72
+ outliers = suite.outliers(shape_tolerance: tolerance)
73
+ unless outliers.empty?
74
+ puts "\nOutliers (#{outliers.size}):"
75
+ outliers.first(20).each do |dr|
76
+ r = dr.report
77
+ puts " #{dr.id} (#{dr.name}): shape_delta=#{r.shape_delta_total} text=#{r.text_delta}"
85
78
  end
86
79
  end
87
80
  end
81
+
82
+ desc "Bench every example QEA in examples/qea against its exports/Images"
83
+ task "svg:examples" do
84
+ project_root = File.expand_path("../..", __dir__)
85
+ qea_dir = File.join(project_root, "examples", "qea")
86
+ exports_dir = File.join(project_root, "examples", "exports")
87
+
88
+ abort "examples/qea not found at #{qea_dir}" unless Dir.exist?(qea_dir)
89
+
90
+ Dir.glob("#{qea_dir}/*.qea").sort.each do |qea_path|
91
+ name = File.basename(qea_path, ".qea")
92
+ ref_dir = Ea::Svg::Parity::BenchOutput.reference_dir(exports_dir, name)
93
+ if ref_dir.nil?
94
+ puts "#{name}: SKIP (no exports/images directory)"
95
+ next
96
+ end
97
+
98
+ doc = Ea::Sources::Qea::Adapter.from_path(qea_path)
99
+ suite = Ea::Svg::Parity::Suite.new(doc, ref_dir).measure
100
+ agg = suite.aggregate_shape_counts
101
+
102
+ matched = suite.matched(shape_tolerance: 5)
103
+ puts "#{name.ljust(40)} #{matched}/#{suite.total} matched"
104
+ Ea::Svg::Parity::BenchOutput.shape_counts(agg, width: 5)
105
+ puts ""
106
+ end
107
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ea
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.148
4
+ version: 0.6.149
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-11-13 00:00:00.000000000 Z
11
+ date: 2026-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lutaml-model