relaton-ccsds 1.14.0 → 1.16.1

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: de41538113c775736c47d2c576b11e087fd965706cc356d14c29ec9b9ec49294
4
- data.tar.gz: 211bd83661e30589ae435885afc1fac89a9b336c2e9b0abfa4bae75dfcf9722f
3
+ metadata.gz: bb70be3294be3ba408274ff671392077b6be402928798bdf42be8a445d26f281
4
+ data.tar.gz: 64c27dfa9fb804c04e9a4381a68001e18d85af4e467162380ab289db234ad3ef
5
5
  SHA512:
6
- metadata.gz: 602946077b688c1fbf035073d632a1d1abf2b1459261a40b72550b9b3bba7cdcd79bd9a3cbcff3188073ea5afeabee97396822c3b56fa3d1d1f47e4747fe3489
7
- data.tar.gz: 450a9e0b4fa07ebcd2bdd75637423fda646ae5dd3899b9ef5fb4063eb6e42fa861997938bb0f9829e076c71616bc6a0249241684838dcbd214fd60093dff011a
6
+ metadata.gz: b33be383d1200e0a976a5d3c48a296cd957314baf342299e712ea7e606eb23d123e91a08dcd3a6b0c17f808ac156e8a97352413900c34281e29a784ad8768625
7
+ data.tar.gz: 8fb7ee5bf02d2b3590cc2b9badb9f0e5a7de8da197d055936f8611158ca772af7d3b3c9f53f1eb6c3a0b3fac7583647875f37e77ef7b03cfdfa521f3d3be720e
data/README.adoc CHANGED
@@ -43,7 +43,7 @@ item = hits[0].fetch
43
43
  [source,ruby]
44
44
  ----
45
45
  item.to_xml
46
- => "<bibitem id="CCSDS230.2-G-1" schema-version="v1.2.3">
46
+ => "<bibitem id="CCSDS230.2-G-1" schema-version="v1.2.4">
47
47
  <fetched>2023-08-25</fetched>
48
48
  <title format="text/plain" language="en" script="Latn">Next Generation Uplink</title>
49
49
  <uri type="pdf">https://public.ccsds.org/Pubs/230x2g1.pdf</uri>
@@ -55,7 +55,7 @@ With argument `bibdata: true` it outputs XML wrapped by `bibdata` element and ad
55
55
  [source,ruby]
56
56
  ----
57
57
  item.to_xml bibdata: true
58
- => "<bibdata schema-version="v1.2.3">
58
+ => "<bibdata schema-version="v1.2.4">
59
59
  <fetched>2023-08-25</fetched>
60
60
  <title format="text/plain" language="en" script="Latn">Next Generation Uplink</title>
61
61
  <uri type="pdf">https://public.ccsds.org/Pubs/230x2g1.pdf</uri>
@@ -120,7 +120,7 @@ RelatonCcsds::XMLParser.from_xml File.read('spec/fixtures/ccsds_230_2-g-1.xml')
120
120
  [source,ruby]
121
121
  ----
122
122
  hash = YAML.load_file 'spec/fixtures/ccsds_230_2-g-1.yaml'
