relaton-ogc 1.14.1 → 1.14.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ba3481b2cd4c2edba451a0b126d48305d7b86864f8a373976767b4fed48532e9
4
- data.tar.gz: 9f574bfe182a4886cbb063dd2e8bb700777641ffeb3fe3368419bd5073b48b02
3
+ metadata.gz: df9aa5c8876eed257c8bba8f85d6f59e917f5239c17a8937f233209c2318a6cc
4
+ data.tar.gz: 829cb72c24ba23c1762fb90f51f683fb889eaa8cb6a2b318de02932b5c4b07cc
5
5
  SHA512:
6
- metadata.gz: 143a7bc6a666ee1e1ec0b4f573aa67a94ba095b4d3adda52f35921a891ed06dea3e2c7cf8ce934101493890ab2de92ae1e5fd4138fd73b6989685b7ad84cbb5d
7
- data.tar.gz: cf59738eb30e67134f2c60e704f95bb6bb9cf8958f49494e8cbb0ae0fa54602c8b09a575aa49e619d01b707608100ab71f848bcd1aceb318019c960be0002ca2
6
+ metadata.gz: 8fcb76f8709b72a4e50f9a163d9e7234c08dd67690cf38b72395047f23347be69feff9c460392b95554889a9fdff40b1b737de892bb489f4632931830792d6c1
7
+ data.tar.gz: 6b4ebf6cb8538a543db51ca9dca4dba2fab47287229a2ce864516d063c6f634e653a6b25f8fe5817bf74301c4657d66efb1fd7631e56ea8ef5f48d45803e72b4
@@ -5,6 +5,7 @@ name: rake
5
5
  on:
6
6
  push:
7
7
  branches: [ master, main ]
8
+ tags: [ v* ]
8
9
  pull_request:
9
10
 
10
11
  jobs:
@@ -10,8 +10,9 @@ on:
10
10
  Next release version. Possible values: x.y.z, major, minor, patch or pre|rc|etc
11
11
  required: true
12
12
  default: 'skip'
13
- push:
14
- tags: [ v* ]
13
+ repository_dispatch:
14
+ types: [ do-release ]
15
+
15
16
 
16
17
  jobs:
17
18
  release:
data/.gitignore CHANGED
@@ -7,6 +7,7 @@
7
7
  /spec/reports/
8
8
  /tmp/
9
9
  /.vscode/
10
+ /vendor/
10
11
 
11
12
  # rspec failure tracking
12
13
  .rspec_status
data/.rubocop.yml CHANGED
@@ -7,6 +7,6 @@ require: rubocop-rails
7
7
  inherit_from:
8
8
  - https://raw.githubusercontent.com/riboseinc/oss-guides/master/ci/rubocop.yml
9
9
  AllCops:
10
- TargetRubyVersion: 2.5
10
+ TargetRubyVersion: 2.7
11
11
  Rails:
12
12
  Enabled: false
data/Gemfile CHANGED
@@ -2,3 +2,12 @@ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in relaton_ogc.gemspec
4
4
  gemspec
5
+
6
+ gem "equivalent-xml", "~> 0.6"
7
+ gem "pry-byebug"
8
+ gem "rake", "~> 13.0"
9
+ gem "rspec", "~> 3.0"
10
+ gem "ruby-jing"
11
+ gem "simplecov"
12
+ gem "vcr"
13
+ gem "webmock"
@@ -522,7 +522,6 @@
522
522
  <value>tip</value>
523
523
  <value>important</value>
524
524
  <value>caution</value>
525
- <value>statement</value>
526
525
  </choice>
527
526
  </define>
528
527
  <define name="figure">
data/grammars/biblio.rng CHANGED
@@ -216,6 +216,9 @@
216
216
  <optional>
217
217
  <ref name="fullname"/>
218
218
  </optional>
219
+ <zeroOrMore>
220
+ <ref name="credential"/>
221
+ </zeroOrMore>
219
222
  <zeroOrMore>
220
223
  <ref name="affiliation"/>
221
224
  </zeroOrMore>
@@ -232,6 +235,11 @@
232
235
  <ref name="FullNameType"/>
233
236
  </element>
234
237
  </define>
238
+ <define name="credential">
239
+ <element name="credential">
240
+ <text/>
241
+ </element>
242
+ </define>
235
243
  <define name="FullNameType">
236
244
  <choice>
237
245
  <group>
@@ -305,7 +313,9 @@
305
313
  <zeroOrMore>
306
314
  <ref name="affiliationdescription"/>
307
315
  </zeroOrMore>
308
- <ref name="organization"/>
316
+ <optional>
317
+ <ref name="organization"/>
318
+ </optional>
309
319
  </element>
310
320
  </define>
311
321
  <define name="affiliationname">
@@ -1316,7 +1326,7 @@
1316
1326
  <value>commentaryOf</value>
