Class: UniProp::VersionMetaDataValidator
- Inherits:
-
Object
- Object
- UniProp::VersionMetaDataValidator
- Defined in:
- lib/uniprop/inspects.rb,
lib/uniprop/metadata_validator.rb
Defined Under Namespace
Classes: MismatchPosition
Instance Attribute Summary collapse
-
#version ⇒ Object
readonly
Returns the value of attribute version.
-
#version_metadata ⇒ Object
readonly
Returns the value of attribute version_metadata.
Instance Method Summary collapse
-
#expected_type(prop) ⇒ String
validate_typeで出力するための理想の型の名称を取得.
-
#initialize(version_metadata) ⇒ VersionMetaDataValidator
constructor
A new instance of VersionMetaDataValidator.
- #inspect ⇒ Object
-
#metadata_insufficient_files ⇒ Set<PropFile>
メタデータの記述が不足しているファイルを取得.
-
#metadata_insufficient_ranges(block_ranges, information_containing_ranges) ⇒ Array<Range<Integer>>
information_containing_rangesのうち、block_rangesに含まれていない範囲を返す.
-
#propfile_to_metadata_insufficient_ranges ⇒ Hash<PropFile,Array<Range>]
各PropFileの、メタデータに記述されていない行の範囲を取得.
-
#run_all_validations ⇒ Object
全ての検証を実行.
-
#validate_column_perfection ⇒ Object
実際の列数とメタデータに記述されている列数に違いがあるファイルを標準出力に出力.
-
#validate_files_excess(reconfirm: false) ⇒ Object
メタデータ内に余分に記述されたファイル(実際には存在しないにも関わらず、メタデータに記述されたファイル)を標準出力に出力.
-
#validate_files_shortage(reconfirm: false) ⇒ Object
メタデータ内で記述が不足しているファイルを標準出力に出力.
-
#validate_properties_excess ⇒ Object
メタデータ内に余分に記述されたプロパティ(実際には存在しないにも関わらず、メタデータに記述されたプロパティ)を標準出力に出力.
-
#validate_properties_shortage ⇒ Object
メタデータ内で記述が不足しているプロパティを標準出力に出力.
-
#validate_row_perfection ⇒ Object
メタデータに記述されていない行の範囲が存在するファイルを標準出力に出力(Unihan, メタデータが記述されていないファイルを除く).
- #validate_type ⇒ Object
-
#validate_unihan_properties_excess ⇒ Object
メタデータ内に余分に記述されたUnihanプロパティ(実際には存在しないにも関わらず、メタデータに記述されたUnihanプロパティ)を出力.
-
#validate_unihan_properties_shortage ⇒ Object
メタデータに記述が不足しているUnihanプロパティを出力.
Constructor Details
#initialize(version_metadata) ⇒ VersionMetaDataValidator
Returns a new instance of VersionMetaDataValidator.
23 24 25 26 27 28 29 30 31 |
# File 'lib/uniprop/metadata_validator.rb', line 23 def initialize() @version_metadata = @version = @version_metadata.version # validate_files_shortage, validate_files_excessでは、実際のキャッシュとメタデータを照らし合わせて検証を行う必要があるため、@versionはEfficientVersionではなくVersionでなければならない。 if @version.class != Version raise TypeError, "The argument must be a VersionMetaData object associated with Version object (not EfficientVersion)" end end |
Instance Attribute Details
#version ⇒ Object (readonly)
Returns the value of attribute version.
21 22 23 |
# File 'lib/uniprop/metadata_validator.rb', line 21 def version @version end |
#version_metadata ⇒ Object (readonly)
Returns the value of attribute version_metadata.
21 22 23 |
# File 'lib/uniprop/metadata_validator.rb', line 21 def @version_metadata end |
Instance Method Details
#expected_type(prop) ⇒ String
validate_typeで出力するための理想の型の名称を取得
189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/uniprop/metadata_validator.rb', line 189 def expected_type(prop) type = prop.property_value_type case type when :string, :numeric return type when :binary, :catalog, :enumerated return "#{type} (#{prop.longest_alias})" when :miscellaneous return prop.miscellaneous_format end end |
#inspect ⇒ Object
70 71 72 |
# File 'lib/uniprop/inspects.rb', line 70 def inspect "#<#{self.class.name} #{.version.major}.#{.version.minor}.#{.version.tiny}>" end |
#metadata_insufficient_files ⇒ Set<PropFile>
メタデータの記述が不足しているファイルを取得
52 53 54 55 56 57 58 |
# File 'lib/uniprop/metadata_validator.rb', line 52 def return @metadata_insufficient_files if @metadata_insufficient_files @metadata_insufficient_files = version.files.reject{_1.} - .actual_propfiles @metadata_insufficient_files end |
#metadata_insufficient_ranges(block_ranges, information_containing_ranges) ⇒ Array<Range<Integer>>
information_containing_rangesのうち、block_rangesに含まれていない範囲を返す
116 117 118 119 120 121 122 123 124 |
# File 'lib/uniprop/metadata_validator.rb', line 116 def (block_ranges, information_containing_ranges) result = information_containing_ranges block_ranges.each do |block_range| pre_result = result result = [] pre_result.each { result.concat(UniPropUtils::RangeProcessor.cut_internal(_1, block_range.begin, block_range.end)) } end result end |
#propfile_to_metadata_insufficient_ranges ⇒ Hash<PropFile,Array<Range>]
各PropFileの、メタデータに記述されていない行の範囲を取得
128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/uniprop/metadata_validator.rb', line 128 def return @propfile_to_metadata_insufficient_ranges if @propfile_to_metadata_insufficient_ranges @propfile_to_metadata_insufficient_ranges = Hash.new { |hash,key| hash[key]=[] } ..each do || propfile = .propfile @propfile_to_metadata_insufficient_ranges[propfile] = (.property_written_ranges, propfile.information_containing_ranges) end @propfile_to_metadata_insufficient_ranges end |
#run_all_validations ⇒ Object
全ての検証を実行
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/uniprop/metadata_validator.rb', line 34 def run_all_validations puts "== validation results for version #{version.version_name} ==" validate_files_shortage(reconfirm: true) validate_files_excess(reconfirm: false) validate_properties_shortage validate_properties_excess validate_row_perfection validate_column_perfection validate_type if version.has_unihan? validate_unihan_properties_shortage validate_unihan_properties_excess end end |
#validate_column_perfection ⇒ Object
実際の列数とメタデータに記述されている列数に違いがあるファイルを標準出力に出力
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/uniprop/metadata_validator.rb', line 165 def validate_column_perfection error_logs = [] ..each do || .blocks.each_with_index do |block, block_no| = block.content.size actual_col_size = .propfile.max_column_size(block.range) if != actual_col_size error_logs << "#{.propfile.basename_prefix} (in block #{block_no})\n\tmetadata column size: #{}\n\tactual column size: #{actual_col_size}" end end end if error_logs.empty? puts "There are no difference in column size between the metadata and the actual description in all files" else puts "Files that the number of columns differs between the metadata and the actual description" error_logs.each { puts _1 } end end |
#validate_files_excess(reconfirm: false) ⇒ Object
メタデータ内に余分に記述されたファイル(実際には存在しないにも関わらず、メタデータに記述されたファイル)を標準出力に出力
73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/uniprop/metadata_validator.rb', line 73 def validate_files_excess(reconfirm: false) version.files(reconfirm: reconfirm, reload: reconfirm) if reconfirm nonexist_files = .propfile_names.filter { !version.has_file?(_1) } if nonexist_files.empty? puts "There are no excessive files in the metadata." else puts "Files that are described in the metadata even though it does not actually exist" nonexist_files.each { puts "・#{_1}" } end end |
#validate_files_shortage(reconfirm: false) ⇒ Object
メタデータ内で記述が不足しているファイルを標準出力に出力
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/uniprop/metadata_validator.rb', line 61 def validate_files_shortage(reconfirm: false) version.files(reconfirm: reconfirm, reload: reconfirm) if reconfirm if .empty? puts "All files are described in the metadata" else puts "Files that are not described in the metadata" .each { puts "・#{_1.basename_prefix}" } end end |
#validate_properties_excess ⇒ Object
メタデータ内に余分に記述されたプロパティ(実際には存在しないにも関わらず、メタデータに記述されたプロパティ)を標準出力に出力
99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/uniprop/metadata_validator.rb', line 99 def validate_properties_excess nonexist_props = .property_names .reject { _1=="" || _1=="codepoint" } .reject { version.has_property?(_1) } if nonexist_props.empty? puts "There are no excessive properties in the metadata." else puts "Properties that's described in the metadata even though it does not actually exist" nonexist_props.each { puts "・#{_1}" } end end |
#validate_properties_shortage ⇒ Object
メタデータ内で記述が不足しているプロパティを標準出力に出力
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/uniprop/metadata_validator.rb', line 87 def validate_properties_shortage = version.properties - .actual_properties if .empty? puts "All properties are described in the metadata" else puts "Properties that not described in the metadata" .each { puts "・#{_1.longest_alias}" } end end |
#validate_row_perfection ⇒ Object
メタデータに記述されていない行の範囲が存在するファイルを標準出力に出力(Unihan, メタデータが記述されていないファイルを除く)
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/uniprop/metadata_validator.rb', line 143 def validate_row_perfection if .all? { _2.empty? } puts "There are no files for which a file name is described in the metadata but for which this information is missing." else puts "Ranges where metadata is missing in propfiles" .each do |propfile, insufficient_ranges| if !insufficient_ranges.empty? puts "・#{propfile.basename_prefix}" insufficient_ranges.each do |range| if range.size==1 puts "\t#{range.begin}" else puts "\t#{range.begin} to #{range.end}" end end end end end end |
#validate_type ⇒ Object
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/uniprop/metadata_validator.rb', line 204 def validate_type # 違いがある箇所を検出 mismatches = [] ..each do || propfile = .propfile .blocks.each do |block| block.content.each_with_index do |prop, col| # 列の値がArrayを使用して記述されている場合、検証をスキップする next if !prop || prop.class==Array mismatch_row_ranges = UniPropUtils::RangeProcessor.sub( block.range, propfile.verbose_property_value_type_match_ranges(col, prop) ) if !mismatch_row_ranges.empty? mismatches << MismatchPosition.new(propfile, col, expected_type(prop), mismatch_row_ranges) end end end end # 検出結果を出力 if mismatches.empty? puts "In all blocks in the metadata, the type of the property described in the block matches the type of the values in the actual file." else mismatches.each do |mismatch| puts "According to the metadata, column #{mismatch.column} in #{mismatch.propfile.basename_prefix} should be #{mismatch.expected_type} value, but the following line is wrong." mismatch.row_ranges.each do |range| if range.size==1 puts "\t#{range.begin}" else puts "\t#{range.begin} to #{range.end}" end end end end end |
#validate_unihan_properties_excess ⇒ Object
メタデータ内に余分に記述されたUnihanプロパティ(実際には存在しないにも関わらず、メタデータに記述されたUnihanプロパティ)を出力
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
# File 'lib/uniprop/metadata_validator.rb', line 265 def validate_unihan_properties_excess nonexist_prop_names = [] .unihan_property_names.each do |prop_name| if version.unihanprop.unihan_properties.all? { !_1.has_alias?(prop_name) } nonexist_prop_names << prop_name end end if nonexist_prop_names.empty? puts "There are no excessive Unihan properties in the metadata." else puts "Unihan properties that's described in the metadata even though it does not actually exist" nonexist_prop_names.each { puts "・#{_1}" } end end |
#validate_unihan_properties_shortage ⇒ Object
メタデータに記述が不足しているUnihanプロパティを出力
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
# File 'lib/uniprop/metadata_validator.rb', line 247 def validate_unihan_properties_shortage = [] version.unihanprop.unihan_properties.each do |prop| if .unihan_property_names.all? { !prop.has_alias?(_1) } << prop end end if .empty? puts "All Unihan properties are described in the metadata" else puts "Unihan properties that's not described in the metadata" .each { puts "・#{_1.longest_alias}" } end end |