Class: Relaton::Bipm::DataOutcomesParser
- Inherits:
-
Object
- Object
- Relaton::Bipm::DataOutcomesParser
- Defined in:
- lib/relaton/bipm/data_outcomes_parser.rb
Constant Summary collapse
- SHORTTYPE =
{ "Resolution" => "RES", "Recommendation" => "REC", "Decision" => "DECN", "Statement" => "DECL", "Declaration" => "DECL", "Action" => "ACT", }.freeze
- TRANSLATIONS =
{ "Declaration" => "Déclaration", "Meeting" => "Réunion", "Recommendation" => "Recommandation", "Resolution" => "Résolution", "Decision" => "Décision", }.freeze
Class Method Summary collapse
-
.parse(data_fetcher) ⇒ Object
Parse documents from data-outcomes dataset and write them to YAML files.
Instance Method Summary collapse
-
#add_part(hash, body, type, num, part) ⇒ Object
Add part to ID and structured identifier.
-
#add_to_index(item, path) ⇒ Object
Add item to index.
-
#bipm_contrib ⇒ Relaton::Bipm::Contributor
Create BIPM contributor.
-
#cctf_subdivision(date) ⇒ Relaton::Bib::Subdivision
Create CCTF subdivision.
-
#cgpm_subdivision ⇒ Relaton::Bib::Subdivision
Create CGPM subdivision.
-
#cipm_subdivision ⇒ Relaton::Bib::Subdivision
Create CIPM subdivision.
-
#committee_subdivision(date, body) ⇒ Relaton::Bib::Subdivision?
Create committee subdivision.
-
#contributors(date, body) ⇒ Array<Hash>
Create contributors.
- #create_date(**args) ⇒ Object
- #create_ext(type, num) ⇒ Object
-
#create_id(body:, type:, num:, part: nil, date:) ⇒ String
Create ID.
-
#create_links(**args) ⇒ Array<Hash>
Create links.
- #create_meeting_docids(en_id) ⇒ Object
-
#create_meeting_docnum(body, type, num, date) ⇒ String
Create meeting document number.
-
#create_resolution_docids(body, type, num, date) ⇒ Array<Relaton::Bib::Docidentifier>
Create documetn IDs.
-
#create_resolution_docnum(body, type, num, date) ⇒ String
Creata resolution document number.
-
#create_title(content, language, format = "text/plain") ⇒ Hash
Create a title.
- #create_titles(data) ⇒ Object
-
#fetch_body(dir) ⇒ Object
Search for English meetings in the body directory.
-
#fetch_meeting(en_file, body, type, dir) ⇒ Object
Create and write BIPM meeting/resolution.
-
#fetch_resolution(**args) ⇒ Object
Parse BIPM resolutions and write them to YAML files.
-
#fetch_type(dir, body) ⇒ Object
Search for meetings.
-
#initialize(data_fetcher) ⇒ DataOutcomesParser
constructor
Create data-outcomes parser.
-
#make_docid(**args) ⇒ Relaton::Bib::Docidentifier
Create doucment ID.
-
#meeting_bibitem(**args) ⇒ Hash
Create hash from BIPM meeting.
- #meeting_links(en_file, fr_file) ⇒ Object
- #meeting_md(eng, frn) ⇒ Object
-
#organization(names, abbr, abbr_lang: "en", url: []) ⇒ Relaton::Bib::Organization
Create organization.
-
#parse ⇒ Object
Parse BIPM meeting and write them to YAML files.
- #parse_doctype(type) ⇒ Object
- #parse_file(path) ⇒ Object
-
#read_files(en_file) ⇒ Array<Hash, String, nil>
Read English and French files.
- #resolution_fr_long_id(body, type, num, year) ⇒ Object
- #resolution_long_ids(body, type, num, year) {|make_docid content: en, type: "BIPM-long", language: "en", script: "Latn"| ... } ⇒ Object
- #resolution_short_ids(body, type, num, year) {|make_docid(content: short, type: "BIPM", primary: true)| ... } ⇒ Object
-
#resolution_source(en_r, fr_r, src) ⇒ Array<Hash>
Parse resolution links.
-
#resolution_title(en_r, fr_r) ⇒ Array<Hash>
Parse resolution titles.
-
#special_id_case?(body, type, year) ⇒ Boolean
Check if ID is special case.
-
#subdivision(names, abbr, abbr_lang: "en") ⇒ Relaton::Bib::Subdivision
Create subdivision.
Constructor Details
#initialize(data_fetcher) ⇒ DataOutcomesParser
Create data-outcomes parser
25 26 27 |
# File 'lib/relaton/bipm/data_outcomes_parser.rb', line 25 def initialize(data_fetcher) @data_fetcher = WeakRef.new data_fetcher end |
Class Method Details
.parse(data_fetcher) ⇒ Object
Parse documents from data-outcomes dataset and write them to YAML files
34 35 36 |
# File 'lib/relaton/bipm/data_outcomes_parser.rb', line 34 def self.parse(data_fetcher) new(data_fetcher).parse end |
Instance Method Details
#add_part(hash, body, type, num, part) ⇒ Object
Add part to ID and structured identifier
431 432 433 434 435 436 437 438 439 440 441 |
# File 'lib/relaton/bipm/data_outcomes_parser.rb', line 431 def add_part(hash, body, type, num, part) regex = /(\p{L}+\s(?:\w+\/)?\d+)(?![\d-])/ date = hash[:date].first.at.to_s hash[:id] = create_id(body: body, type: type, num: num, part: part, date: date) # += "#{part}" hash[:docnumber].sub!(regex) { |m| "#{m}-#{part}" } hash[:docidentifier].select { |id| id.type == "BIPM" }.each do |did| did.content.sub!(regex) { "#{$1}-#{part}" } # did.instance_variable_set(:@id, id) end hash[:ext].structuredidentifier.part = part end |
#add_to_index(item, path) ⇒ Object
Add item to index
273 274 275 276 |
# File 'lib/relaton/bipm/data_outcomes_parser.rb', line 273 def add_to_index(item, path) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength key = Id.new.parse(item.docnumber).to_hash @data_fetcher.index.add_or_update key, path end |
#bipm_contrib ⇒ Relaton::Bipm::Contributor
Create BIPM contributor
319 320 321 322 323 324 325 326 327 |
# File 'lib/relaton/bipm/data_outcomes_parser.rb', line 319 def bipm_contrib nms = [ { content: "International Bureau of Weights and Measures", language: "en" }, { content: "Bureau international des poids et mesures", language: "fr" }, ] bipm_org = organization(nms, "BIPM", abbr_lang: "fr", url: ["www.bipm.org"]) role = Relaton::Bib::Contributor::Role.new(type: "publisher") Relaton::Bib::Contributor.new(organization: bipm_org, role: [role]) end |
#cctf_subdivision(date) ⇒ Relaton::Bib::Subdivision
Create CCTF subdivision
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
# File 'lib/relaton/bipm/data_outcomes_parser.rb', line 336 def cctf_subdivision(date) # rubocop:disable Metrics/MethodLength if ::Date.parse(date).year < 1999 nms = [ { content: "Consultative Committee for the Definition of the Second", language: "en" }, { content: "Comité Consultatif pour la Définition de la Seconde", language: "fr" }, ] subdivision nms, "CCDS" else nms = [ { content: "Consultative Committee for Time and Frequency", language: "en" }, { content: "Comité consultatif du temps et des fréquences", language: "fr" }, ] subdivision nms, "CCTF" end end |
#cgpm_subdivision ⇒ Relaton::Bib::Subdivision
Create CGPM subdivision
389 390 391 392 393 394 395 |
# File 'lib/relaton/bipm/data_outcomes_parser.rb', line 389 def cgpm_subdivision nms = [ { content: "General Conference on Weights and Measures", language: "en" }, { content: "Conférence Générale des Poids et Mesures", language: "fr" }, ] subdivision nms, "CGPM", abbr_lang: "fr" end |
#cipm_subdivision ⇒ Relaton::Bib::Subdivision
Create CIPM subdivision
402 403 404 405 406 407 408 |
# File 'lib/relaton/bipm/data_outcomes_parser.rb', line 402 def cipm_subdivision names = [ { content: "International Committee for Weights and Measures", language: "en" }, { content: "Comité international des poids et mesures", language: "fr" }, ] subdivision names, "CIPM", abbr_lang: "fr" end |
#committee_subdivision(date, body) ⇒ Relaton::Bib::Subdivision?
Create committee subdivision
306 307 308 309 310 311 312 |
# File 'lib/relaton/bipm/data_outcomes_parser.rb', line 306 def committee_subdivision(date, body) case body when "CCTF" then cctf_subdivision date when "CGPM" then cgpm_subdivision when "CIPM" then cipm_subdivision end end |
#contributors(date, body) ⇒ Array<Hash>
Create contributors
286 287 288 289 290 291 292 293 294 295 296 |
# File 'lib/relaton/bipm/data_outcomes_parser.rb', line 286 def contributors(date, body) contribs = [bipm_contrib] subdiv = committee_subdivision date, body return contribs unless subdiv bipm_name = [Relaton::Bib::TypedLocalizedString.new(content: "BIPM", script: "Latn")] org = Relaton::Bib::Organization.new(name: bipm_name, subdivision: [subdiv]) desc = Relaton::Bib::LocalizedMarkedUpString.new(content: "committee") role = Relaton::Bib::Contributor::Role.new(type: "author", description: [desc]) contribs << Relaton::Bib::Contributor.new(organization: org, role: [role]) end |
#create_date(**args) ⇒ Object
480 481 482 483 484 |
# File 'lib/relaton/bipm/data_outcomes_parser.rb', line 480 def create_date(**args) return [] if args[:at].nil? || args[:at].empty? [Relaton::Bib::Date.new(**args)] end |
#create_ext(type, num) ⇒ Object
205 206 207 208 209 |
# File 'lib/relaton/bipm/data_outcomes_parser.rb', line 205 def create_ext(type, num) doctype = Doctype.new(content: parse_doctype(type)) strid = StructuredIdentifier.new docnumber: num Ext.new(doctype: doctype, structuredidentifier: strid) end |
#create_id(body:, type:, num:, part: nil, date:) ⇒ String
Create ID
555 556 557 558 |
# File 'lib/relaton/bipm/data_outcomes_parser.rb', line 555 def create_id(body:, type:, num:, part: nil, date:) year = ::Date.parse(date).year [body, SHORTTYPE[type.capitalize] || type, num, part, year].compact.join.gsub("-", "") end |
#create_links(**args) ⇒ Array<Hash>
Create links
501 502 503 504 505 506 507 508 509 510 |
# File 'lib/relaton/bipm/data_outcomes_parser.rb', line 501 def create_links(**args) links = args.slice(:en, :fr).each_with_object([]) do |(lang, md), mem| next unless md && md["url"] mem << Relaton::Bib::Uri.new(type: "citation", content: md["url"], language: lang.to_s, script: "Latn") end Array(args[:pdf]).each { |pdf| links << Relaton::Bib::Uri.new(type: "pdf", content: pdf) } links += args[:src] if args[:src] links end |
#create_meeting_docids(en_id) ⇒ Object
630 631 632 633 634 635 636 637 638 639 640 |
# File 'lib/relaton/bipm/data_outcomes_parser.rb', line 630 def create_meeting_docids(en_id) fr_id = en_id.sub(/(\d+)(?:st|nd|rd|th)/, '\1e').sub("Meeting", "réunion") fr_id_sup = fr_id.sub(/(\d+)(e)/, '\1<sup>\2</sup>') result = [ make_docid(content: en_id, type: "BIPM", primary: true, language: "en", script: "Latn"), make_docid(content: fr_id_sup, type: "BIPM", primary: true, language: "fr", script: "Latn"), make_docid(content: "#{en_id} / #{fr_id_sup}", type: "BIPM", primary: true), ] @data_fetcher.errors[:meeting_docidentifier] &&= result.empty? result end |
#create_meeting_docnum(body, type, num, date) ⇒ String
Create meeting document number
539 540 541 542 543 |
# File 'lib/relaton/bipm/data_outcomes_parser.rb', line 539 def create_meeting_docnum(body, type, num, date) year = ::Date.parse(date).year ord = %w[th st nd rd th th th th th th][num.to_i % 10] "#{body} #{num}#{ord} #{type} (#{year})" end |
#create_resolution_docids(body, type, num, date) ⇒ Array<Relaton::Bib::Docidentifier>
Create documetn IDs
581 582 583 584 585 586 587 588 |
# File 'lib/relaton/bipm/data_outcomes_parser.rb', line 581 def create_resolution_docids(body, type, num, date) year = ::Date.parse(date).year ids = [] resolution_short_ids(body, type, num, year) { |id| ids << id } resolution_long_ids(body, type, num, year) { |id| ids << id } @data_fetcher.errors[:resolution_docidentifier] &&= ids.empty? ids end |
#create_resolution_docnum(body, type, num, date) ⇒ String
Creata resolution document number
522 523 524 525 526 527 |
# File 'lib/relaton/bipm/data_outcomes_parser.rb', line 522 def create_resolution_docnum(body, type, num, date) year = ::Date.parse(date).year id = "#{body} #{SHORTTYPE[type.capitalize]}" id += " #{num}" if num.to_i.positive? "#{id} (#{year})" end |
#create_title(content, language, format = "text/plain") ⇒ Hash
Create a title
418 419 420 421 422 423 |
# File 'lib/relaton/bipm/data_outcomes_parser.rb', line 418 def create_title(content, language, format = "text/plain") if language == "fr" content.sub!(/(\d+)(e)/, '\1<sup>\2</sup>') end Relaton::Bib::Title.new(content: content, language: language, script: "Latn") end |
#create_titles(data) ⇒ Object
486 487 488 489 490 491 492 |
# File 'lib/relaton/bipm/data_outcomes_parser.rb', line 486 def create_titles(data) result = data.each_with_object([]) do |(lang, md), mem| mem << create_title(md["title"], lang.to_s) if md && md["title"] end @data_fetcher.errors[:meeting_title] &&= result.empty? result end |
#fetch_body(dir) ⇒ Object
Search for English meetings in the body directory
52 53 54 55 |
# File 'lib/relaton/bipm/data_outcomes_parser.rb', line 52 def fetch_body(dir) body = dir.split("/").last.upcase Dir[File.join(dir, "*-en")].each { |type_dir| fetch_type type_dir, body } end |
#fetch_meeting(en_file, body, type, dir) ⇒ Object
Create and write BIPM meeting/resolution
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 |
# File 'lib/relaton/bipm/data_outcomes_parser.rb', line 80 def fetch_meeting(en_file, body, type, dir) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength _, en, fr_file, fr = read_files en_file en_md, fr_md, num, part = meeting_md en, fr src = meeting_links en_file, fr_file file = "#{num}.#{@data_fetcher.ext}" path = File.join dir, file hash = meeting_bibitem body: body, type: type, en: en_md, fr: fr_md, num: num, src: src, pdf: en["pdf"] if @data_fetcher.files.include?(path) && part add_part hash, body, type, num, part item = ItemData.new(**hash) has_part_item = parse_file path has_part_item.relation << Relaton::Bib::Relation.new(type: "partOf", bibitem: item) @data_fetcher.write_file path, has_part_item, warn_duplicate: false path = File.join dir, "#{num}-#{part}.#{@data_fetcher.ext}" elsif part hash[:title].each { |t| t.content.sub!(/\s\(.+\)$/, "") } h = meeting_bibitem body: body, type: type, en: en_md, fr: fr_md, num: num, src: src, pdf: en["pdf"] add_part h, body, type, num, part part_item = ItemData.new(**h) part_item_path = File.join dir, "#{num}-#{part}.#{@data_fetcher.ext}" @data_fetcher.write_file part_item_path, part_item add_to_index part_item, part_item_path hash[:relation] = [Relaton::Bib::Relation.new(type: "partOf", bibitem: part_item)] item = ItemData.new(**hash) else item = ItemData.new(**hash) end @data_fetcher.write_file path, item add_to_index item, path fetch_resolution body: body, en: en, fr: fr, dir: dir, src: src, num: num end |
#fetch_resolution(**args) ⇒ Object
Parse BIPM resolutions and write them to YAML files
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/relaton/bipm/data_outcomes_parser.rb', line 166 def fetch_resolution(**args) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity args[:en]["resolutions"].each.with_index do |r, i| # rubocop:disable Metrics/BlockLength num = r["identifier"].to_s # .split("-").last date = r["dates"].first.to_s @data_fetcher.errors[:resolution_date] &&= date.nil? || date.empty? year = date.split("-").first num = "0" if num == year hash = { type: "proceedings", title: [], place: [Relaton::Bib::Place.new(city: "Paris")], ext: create_ext(r["type"], num), } fr_r = args.dig(:fr, "resolutions", i) # @TODO: create a GH issue when fr is missing hash[:title] = resolution_title r, fr_r hash[:source] = resolution_source r, fr_r, args[:src] hash[:date] = create_date(type: "published", at: date) num_justed = num.rjust 2, "0" type = r["type"].capitalize docnum = create_resolution_docnum args[:body], type, num, date hash[:id] = create_id(body: args[:body], type: type, num: num_justed, date: date) hash[:docidentifier] = create_resolution_docids args[:body], type, num, date hash[:docnumber] = docnum hash[:language] = %w[en fr] hash[:script] = ["Latn"] hash[:contributor] = contributors date, args[:body] @data_fetcher.errors[:resolution_contributor] &&= hash[:contributor].size < 2 # BIPM + committee item = ItemData.new(**hash) file = "#{year}-#{num_justed}.#{@data_fetcher.ext}" out_dir = File.join args[:dir], r["type"].downcase FileUtils.mkdir_p out_dir path = File.join out_dir, file @data_fetcher.write_file path, item add_to_index item, path end end |
#fetch_type(dir, body) ⇒ Object
Search for meetings
63 64 65 66 67 68 69 70 |
# File 'lib/relaton/bipm/data_outcomes_parser.rb', line 63 def fetch_type(dir, body) # rubocop:disable Metrics/AbcSize type = dir.split("/").last.split("-").first.sub(/s$/, "").capitalize body_dir = File.join @data_fetcher.output, body.downcase FileUtils.mkdir_p body_dir outdir = File.join body_dir, type.downcase FileUtils.mkdir_p outdir Dir[File.join(dir, "*.{yml,yaml}")].each { |en_file| fetch_meeting en_file, body, type, outdir } end |
#make_docid(**args) ⇒ Relaton::Bib::Docidentifier
Create doucment ID
653 654 655 |
# File 'lib/relaton/bipm/data_outcomes_parser.rb', line 653 def make_docid(**args) Relaton::Bib::Docidentifier.new(**args) end |
#meeting_bibitem(**args) ⇒ Hash
Create hash from BIPM meeting
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 |
# File 'lib/relaton/bipm/data_outcomes_parser.rb', line 457 def meeting_bibitem(**args) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity docnum = create_meeting_docnum args[:body], args[:type], args[:num], args[:en]["date"] hash = { title: [], type: "proceedings", place: [Relaton::Bib::Place.new(city: "Paris")], ext: create_ext(args[:type], args[:num]), } hash[:title] = create_titles args.slice(:en, :fr) hash[:date] = create_date(type: "published", at: args[:en]["date"]) @data_fetcher.errors[:meeting_date] &&= hash[:date].empty? hash[:docidentifier] = create_meeting_docids docnum hash[:docnumber] = docnum # .sub(" --", "").sub(/\s\(\d{4}\)/, "") hash[:id] = create_id(body: args[:body], type: args[:type], num: args[:num], date: args[:en]["date"]) hash[:source] = create_links(**args) @data_fetcher.errors[:meeting_source] &&= hash[:source].empty? hash[:language] = %w[en fr] hash[:script] = ["Latn"] hash[:contributor] = contributors args[:en]["date"], args[:body] @data_fetcher.errors[:meeting_contributor] &&= hash[:contributor].size < 2 # BIPM + committee hash end |
#meeting_links(en_file, fr_file) ⇒ Object
146 147 148 149 150 151 152 153 154 |
# File 'lib/relaton/bipm/data_outcomes_parser.rb', line 146 def meeting_links(en_file, fr_file) gh_src = "https://raw.githubusercontent.com/metanorma/bipm-data-outcomes/" { "en" => en_file, "fr" => fr_file }.map do |lang, file| next unless file src = gh_src + file.split("/")[-3..].unshift("main").join("/") Relaton::Bib::Uri.new(type: "src", content: src, language: lang, script: "Latn") end.compact end |
#meeting_md(eng, frn) ⇒ Object
140 141 142 143 144 |
# File 'lib/relaton/bipm/data_outcomes_parser.rb', line 140 def meeting_md(eng, frn) en_md = eng["metadata"] num, part = en_md["identifier"].to_s.split("-") [en_md, frn&.dig("metadata"), num, part] end |
#organization(names, abbr, abbr_lang: "en", url: []) ⇒ Relaton::Bib::Organization
Create organization
362 363 364 365 366 367 |
# File 'lib/relaton/bipm/data_outcomes_parser.rb', line 362 def organization(names, abbr, abbr_lang: "en", url: []) name = names.map { |ctrb| Relaton::Bib::TypedLocalizedString.new(**ctrb, script: "Latn") } abbreviation = Relaton::Bib::LocalizedString.new(content: abbr, language: abbr_lang, script: "Latn") uri = url.map { |u| Relaton::Bib::Uri.new(content: u) } Relaton::Bib::Organization.new(name: name, abbreviation: abbreviation, uri: uri) end |
#parse ⇒ Object
Parse BIPM meeting and write them to YAML files
41 42 43 44 45 |
# File 'lib/relaton/bipm/data_outcomes_parser.rb', line 41 def parse dirs = "cctf,cgpm,cipm,ccauv,ccem,ccl,ccm,ccpr,ccqm,ccri,cct,ccu,jcgm,jcrb" source_path = File.join "bipm-data-outcomes", "{#{dirs}}" Dir[source_path].each { |body_dir| fetch_body(body_dir) } end |
#parse_doctype(type) ⇒ Object
211 212 213 214 215 216 |
# File 'lib/relaton/bipm/data_outcomes_parser.rb', line 211 def parse_doctype(type) case type when "Meeting" then "meeting-report" else type.downcase end end |
#parse_file(path) ⇒ Object
113 114 115 116 117 118 119 120 |
# File 'lib/relaton/bipm/data_outcomes_parser.rb', line 113 def parse_file(path) case @data_fetcher.format when "yaml" Item.from_yaml(File.read(path, encoding: "UTF-8")) when "xml" Item.from_xml(File.read(path, encoding: "UTF-8")) end end |
#read_files(en_file) ⇒ Array<Hash, String, nil>
Read English and French files
129 130 131 132 133 134 135 136 137 138 |
# File 'lib/relaton/bipm/data_outcomes_parser.rb', line 129 def read_files(en_file) fr_file = en_file.sub "en", "fr" [en_file, fr_file].map do |file| if File.exist? file data = YAML.safe_load(File.read(file, encoding: "UTF-8")) path = file end [path, data] end.flatten end |
#resolution_fr_long_id(body, type, num, year) ⇒ Object
617 618 619 620 621 622 623 624 625 626 627 628 |
# File 'lib/relaton/bipm/data_outcomes_parser.rb', line 617 def resolution_fr_long_id(body, type, num, year) fr = TRANSLATIONS[type] || type if special_id_case? body, type, year fr += " #{body}" fr += "/#{num}" if num.to_i.positive? else fr += " #{num}" if num.to_i.positive? fr += body == "CGPM" ? " de la" : " du" fr += " #{body}" end "#{fr} (#{year})" end |
#resolution_long_ids(body, type, num, year) {|make_docid content: en, type: "BIPM-long", language: "en", script: "Latn"| ... } ⇒ Object
605 606 607 608 609 610 611 612 613 614 615 |
# File 'lib/relaton/bipm/data_outcomes_parser.rb', line 605 def resolution_long_ids(body, type, num, year, &_block) en = "#{body} #{type}" en += " #{num}" if num.to_i.positive? en += " (#{year})" yield make_docid content: en, type: "BIPM-long", language: "en", script: "Latn" fr = resolution_fr_long_id(body, type, num, year) yield make_docid content: fr, type: "BIPM-long", language: "fr", script: "Latn" yield make_docid(content: "#{en} / #{fr}", type: "BIPM-long") end |
#resolution_short_ids(body, type, num, year) {|make_docid(content: short, type: "BIPM", primary: true)| ... } ⇒ Object
590 591 592 593 594 595 596 597 598 599 600 601 602 603 |
# File 'lib/relaton/bipm/data_outcomes_parser.rb', line 590 def resolution_short_ids(body, type, num, year, &_block) short_type = SHORTTYPE[type] id = "#{body} #{short_type}" id += " #{num}" if num.to_i.positive? short = "#{id} (#{year})" yield make_docid(content: short, type: "BIPM", primary: true) en = "#{id} (#{year}, E)" yield make_docid(content: en, type: "BIPM", primary: true, language: "en", script: "Latn") fr = "#{id} (#{year}, F)" yield make_docid(content: fr, type: "BIPM", primary: true, language: "fr", script: "Latn") end |
#resolution_source(en_r, fr_r, src) ⇒ Array<Hash>
Parse resolution links
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
# File 'lib/relaton/bipm/data_outcomes_parser.rb', line 243 def resolution_source(en_r, fr_r, src) source = [] if en_r["url"] && !en_r["url"].empty? source << Relaton::Bib::Uri.new(type: "citation", content: en_r["url"], language: "en", script: "Latn") @data_fetcher.errors[:resolution_source_citation_en] = false else @data_fetcher.errors[:resolution_source_citation] &&= true end if fr_r && fr_r["url"] && !fr_r["url"].empty? source << Relaton::Bib::Uri.new(type: "citation", content: fr_r["url"], language: "fr", script: "Latn") @data_fetcher.errors[:resolution_source_citation_fr] = false else @data_fetcher.errors[:resolution_source_citation_fr] &&= true end source += src if src if en_r["reference"] source << Relaton::Bib::Uri.new(type: "pdf", content: en_r["reference"]) @data_fetcher.errors[:resolution_source_pdf] = false else @data_fetcher.errors[:resolution_source_pdf] &&= true end source end |
#resolution_title(en_r, fr_r) ⇒ Array<Hash>
Parse resolution titles
226 227 228 229 230 231 232 |
# File 'lib/relaton/bipm/data_outcomes_parser.rb', line 226 def resolution_title(en_r, fr_r) title = [] title << create_title(en_r["title"], "en") if en_r["title"] && !en_r["title"].empty? title << create_title(fr_r["title"], "fr") if fr_r && fr_r["title"] && !fr_r["title"].empty? @data_fetcher.errors[:resolution_title] &&= title.empty? title end |
#special_id_case?(body, type, year) ⇒ Boolean
Check if ID is special case
569 570 571 572 |
# File 'lib/relaton/bipm/data_outcomes_parser.rb', line 569 def special_id_case?(body, type, year) (body == "CIPM" && type == "Decision" && year.to_i > 2011) || (body == "JCRB" && %w[Recomendation Resolution Descision].include?(type)) end |
#subdivision(names, abbr, abbr_lang: "en") ⇒ Relaton::Bib::Subdivision
Create subdivision
378 379 380 381 382 |
# File 'lib/relaton/bipm/data_outcomes_parser.rb', line 378 def subdivision(names, abbr, abbr_lang: "en") name = names.map { |n| Relaton::Bib::TypedLocalizedString.new(**n, script: "Latn") } abbreviation = Relaton::Bib::LocalizedString.new(content: abbr, language: abbr_lang, script: "Latn") Relaton::Bib::Subdivision.new(type: "committee", name: name, abbreviation: abbreviation) end |