1317
1327
  <value>hasCommentary</value>
1318
1328
  <value>related</value>
1319
- <value>complements</value>
1329
+ <value>hasComplement</value>
1320
1330
  <value>complementOf</value>
1321
1331
  <value>obsoletes</value>
1322
1332
  <value>obsoletedBy</value>
@@ -1,9 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RelatonOgc
2
4
  class DataFetcher
3
5
  module Utils
4
- ENDPOINT = "https://raw.githubusercontent.com/opengeospatial/"\
5
- "NamingAuthority/master/incubation/bibliography/"\
6
- "bibliography.json".freeze
6
+ ENDPOINT = "https://raw.githubusercontent.com/opengeospatial/NamingAuthority/master/definitions/docs/docs.json"
7
7
 
8
8
  def get_data # rubocop:disable Metrics/AbcSize
9
9
  h = {}
@@ -43,45 +43,54 @@ module RelatonOgc
43
43
  # Create DataFetcher instance
44
44
  #
45
45
  # @param [String] output directory to save the documents
46
- # @param [String] format output format "yaml" or "xmo"
46
+ # @param [String] format output format "yaml", "xml", or "bibxml"
47
47
  #
48
48
  def initialize(output, format)
49
49
  @output = output
50
50
  @etagfile = File.join output, "etag.txt"
51
51
  @format = format
52
+ @ext = format.sub "bib", ""
52
53
  @docids = []
53
- @dupids = []
54
+ @dupids = Set.new
55
+ end
56
+
57
+ def index
58
+ @index ||= Relaton::Index.find_or_create :ogc, file: "index-v1.yaml"
54
59
  end
55
60
 
56
61
  def self.fetch(output: "data", format: "yaml")
57
62
  t1 = Time.now
58
63
  puts "Started at: #{t1}"
59
- FileUtils.mkdir_p output unless Dir.exist? output
64
+ FileUtils.mkdir_p output
60
65
  new(output, format).fetch
61
66
  t2 = Time.now
62
67
  puts "Stopped at: #{t2}"
63
68
  puts "Done in: #{(t2 - t1).round} sec."
64
69
  end
65
70
 
66
- def fetch # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
71
+ def fetch
67
72
  get_data do |etag, json|
68
73
  no_errors = true
69
- json.each do |_, hit|
70
- next if hit["type"] == "CC"
71
-
72
- bib = Scrapper.parse_page hit
73
- write_document bib
74
- rescue StandardError => e
75
- no_errors = false
76
- warn "Fetching document: #{hit['identifier']}"
77
- warn "#{e.class} #{e.message}"
78
- warn e.backtrace
79
- end
80
- warn "[relaton-ogc] WARNING Duplicated documents: #{@dupids.uniq.join(', ')}" if @dupids.any?
74
+ json.each { |_, hit| fetch_doc(hit) || no_errors = false }
75
+ warn "[relaton-ogc] WARNING Duplicated documents: #{@dupids.to_a.join(', ')}" if @dupids.any?
81
76
  self.etag = etag if no_errors
77
+ index.save
82
78
  end
83
79
  end
84
80
 
81
+ def fetch_doc(hit)
82
+ return if hit["type"] == "CC"
83
+
84
+ bib = Scrapper.parse_page hit
85
+ write_document bib
86
+ true
87
+ rescue StandardError => e
88
+ warn "Fetching document: #{hit['identifier']}"
89
+ warn "#{e.class} #{e.message}"
90
+ warn e.backtrace
91
+ false
92
+ end
93
+
85
94
  def write_document(bib) # rubocop:disable Metrics/AbcSize
86
95
  if @docids.include?(bib.docidentifier[0].id)
87
96
  @dupids << bib.docidentifier[0].id
@@ -89,10 +98,22 @@ module RelatonOgc
89
98
  end
90
99
 
91
100
  @docids << bib.docidentifier[0].id
101
+ file = file_name bib
102
+ index.add_or_update bib.docidentifier[0].id, file
103
+ File.write file, content(bib), encoding: "UTF-8"
104
+ end
105
+
106
+ def file_name(bib)
92
107
  name = bib.docidentifier[0].id.upcase.gsub(/[\s:.]/, "_")
93
- file = "#{@output}/#{name}.#{@format}"
94
- content = @format == "xml" ? bib.to_xml(bibdata: true) : bib.to_hash.to_yaml
95
- File.write file, content, encoding: "UTF-8"
108
+ "#{@output}/#{name}.#{@ext}"
109
+ end
110
+
111
+ def content(bib)
112
+ case @format
113
+ when "xml" then bib.to_xml bibdata: true
114
+ when "yaml" then bib.to_hash.to_yaml
115
+ when "bibxml" then bib.to_bibxml
116
+ end
96
117
  end
