Module: Unitsdb::Commands::Qudt::Formatter
- Defined in:
- lib/unitsdb/commands/qudt/formatter.rb
Overview
Formats output for QUDT matching results
Class Method Summary collapse
-
.display_db_results(entity_type, matches, missing_refs, unmatched_db) ⇒ Object
Display results for UnitsDB → QUDT matching.
-
.display_missing_qudt_entities(entity_type, unmatched_qudt) ⇒ Object
Display missing QUDT entities analysis.
-
.display_qudt_results(entity_type, matches, missing_matches, unmatched_qudt) ⇒ Object
Display results for QUDT → UnitsDB matching.
-
.format_qudt_entity_details(entity) ⇒ Object
Format detailed information about a QUDT entity.
-
.get_db_entity_id(entity) ⇒ Object
Helper to get db entity id.
-
.get_db_entity_name(entity) ⇒ Object
Helper to get db entity name.
-
.get_qudt_entity_name(entity) ⇒ Object
Helper to get qudt entity name.
-
.print_direction_header(direction) ⇒ Object
Print a direction header (UnitsDB → QUDT or QUDT → UnitsDB).
Class Method Details
.display_db_results(entity_type, matches, missing_refs, unmatched_db) ⇒ Object
Display results for UnitsDB → QUDT matching
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 |
# File 'lib/unitsdb/commands/qudt/formatter.rb', line 115 def display_db_results(entity_type, matches, missing_refs, unmatched_db) puts "\nResults for #{entity_type.capitalize} (UnitsDB → QUDT):" puts " Matched: #{matches.size}" puts " Missing references (could be added): #{missing_refs.size}" puts " Unmatched UnitsDB entities: #{unmatched_db.size}" unless unmatched_db.empty? puts "\nUnmatched UnitsDB #{entity_type}:" unmatched_db.each do |entity| id = get_db_entity_id(entity) name = get_db_entity_name(entity) puts " - #{name} (#{id})" end end return if missing_refs.empty? puts "\nPotential references (QUDT references that could be added to UnitsDB):" missing_refs.each do |match| qudt_entity = match[:qudt_entity] db_entity = match[:db_entity] # Get entity IDs and names db_id = get_db_entity_id(db_entity) db_name = get_db_entity_name(db_entity) qudt_name = get_qudt_entity_name(qudt_entity) qudt_uri = qudt_entity.uri case qudt_entity when Unitsdb::QudtUnit puts " - UnitsDB unit '#{db_name}' (#{db_id}) → QUDT unit '#{qudt_name}' (#{qudt_uri})" when Unitsdb::QudtQuantityKind puts " - UnitsDB quantity '#{db_name}' (#{db_id}) → QUDT quantity kind '#{qudt_name}' (#{qudt_uri})" when Unitsdb::QudtDimensionVector puts " - UnitsDB dimension '#{db_name}' (#{db_id}) → QUDT dimension vector '#{qudt_name}' (#{qudt_uri})" when Unitsdb::QudtSystemOfUnits puts " - UnitsDB unit system '#{db_name}' (#{db_id}) → QUDT system of units '#{qudt_name}' (#{qudt_uri})" end end end |
.display_missing_qudt_entities(entity_type, unmatched_qudt) ⇒ Object
Display missing QUDT entities analysis
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/unitsdb/commands/qudt/formatter.rb', line 50 def display_missing_qudt_entities(entity_type, unmatched_qudt) return if unmatched_qudt.empty? puts "\n#{'=' * 60}" puts "MISSING QUDT ENTITIES ANALYSIS" puts "=" * 60 puts "\nQUDT #{entity_type.capitalize} that don't exist in UnitsDB (#{unmatched_qudt.size} total):" puts "\nThese are QUDT entities that have no corresponding entity in UnitsDB." puts "Consider whether any of these should be added to UnitsDB.\n" unmatched_qudt.each_with_index do |entity, index| puts "\n#{index + 1}. #{format_qudt_entity_details(entity)}" end puts "\n#{'-' * 60}" puts "RECOMMENDATION: Review these entities to determine if any should be added to UnitsDB." puts "Focus on commonly used #{entity_type} that would benefit the UnitsDB community." puts "-" * 60 end |
.display_qudt_results(entity_type, matches, missing_matches, unmatched_qudt) ⇒ Object
Display results for QUDT → UnitsDB matching
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/unitsdb/commands/qudt/formatter.rb', line 16 def display_qudt_results(entity_type, matches, missing_matches, unmatched_qudt) puts "\nResults for #{entity_type.capitalize} (QUDT → UnitsDB):" puts " Matched: #{matches.size}" puts " Missing matches (could be added): #{missing_matches.size}" puts " Unmatched QUDT entities: #{unmatched_qudt.size}" return if missing_matches.empty? puts "\nPotential additions (QUDT #{entity_type} that could be added to UnitsDB):" missing_matches.each do |match| qudt_entity = match[:qudt_entity] db_entity = match[:db_entity] # Get entity IDs and names db_id = get_db_entity_id(db_entity) db_name = get_db_entity_name(db_entity) qudt_name = get_qudt_entity_name(qudt_entity) qudt_uri = qudt_entity.uri case qudt_entity when Unitsdb::QudtUnit puts " - UnitsDB unit '#{db_name}' (#{db_id}) → QUDT unit '#{qudt_name}' (#{qudt_uri})" when Unitsdb::QudtQuantityKind puts " - UnitsDB quantity '#{db_name}' (#{db_id}) → QUDT quantity kind '#{qudt_name}' (#{qudt_uri})" when Unitsdb::QudtDimensionVector puts " - UnitsDB dimension '#{db_name}' (#{db_id}) → QUDT dimension vector '#{qudt_name}' (#{qudt_uri})" when Unitsdb::QudtSystemOfUnits puts " - UnitsDB unit system '#{db_name}' (#{db_id}) → QUDT system of units '#{qudt_name}' (#{qudt_uri})" end end end |
.format_qudt_entity_details(entity) ⇒ Object
Format detailed information about a QUDT entity
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/unitsdb/commands/qudt/formatter.rb', line 71 def format_qudt_entity_details(entity) case entity when Unitsdb::QudtUnit details = "UNIT: #{entity.label || 'No label'}" details += "\n URI: #{entity.uri}" details += "\n Symbol: #{entity.symbol}" if entity.symbol details += "\n Description: #{entity.description}" if entity.description details += "\n Quantity Kind: #{entity.has_quantity_kind}" if entity.has_quantity_kind details += "\n Dimension Vector: #{entity.has_dimension_vector}" if entity.has_dimension_vector details += "\n Conversion Multiplier: #{entity.conversion_multiplier}" if entity.conversion_multiplier details when Unitsdb::QudtQuantityKind details = "QUANTITY KIND: #{entity.label || 'No label'}" details += "\n URI: #{entity.uri}" details += "\n Symbol: #{entity.symbol}" if entity.symbol details += "\n Description: #{entity.description}" if entity.description details += "\n Dimension Vector: #{entity.has_dimension_vector}" if entity.has_dimension_vector details when Unitsdb::QudtDimensionVector details = "DIMENSION VECTOR: #{entity.label || 'No label'}" details += "\n URI: #{entity.uri}" details += "\n Description: #{entity.description}" if entity.description exponents = [] exponents << "L:#{entity.dimension_exponent_for_length}" if entity.dimension_exponent_for_length != 0 exponents << "M:#{entity.dimension_exponent_for_mass}" if entity.dimension_exponent_for_mass != 0 exponents << "T:#{entity.dimension_exponent_for_time}" if entity.dimension_exponent_for_time != 0 exponents << "I:#{entity.dimension_exponent_for_electric_current}" if entity.dimension_exponent_for_electric_current != 0 exponents << "Θ:#{entity.dimension_exponent_for_thermodynamic_temperature}" if entity.dimension_exponent_for_thermodynamic_temperature != 0 exponents << "N:#{entity.dimension_exponent_for_amount_of_substance}" if entity.dimension_exponent_for_amount_of_substance != 0 exponents << "J:#{entity.dimension_exponent_for_luminous_intensity}" if entity.dimension_exponent_for_luminous_intensity != 0 details += "\n Exponents: #{exponents.join(', ')}" unless exponents.empty? details when Unitsdb::QudtSystemOfUnits details = "SYSTEM OF UNITS: #{entity.label || 'No label'}" details += "\n URI: #{entity.uri}" details += "\n Abbreviation: #{entity.abbreviation}" if entity.abbreviation details += "\n Description: #{entity.description}" if entity.description details else "UNKNOWN ENTITY TYPE: #{entity.uri}" end end |
.get_db_entity_id(entity) ⇒ Object
Helper to get db entity id
157 158 159 160 161 |
# File 'lib/unitsdb/commands/qudt/formatter.rb', line 157 def get_db_entity_id(entity) return entity.identifiers.first.id unless entity.identifiers.empty? entity.short || "unknown-id" end |
.get_db_entity_name(entity) ⇒ Object
Helper to get db entity name
164 165 166 167 168 169 |
# File 'lib/unitsdb/commands/qudt/formatter.rb', line 164 def get_db_entity_name(entity) return entity.names.first.value unless entity.names.empty? return entity.short if entity.short "unknown-name" end |
.get_qudt_entity_name(entity) ⇒ Object
Helper to get qudt entity name
172 173 174 175 176 177 178 179 |
# File 'lib/unitsdb/commands/qudt/formatter.rb', line 172 def get_qudt_entity_name(entity) case entity when Unitsdb::QudtUnit, Unitsdb::QudtQuantityKind, Unitsdb::QudtDimensionVector, Unitsdb::QudtSystemOfUnits entity.label || "No label" else "unknown-name" end end |
.print_direction_header(direction) ⇒ Object
Print a direction header (UnitsDB → QUDT or QUDT → UnitsDB)
11 12 13 |
# File 'lib/unitsdb/commands/qudt/formatter.rb', line 11 def print_direction_header(direction) puts "\n=== #{direction} ===\n" end |