Class: Relaton::Bipm::RawdataBipmMetrologia::Fetcher
- Inherits:
-
Object
- Object
- Relaton::Bipm::RawdataBipmMetrologia::Fetcher
- Defined in:
- lib/relaton/bipm/rawdata_bipm_metrologia/fetcher.rb
Constant Summary collapse
- DIR =
"rawdata-bipm-metrologia/data/*content/0026-1394"
Class Method Summary collapse
Instance Method Summary collapse
-
#archive_date(path) ⇒ String
Extract archive date from path for sorting.
-
#docidentifier(id) ⇒ Array<Relaton::Bib::Docidentifier>
Create docidentifier.
-
#fetch ⇒ Object
Fetch documents from rawdata-bipm-metrologia and save to files.
-
#fetch_articles ⇒ Object
Fetch articles from rawdata-bipm-metrologia and save to files.
-
#fetch_issues ⇒ Object
Fetch issues from rawdata-bipm-metrologia and save to files.
-
#fetch_metrologia(*args) ⇒ Object
Fetch metrologia root document from rawdata-bipm-metrologia and save to a file.
-
#fetch_volumes ⇒ Object
Fetch volumes from rawdata-bipm-metrologia and save to files.
- #id_parts(*args) ⇒ Object
-
#identifier(*args) ⇒ String
Create identifier.
-
#initialize(data_fetcher) ⇒ Fetcher
constructor
A new instance of Fetcher.
- #link(*args) ⇒ Object
-
#rel_bibitem(id) ⇒ Relaton::Bipm::Item
Create relation bibitem.
-
#relation(*args) ⇒ Array<Relaton::Bib::Relation>
Fetch relations.
- #typed_uri(*args) ⇒ Object
Constructor Details
#initialize(data_fetcher) ⇒ Fetcher
Returns a new instance of Fetcher.
17 18 19 |
# File 'lib/relaton/bipm/rawdata_bipm_metrologia/fetcher.rb', line 17 def initialize(data_fetcher) @data_fetcher = WeakRef.new data_fetcher end |
Class Method Details
.fetch(data_fetcher) ⇒ Object
12 13 14 |
# File 'lib/relaton/bipm/rawdata_bipm_metrologia/fetcher.rb', line 12 def self.fetch(data_fetcher) new(data_fetcher).fetch end |
Instance Method Details
#archive_date(path) ⇒ String
Extract archive date from path for sorting
160 161 162 |
# File 'lib/relaton/bipm/rawdata_bipm_metrologia/fetcher.rb', line 160 def archive_date(path) path[%r{/data/(\d{4}-\d{2}-\d{2}T[\d_]+)_content/}, 1].to_s end |
#docidentifier(id) ⇒ Array<Relaton::Bib::Docidentifier>
Create docidentifier
94 95 96 |
# File 'lib/relaton/bipm/rawdata_bipm_metrologia/fetcher.rb', line 94 def docidentifier(id) [Relaton::Bib::Docidentifier.new(content: id, type: "BIPM", primary: true)] end |
#fetch ⇒ Object
Fetch documents from rawdata-bipm-metrologia and save to files
24 25 26 27 28 29 |
# File 'lib/relaton/bipm/rawdata_bipm_metrologia/fetcher.rb', line 24 def fetch fetch_metrologia fetch_volumes fetch_issues fetch_articles end |
#fetch_articles ⇒ Object
Fetch articles from rawdata-bipm-metrologia and save to files
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/relaton/bipm/rawdata_bipm_metrologia/fetcher.rb', line 34 def fetch_articles # rubocop:disable Metrics/AbcSize, Metrics/MethodLength # aff = Affiliations.parse DIR Dir["#{DIR}/**/*.xml"].sort_by { |p| archive_date(p) }.each do |path| item = ArticleParser.parse path, @data_fetcher.errors file = "#{item.docidentifier.first.content.downcase.tr(' ', '-')}.#{@data_fetcher.ext}" out_path = File.join(@data_fetcher.output, file) key = Relaton::Bipm::Id.new.parse(item.docidentifier.first.content).to_hash @data_fetcher.index.add_or_update key, out_path @data_fetcher.write_file out_path, item end end |
#fetch_issues ⇒ Object
Fetch issues from rawdata-bipm-metrologia and save to files
58 59 60 61 62 63 |
# File 'lib/relaton/bipm/rawdata_bipm_metrologia/fetcher.rb', line 58 def fetch_issues Dir["#{DIR}/*/*"].each do |path| volume, issue = path.split("/").last(2) fetch_metrologia volume, issue end end |
#set(volume, issue) ⇒ Object #set(volume) ⇒ Object
Fetch metrologia root document from rawdata-bipm-metrologia and save to a file
74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/relaton/bipm/rawdata_bipm_metrologia/fetcher.rb', line 74 def fetch_metrologia(*args) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize id = identifier(*args) item = ItemData.new( type: "article", formattedref: Relaton::Bib::Formattedref.new(content: id), docidentifier: docidentifier(id), language: ["en"], script: ["Latn"], relation: relation(*args), source: typed_uri(*args) ) file = "#{id.downcase.gsub(' ', '-')}.#{@data_fetcher.ext}" path = File.join(@data_fetcher.output, file) @data_fetcher.index.add_or_update Id.new.parse(id).to_hash, path @data_fetcher.write_file path, item end |
#fetch_volumes ⇒ Object
Fetch volumes from rawdata-bipm-metrologia and save to files
49 50 51 52 53 |
# File 'lib/relaton/bipm/rawdata_bipm_metrologia/fetcher.rb', line 49 def fetch_volumes Dir["#{DIR}/*"].map { |path| path.split("/").last }.uniq.each do |volume| fetch_metrologia volume end end |
#id_parts(*args) ⇒ Object
117 118 119 |
# File 'lib/relaton/bipm/rawdata_bipm_metrologia/fetcher.rb', line 117 def id_parts(*args) args.map { |p| p.match(/[^_]+$/).to_s } end |
#set(volume, issue, article) ⇒ String #set(volume, issue) ⇒ String #set(volume) ⇒ String
Create identifier
113 114 115 |
# File 'lib/relaton/bipm/rawdata_bipm_metrologia/fetcher.rb', line 113 def identifier(*args) ["Metrologia", *id_parts(*args)].join(" ") end |
#link(*args) ⇒ Object
164 165 166 167 168 169 170 171 |
# File 'lib/relaton/bipm/rawdata_bipm_metrologia/fetcher.rb', line 164 def link(*args) params = id_parts(*args).join("/") case args.size when 0 then "https://iopscience.iop.org/journal/0026-1394" when 1 then "https://iopscience.iop.org/volume/0026-1394/#{params}" when 2 then "https://iopscience.iop.org/issue/0026-1394/#{params}" end end |
#rel_bibitem(id) ⇒ Relaton::Bipm::Item
Create relation bibitem
145 146 147 |
# File 'lib/relaton/bipm/rawdata_bipm_metrologia/fetcher.rb', line 145 def rel_bibitem(id) Relaton::Bib::ItemData.new(formattedref: Relaton::Bib::Formattedref.new(content: id), docidentifier: docidentifier(id)) end |
#relation(*args) ⇒ Array<Relaton::Bib::Relation>
Fetch relations
128 129 130 131 132 133 134 135 136 |
# File 'lib/relaton/bipm/rawdata_bipm_metrologia/fetcher.rb', line 128 def relation(*args) dir = [DIR, *args].join("/") ids = Set.new Dir["#{dir}/*"].each do |path| part = path.split("/").last ids << identifier(*args, part) end ids.map { |id| Relaton::Bib::Relation.new(type: "partOf", bibitem: rel_bibitem(id)) } end |
#typed_uri(*args) ⇒ Object
149 150 151 |
# File 'lib/relaton/bipm/rawdata_bipm_metrologia/fetcher.rb', line 149 def typed_uri(*args) [Relaton::Bib::Uri.new(type: "src", content: link(*args))] end |