97
118
  end
98
119
  end
@@ -4,76 +4,29 @@ require "fileutils"
4
4
 
5
5
  module RelatonOgc
6
6
  class HitCollection < RelatonBib::HitCollection
7
- # include DataFetcher::Utils
8
-
9
- # ENDPOINT = "https://raw.githubusercontent.com/opengeospatial/"\
10
- # "NamingAuthority/master/incubation/bibliography/"\
11
- # "bibliography.json".freeze
12
- ENDPOINT = "https://raw.githubusercontent.com/relaton/relaton-data-ogc/main/data/".freeze
13
- # DATADIR = File.expand_path ".relaton/ogc/", Dir.home
14
- # DATAFILE = File.expand_path "bibliography.json", DATADIR
15
- # ETAGFILE = File.expand_path "etag.txt", DATADIR
7
+ ENDPOINT = "https://raw.githubusercontent.com/relaton/relaton-data-ogc/main/".freeze
8
+ INDEX_FILE = "index-v1.yaml".freeze
16
9
 
17
10
  # @param code [Strig]
18
11
  # @param year [String]
19
12
  # @param opts [Hash]
20
13
  def initialize(code, year = nil) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
21
14
  super
22
- # @etagfile = File.expand_path "etag.txt", DATADIR
23
- # @array = from_json(ref).sort_by do |hit|
24
- # hit.hit["date"] ? Date.parse(hit.hit["date"]) : Date.new
25
- # rescue ArgumentError
26
- # Date.parse "0000-01-01"
27
- # end.reverse
28
- url = "#{ENDPOINT}#{code.upcase.gsub(/[\s:.]/, '_')}.yaml"
29
- resp = Faraday.get url do |req|
30
- req.options.timeout = 10
31
- end
32
- @array = case resp.status
33
- when 200
34
- hash = YAML.safe_load(resp.body)
35
- hash["fetched"] = Date.today.to_s
36
- bib = OgcBibliographicItem.from_hash hash
37
- [Hit.new(bib, self)]
38
- else []
39
- end
40
- end
41
-
42
- # private
15
+ @array = []
16
+ return if code.nil? || code.empty?
43
17
 
44
- #
45
- # Fetch data form json
46
- #
47
- # @param docid [String]
48
- # def from_json(docid, **_opts)
49
- # ref = docid.sub(/^OGC\s/, "").strip
50
- # return [] if ref.empty?
18
+ index = Relaton::Index.find_or_create :ogc, url: "#{ENDPOINT}index-v1.zip", file: INDEX_FILE
19
+ row = index.search(code).min_by { |r| r[:id] }
20
+ return unless row
51
21
 
52
- # data.select do |_k, doc|
53
- # doc["type"] != "CC" && doc["identifier"].include?(ref)
54
- # end.map { |_k, h| Hit.new(h, self) }
55
- # end
22
+ url = "#{ENDPOINT}#{row[:file]}"
23
+ resp = Faraday.get(url) { |req| req.options.timeout = 10 }
24
+ return unless resp.status == 200
56
25
 
57
- #
58
- # Fetches json data
59
- #
60
- # @return [Hash]
61
- # def data
62
- # ctime = File.ctime DATAFILE if File.exist? DATAFILE
63
- # fetch_data if !ctime || ctime.to_date < Date.today
64
- # @data ||= JSON.parse File.read(DATAFILE, encoding: "UTF-8")
65
- # end
66
-
67
- #
68
- # fetch data form server and save it to file.
69
- #
70
- # def fetch_data
71
- # json = get_data
72
- # return unless json
73
-
74
- # FileUtils.mkdir_p DATADIR unless Dir.exist? DATADIR
75
- # @data = json
76
- # File.write DATAFILE, @data.to_json, encoding: "UTF-8"
77
- # end
26
+ hash = YAML.safe_load(resp.body)
27
+ hash["fetched"] = Date.today.to_s
28
+ bib = OgcBibliographicItem.from_hash hash
29
+ @array = [Hit.new(bib, self)]
30
+ end
78
31
  end
79
32
  end
@@ -47,5 +47,12 @@ module RelatonOgc
47
47
  def grammar_hash
48
48
  @grammar_hash ||= ::RelatonOgc.grammar_hash
49
49
  end
50
+
51
+ #
52
+ # Remove index file
53
+ #
54
+ def remove_index_file
55
+ Relaton::Index.find_or_create(:ogc, url: true, file: HitCollection::INDEX_FILE).remove_file
56
+ end
50
57
  end
51
58
  end
@@ -85,7 +85,7 @@ module RelatonOgc
85
85
  end
86
86
 
87
87
  # @param stage [String]
88
- # @return [RelatonBib::DocumentStatus, NilClass]
88
+ # @return [RelatonBib::DocumentStatus, nil]
89
89
  def fetch_status(stage)