123
- => {"schema-version"=>"v1.2.3",
123
+ => {"schema-version"=>"v1.2.4",
124
124
  "id"=>"CCSDS230.2-G-1",
125
125
  ...
126
126
 
data/grammars/biblio.rng CHANGED
@@ -1283,7 +1283,7 @@
1283
1283
  <value>mergedInto</value>
1284
1284
  <value>splits</value>
1285
1285
  <value>splitInto</value>
1286
- <value>instance</value>
1286
+ <value>instanceOf</value>
1287
1287
  <value>hasInstance</value>
1288
1288
  <value>exemplarOf</value>
1289
1289
  <value>hasExemplar</value>
@@ -37,7 +37,7 @@ module RelatonCcsds
37
37
  end
38
38
 
39
39
  # @return [Hash]
40
- def to_hash
40
+ def to_hash(embedded: false)
41
41
  hash = super
42
42
  if technology_area
43
43
  hash["ext"] ||= {}
@@ -15,6 +15,8 @@ module RelatonCcsds
15
15
  FileRef,ISO_x0020_Number,Patents,Extra_x0020_Link,Area,calHtmlColorCode&$filter=Book_x0020_Type%20eq%20%27Silver%20Book%27
16
16
  URL
17
17
 
18
+ TRRGX = /\s-\s\w+\sTranslated$/.freeze
19
+
18
20
  def initialize(output, format)
19
21
  @output = output
20
22
  @format = format
@@ -68,18 +70,64 @@ module RelatonCcsds
68
70
  end
69
71
 
70
72
  def save_bib(bib)
73
+ search_translation bib
71
74
  id = bib.docidentifier.first.id
72
- file = File.join @output, "#{id.gsub(/[.\s]+/, '-')}.#{@ext}"
73
- if @files.include? file
75
+ file = File.join @output, "#{id.gsub(/[.\s-]+/, '-')}.#{@ext}"
76
+ if @files.include?(file)
74
77
  puts "(#{file}) file already exists. Trying to merge links ..."
75
78
  merge_links bib, file
76
- else
77
- @files << file
79
+ else @files << file
78
80
  end
79
81
  File.write file, content(bib), encoding: "UTF-8"
80
82
  index.add_or_update id, file
81
83
  end
82
84
 
85
+ def search_translation(bib) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
86
+ bibid = bib.docidentifier.first.id.dup
87
+ if bibid.sub!(TRRGX, "")
88
+ index.search do |row|
89
+ id = row[:id].sub(TRRGX, "")
90
+ next if id != bibid || row[:id] == bib.docidentifier.first.id
91
+
92
+ create_translation_relation bib, row[:file]
93
+ end
94
+ else
95
+ index.search do |row|
96
+ next unless row[:id].match?(/^#{bibid}#{TRRGX}/)
97
+
98
+ create_instance_relation bib, row[:file]
99
+ end
100
+ end
101
+ end
102
+
103
+ def create_translation_relation(bib, file) # rubocop:disable Metrics/MethodLength
104
+ hash = YAML.load_file file
105
+ inst = BibliographicItem.from_hash hash
106
+ if inst.docidentifier.first.id.match?(TRRGX)
107
+ type1 = type2 = "hasTranslation"
108
+ else
109
+ type1 = "instanceOf"
110
+ type2 = "hasInstance"
111
+ end
112
+ create_relation(bib, inst, type1)
113
+ create_relation(inst, bib, type2)
114
+ File.write file, content(inst), encoding: "UTF-8"
115
+ end
116
+
117
+ def create_instance_relation(bib, file)
118
+ hash = YAML.load_file file
119
+ inst = BibliographicItem.from_hash hash
120
+ create_relation bib, inst, "hasInstance"
121
+ create_relation inst, bib, "instanceOf"
122
+ File.write file, content(inst), encoding: "UTF-8"
123
+ end
124
+
125
+ def create_relation(bib1, bib2, type)
126
+ fref = RelatonBib::FormattedRef.new content: bib2.docidentifier.first.id
127
+ rel = BibliographicItem.new docid: bib2.docidentifier, formattedref: fref
128
+ bib1.relation << RelatonBib::DocumentRelation.new(type: type, bibitem: rel)
129
+ end
130
+
83
131
  def merge_links(bib, file) # rubocop:disable Metrics/AbcSize
84
132
  hash = YAML.load_file file
85
133
  bib2 = BibliographicItem.from_hash hash
@@ -76,13 +76,13 @@ module RelatonCcsds
76
76
  end
77
77
 
78
78
  def parse_edition
79
- @doc["Issue_x0020_Number"]
79
+ @doc["Issue_x0020_Number"].match(/^\d+/)&.to_s
80
80
  end
81
81
 
82
82
  def parse_relation
83
83
  @docs.each_with_object(successor + adopted) do |d, a|
84
84
  id = docidentifier d["Document_x0020_Number"].strip
85
- type = relaton_type id
85
+ type = relation_type id
86
86
  next unless type
87
87
 
88
88
  a << create_relation(type, id)
@@ -104,12 +104,14 @@ module RelatonCcsds
104
104
  [create_relation("hasSuccessor", @successor.docidentifier[0].id)]
105
105
  end
106
106
 
107
- def relaton_type(rel_id)
108
- same = rel_id == docidentifier
109
- if rel_id.include?(docidentifier) && !same
110
- "hasEdition"
111
- elsif docidentifier.include?(rel_id) && !same
112
- "editionOf"
107
+ def relation_type(rel_id)
108
+ return if rel_id == docidentifier ||
109
+ rel_id.match(DataFetcher::TRRGX).to_s != docidentifier.match(DataFetcher::TRRGX).to_s
110
+
111
+ if rel_id.include?(docidentifier.sub(DataFetcher::TRRGX, ""))
112
+ "updatedBy"
113
+ elsif docidentifier.include?(rel_id.sub(DataFetcher::TRRGX, ""))
114
+ "updates"
113
115
  end
114
116
  end
115
117
 
@@ -54,7 +54,7 @@ module RelatonCcsds
54
54
  # Remove index file
55
55
  #
56
56
  def remove_index_file
57
- Relaton::Index.find_or_create(:CC, url: true, file: HitCollection::INDEX_FILE).remove_file
57
+ Relaton::Index.find_or_create(:ccsds, url: true, file: HitCollection::INDEX_FILE).remove_file
58
58
  end
59
59
  end
60
60
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RelatonCcsds
4
- VERSION = "1.14.0"
4
+ VERSION = "1.16.1"
5
5
  end
data/lib/relaton_ccsds.rb CHANGED
@@ -20,9 +20,9 @@ module RelatonCcsds
20
20
  # Your code goes here...
21
21
 
22
22
  def self.grammar_hash
23
- gem_path = File.expand_path "..", __dir__
24
- grammars_path = File.join gem_path, "grammars", "*"
25
- grammars = Dir[grammars_path].sort.map { |gp| File.read gp }.join
26
- Digest::MD5.hexdigest grammars
23
+ # gem_path = File.expand_path "..", __dir__
24
+ # grammars_path = File.join gem_path, "grammars", "*"
25
+ # grammars = Dir[grammars_path].sort.map { |gp| File.read gp }.join
26
+ Digest::MD5.hexdigest RelatonCcsds::VERSION + RelatonBib::VERSION # grammars
27
27
  end
28
28
  end
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
25
25
 
26
26
  # Uncomment to register a new dependency of your gem
27
27
  spec.add_dependency "mechanize", "~> 2.7"
28
- spec.add_dependency "relaton-bib", "~> 1.14.13"
28
+ spec.add_dependency "relaton-bib", "~> 1.16.0"
29
29
  spec.add_dependency "relaton-index", "~> 0.2.0"
30
30
 
31
31
  # For more information and examples about making a new gem, check out our
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-ccsds
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.14.0
4
+ version: 1.16.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-08-26 00:00:00.000000000 Z
11
+ date: 2023-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mechanize
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 1.14.13
33
+ version: 1.16.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 1.14.13
40
+ version: 1.16.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: relaton-index
43
43
  requirement: !ruby/object:Gem::Requirement