90
90
  stage && RelatonBib::DocumentStatus.new(stage: stage)
91
91
  end
@@ -134,12 +134,14 @@ module RelatonOgc
134
134
  )
135
135
  end
136
136
 
137
- # @param date [String]
137
+ # @param date [String, nil]
138
138
  # @return [Array<RelatonBib::BibliographicDate>]
139
139
  def fetch_date(date)
140
140
  return [] unless date
141
141
 
142
142
  [RelatonBib::BibliographicDate.new(type: "published", on: date)]
143
+ rescue Date::Error
144
+ []
143
145
  end
144
146
  end
145
147
  end
@@ -1,3 +1,3 @@
1
1
  module RelatonOgc
2
- VERSION = "1.14.1".freeze
2
+ VERSION = "1.14.3".freeze
3
3
  end
data/lib/relaton_ogc.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require "relaton/index"
1
2
  require "relaton_iso_bib"
2
3
  require "relaton_ogc/version"
3
4
  require "relaton_ogc/ogc_bibliographic_item"
data/relaton_ogc.gemspec CHANGED
@@ -23,17 +23,9 @@ Gem::Specification.new do |spec|
23
23
  spec.bindir = "exe"
24
24
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
25
  spec.require_paths = ["lib"]
26
- spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
26
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
27
27
 
28
- spec.add_development_dependency "equivalent-xml", "~> 0.6"
29
- spec.add_development_dependency "pry-byebug"
30
- spec.add_development_dependency "rake", "~> 13.0"
31
- spec.add_development_dependency "rspec", "~> 3.0"
32
- spec.add_development_dependency "ruby-jing"
33
- spec.add_development_dependency "simplecov"
34
- spec.add_development_dependency "vcr"
35
- spec.add_development_dependency "webmock"
36
-
37
- spec.add_dependency "faraday", "~> 1.0"
28
+ spec.add_dependency "faraday", "~> 2.7.0"
29
+ spec.add_dependency "relaton-index", "~> 0.2.0"
38
30
  spec.add_dependency "relaton-iso-bib", "~> 1.14.0"
39
31
  end
metadata CHANGED
@@ -1,141 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-ogc
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.14.1
4
+ version: 1.14.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-12-06 00:00:00.000000000 Z
11
+ date: 2023-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: equivalent-xml
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '0.6'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '0.6'
27
- - !ruby/object:Gem::Dependency
28
- name: pry-byebug
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: rake
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '13.0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '13.0'
55
- - !ruby/object:Gem::Dependency
56
- name: rspec
14
+ name: faraday
57
15
  requirement: !ruby/object:Gem::Requirement
58
16
  requirements:
59
17
  - - "~>"
60
18
  - !ruby/object:Gem::Version
61
- version: '3.0'
62
- type: :development
19
+ version: 2.7.0
20
+ type: :runtime
63
21
  prerelease: false
64
22
  version_requirements: !ruby/object:Gem::Requirement
65
23
  requirements:
66
24
  - - "~>"
67
25
  - !ruby/object:Gem::Version
68
- version: '3.0'
26
+ version: 2.7.0
69
27
  - !ruby/object:Gem::Dependency
70
- name: ruby-jing
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: simplecov
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: vcr
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
- - !ruby/object:Gem::Dependency
112
- name: webmock
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- version: '0'
125
- - !ruby/object:Gem::Dependency
126
- name: faraday
28
+ name: relaton-index
127
29
  requirement: !ruby/object:Gem::Requirement
128
30
  requirements:
129
31
  - - "~>"
130
32
  - !ruby/object:Gem::Version
131
- version: '1.0'
33
+ version: 0.2.0
132
34
  type: :runtime
133
35
  prerelease: false
134
36
  version_requirements: !ruby/object:Gem::Requirement
135
37
  requirements:
136
38
  - - "~>"
137
39
  - !ruby/object:Gem::Version
138
- version: '1.0'
40
+ version: 0.2.0
139
41
  - !ruby/object:Gem::Dependency
140
42
  name: relaton-iso-bib
141
43
  requirement: !ruby/object:Gem::Requirement
@@ -200,14 +102,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
200
102
  requirements:
201
103
  - - ">="
202
104
  - !ruby/object:Gem::Version
203
- version: 2.5.0
105
+ version: 2.7.0
204
106
  required_rubygems_version: !ruby/object:Gem::Requirement
205
107
  requirements:
206
108
  - - ">="
207
109
  - !ruby/object:Gem::Version
208
110
  version: '0'
209
111
  requirements: []
210
- rubygems_version: 3.1.6
112
+ rubygems_version: 3.3.26
211
113
  signing_key:
212
114
  specification_version: 4
213
115
  summary: 'RelatonOgc: retrieve OGC Standards for bibliographic use using the OgcBibliographicItem