relaton-ccsds 1.16.1 → 1.16.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.adoc +53 -7
- data/lib/relaton_ccsds/bibliographic_item.rb +9 -1
- data/lib/relaton_ccsds/bibliography.rb +11 -7
- data/lib/relaton_ccsds/data_fetcher.rb +136 -26
- data/lib/relaton_ccsds/version.rb +1 -1
- metadata +2 -3
- data/.vscode/launch.json +0 -40
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 04acb04f4b67b4c455bbf9406090419eb77c3ad03c7f0cd44c0c83e19c6a2bba
|
4
|
+
data.tar.gz: 37a89024ff34103d7e36d5d554ae30d27a6d306bb0448caea2363e94d3603420
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 859719c12454ad67c2b1614ac4ff9c65bb2b1b7d0abcb1c778ff8b593441f715ed26ad0af1084f95beff4531a84ff76b2a305124112838d5232bc74e0fb2b624
|
7
|
+
data.tar.gz: 777d29e9a4e150220bcc75836cbc9f5dab248bc0a07a17c0b86632752d9227e09fec328074f14a163c5ed005dbe33c7cd2d971dae55c7bab5f68be8f1286f3a9
|
data/.gitignore
CHANGED
data/README.adoc
CHANGED
@@ -23,17 +23,28 @@ Or install it yourself as:
|
|
23
23
|
|
24
24
|
== Usage
|
25
25
|
|
26
|
-
===
|
26
|
+
=== Configuration
|
27
|
+
|
28
|
+
Configuration is optional. The available option is `logger` which is a `Logger` instance. By default, the logger is `Logger.new($stderr)` with `Logger::WARN` level. To change the logger level, use `RelatonCcsds.configure` block.
|
27
29
|
|
28
30
|
[source,ruby]
|
29
31
|
----
|
30
32
|
require 'relaton_ccsds'
|
31
33
|
=> true
|
32
34
|
|
35
|
+
RelatonCcsds.configure do |config|
|
36
|
+
config.logger.level = Logger::DEBUG
|
37
|
+
end
|
38
|
+
----
|
39
|
+
|
40
|
+
=== Search for a standard using keywords
|
41
|
+
|
42
|
+
[source,ruby]
|
43
|
+
----
|
33
44
|
hits = RelatonCcsds::Bibliography.search("CCSDS 230.2-G-1")
|
34
45
|
=> <RelatonCcsds::HitCollection:0x00000000001770 @ref=CCSDS 230.2-G-1 @fetched=false>
|
35
46
|
|
36
|
-
item = hits[0].
|
47
|
+
item = hits[0].doc
|
37
48
|
=> #<RelatonCcsds::BibliographicItem:0x00000001135f6540
|
38
49
|
...
|
39
50
|
----
|
@@ -83,9 +94,9 @@ item.link
|
|
83
94
|
@script=nil,
|
84
95
|
@type="pdf">]
|
85
96
|
|
86
|
-
|
87
|
-
[relaton-ccsd] (CCSDS 720.6-Y-1)
|
88
|
-
[relaton-ccsd] (CCSDS 720.6-Y-1)
|
97
|
+
RelatonCcsds::Bibliography.get("CCSDS 720.6-Y-1").link
|
98
|
+
[relaton-ccsd] (CCSDS 720.6-Y-1) Fetching from Relaton repository ...
|
99
|
+
[relaton-ccsd] (CCSDS 720.6-Y-1) Found: `CCSDS 720.6-Y-1`.
|
89
100
|
=> [#<RelatonBib::TypedUri:0x0000000114183bb0
|
90
101
|
@content=#<Addressable::URI:0xca8 URI:https://public.ccsds.org/Pubs/720x6y1.pdf>,
|
91
102
|
@language=nil,
|
@@ -102,12 +113,47 @@ item.link
|
|
102
113
|
[source,ruby]
|
103
114
|
----
|
104
115
|
RelatonCcsds::Bibliography.get("CCSDS 230.2-G-1")
|
105
|
-
[relaton-ccsd] (CCSDS 230.2-G-1)
|
106
|
-
[relaton-ccsd] (CCSDS 230.2-G-1)
|
116
|
+
[relaton-ccsd] (CCSDS 230.2-G-1) Fetching from Relaton repository ...
|
117
|
+
[relaton-ccsd] (CCSDS 230.2-G-1) Found: `CCSDS 230.2-G-1`.
|
107
118
|
=> #<RelatonCcsds::BibliographicItem:0x00000001135dade0
|
108
119
|
...
|
109
120
|
----
|
110
121
|
|
122
|
+
=== Get specific format
|
123
|
+
|
124
|
+
[source,ruby]
|
125
|
+
----
|
126
|
+
item = RelatonCcsds::Bibliography.get("CCSDS 720.4-Y-1 (DOC)")
|
127
|
+
[relaton-ccsd] (CCSDS 720.4-Y-1 (DOC)) Fetching from Relaton repository ...
|
128
|
+
[relaton-ccsd] (CCSDS 720.4-Y-1 (DOC)) Found: `CCSDS 720.4-Y-1`.
|
129
|
+
=> #<RelatonCcsds::BibliographicItem:0x000000011100dfe0
|
130
|
+
...
|
131
|
+
|
132
|
+
item.link.size
|
133
|
+
=> 1
|
134
|
+
|
135
|
+
item.link[0].type
|
136
|
+
=> "doc"
|
137
|
+
|
138
|
+
pry(main)> item.link[0].content.to_s
|
139
|
+
=> "https://public.ccsds.org/Pubs/720x4y1.doc"
|
140
|
+
|
141
|
+
item = RelatonCcsds::Bibliography.get("CCSDS 720.4-Y-1 (PDF)")
|
142
|
+
[relaton-ccsd] (CCSDS 720.4-Y-1 (PDF)) Fetching from Relaton repository ...
|
143
|
+
[relaton-ccsd] (CCSDS 720.4-Y-1 (PDF)) Found: `CCSDS 720.4-Y-1`.
|
144
|
+
=> #<RelatonCcsds::BibliographicItem:0x0000000111004620
|
145
|
+
...
|
146
|
+
|
147
|
+
item.link.size
|
148
|
+
=> 1
|
149
|
+
|
150
|
+
item.link[0].type
|
151
|
+
=> "pdf"
|
152
|
+
|
153
|
+
item.link[0].content.to_s
|
154
|
+
=> "https://public.ccsds.org/Pubs/720x4y1.pdf"
|
155
|
+
----
|
156
|
+
|
111
157
|
=== Create bibliographic item from XML
|
112
158
|
[source,ruby]
|
113
159
|
----
|
@@ -7,7 +7,7 @@ module RelatonCcsds
|
|
7
7
|
# @param technology_area [String, nil]
|
8
8
|
def initialize(**args)
|
9
9
|
if args[:doctype] && !DOCTYPES.include?(args[:doctype])
|
10
|
-
Util.warn "WARNING:
|
10
|
+
Util.warn "WARNING: Invalid doctype: `#{args[:doctype]}`"
|
11
11
|
end
|
12
12
|
@technology_area = args.delete(:technology_area)
|
13
13
|
super
|
@@ -45,5 +45,13 @@ module RelatonCcsds
|
|
45
45
|
end
|
46
46
|
hash
|
47
47
|
end
|
48
|
+
|
49
|
+
def to_format(format)
|
50
|
+
return self unless format
|
51
|
+
|
52
|
+
me = deep_clone
|
53
|
+
me.link.select! { |l| l.type.casecmp(format).zero? }
|
54
|
+
me if me.link.any?
|
55
|
+
end
|
48
56
|
end
|
49
57
|
end
|
@@ -15,22 +15,26 @@ module RelatonCcsds
|
|
15
15
|
|
16
16
|
#
|
17
17
|
# Get CCSDS standard by document reference.
|
18
|
+
# If format is not specified, then all format will be returned.
|
18
19
|
#
|
19
|
-
# @param
|
20
|
+
# @param reference [String]
|
20
21
|
# @param year [String, nil]
|
21
22
|
# @param opts [Hash]
|
23
|
+
# @option opts [String] :format format of fetched document (DOC, PDF)
|
22
24
|
#
|
23
25
|
# @return [RelatonCcsds::BibliographicItem]
|
24
26
|
#
|
25
|
-
def get(
|
26
|
-
|
27
|
+
def get(reference, _year = nil, opts = {}) # rubocop:disable Metrics/MethodLength
|
28
|
+
ref = reference.sub(/\s\((DOC|PDF)\)$/, "")
|
29
|
+
opts[:format] ||= Regexp.last_match(1)
|
30
|
+
Util.warn "(#{reference}) Fetching from Relaton repository ..."
|
27
31
|
hits = search ref
|
28
|
-
|
29
|
-
|
32
|
+
doc = hits.first&.doc&.to_format(opts[:format])
|
33
|
+
unless doc
|
34
|
+
Util.warn "(#{reference}) Not found."
|
30
35
|
return nil
|
31
36
|
end
|
32
|
-
|
33
|
-
Util.warn "(#{ref}) found `#{hits.first.code}`."
|
37
|
+
Util.warn "(#{reference}) Found: `#{hits.first.code}`."
|
34
38
|
doc
|
35
39
|
end
|
36
40
|
end
|
@@ -17,6 +17,12 @@ module RelatonCcsds
|
|
17
17
|
|
18
18
|
TRRGX = /\s-\s\w+\sTranslated$/.freeze
|
19
19
|
|
20
|
+
#
|
21
|
+
# Initialize fetcher
|
22
|
+
#
|
23
|
+
# @param [String] output path to output directory
|
24
|
+
# @param [String] format output format (yaml, xml, bibxml)
|
25
|
+
#
|
20
26
|
def initialize(output, format)
|
21
27
|
@output = output
|
22
28
|
@format = format
|
@@ -36,6 +42,14 @@ module RelatonCcsds
|
|
36
42
|
@index ||= Relaton::Index.find_or_create "CCSDS", file: "index-v1.yaml"
|
37
43
|
end
|
38
44
|
|
45
|
+
#
|
46
|
+
# Create fetcher instance and fetch data
|
47
|
+
#
|
48
|
+
# @param [String] output path to output directory (default: "data")
|
49
|
+
# @param [String] format output format (yaml, xml, bibxml) (default: "yaml")
|
50
|
+
#
|
51
|
+
# @return [void]
|
52
|
+
#
|
39
53
|
def self.fetch(output: "data", format: "yaml")
|
40
54
|
t1 = Time.now
|
41
55
|
puts "Started at: #{t1}"
|
@@ -52,6 +66,14 @@ module RelatonCcsds
|
|
52
66
|
index.save
|
53
67
|
end
|
54
68
|
|
69
|
+
#
|
70
|
+
# Fetch documents from url
|
71
|
+
#
|
72
|
+
# @param [String] url
|
73
|
+
# @param [Boolean] retired if true, then fetch retired documents
|
74
|
+
#
|
75
|
+
# @return [void]
|
76
|
+
#
|
55
77
|
def fetch_docs(url, retired: false)
|
56
78
|
resp = agent.get(url)
|
57
79
|
json = JSON.parse resp.body
|
@@ -60,6 +82,15 @@ module RelatonCcsds
|
|
60
82
|
end
|
61
83
|
end
|
62
84
|
|
85
|
+
#
|
86
|
+
# Parse document and save to file
|
87
|
+
#
|
88
|
+
# @param [Hash] doc document data
|
89
|
+
# @param [Array<Hash>] results collection of documents
|
90
|
+
# @param [Boolean] retired if true then document is retired
|
91
|
+
#
|
92
|
+
# @return [void]
|
93
|
+
#
|
63
94
|
def parse_and_save(doc, results, retired)
|
64
95
|
bibitem = DataParser.new(doc, results).parse
|
65
96
|
if retired
|
@@ -69,8 +100,15 @@ module RelatonCcsds
|
|
69
100
|
save_bib bibitem
|
70
101
|
end
|
71
102
|
|
103
|
+
#
|
104
|
+
# Save bibitem to file
|
105
|
+
#
|
106
|
+
# @param [RelatonCcsds::BibliographicItem] bib bibitem
|
107
|
+
#
|
108
|
+
# @return [void]
|
109
|
+
#
|
72
110
|
def save_bib(bib)
|
73
|
-
|
111
|
+
search_instance_translation bib
|
74
112
|
id = bib.docidentifier.first.id
|
75
113
|
file = File.join @output, "#{id.gsub(/[.\s-]+/, '-')}.#{@ext}"
|
76
114
|
if @files.include?(file)
|
@@ -82,52 +120,117 @@ module RelatonCcsds
|
|
82
120
|
index.add_or_update id, file
|
83
121
|
end
|
84
122
|
|
85
|
-
|
123
|
+
#
|
124
|
+
# Search translation and instance relation
|
125
|
+
#
|
126
|
+
# @param [RelatonCcsds::BibliographicItem] bib <description>
|
127
|
+
#
|
128
|
+
# @return [void]
|
129
|
+
#
|
130
|
+
def search_instance_translation(bib)
|
86
131
|
bibid = bib.docidentifier.first.id.dup
|
87
132
|
if bibid.sub!(TRRGX, "")
|
88
|
-
|
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
|
133
|
+
search_relations bibid, bib
|
94
134
|
else
|
95
|
-
|
96
|
-
|
135
|
+
search_translations bibid, bib
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
#
|
140
|
+
# Search instance or translation relation
|
141
|
+
#
|
142
|
+
# @param [String] bibid instance bibitem id
|
143
|
+
# @param [RelatonCcsds::BibliographicItem] bib instance or translation bibitem
|
144
|
+
#
|
145
|
+
# @return [void]
|
146
|
+
#
|
147
|
+
def search_relations(bibid, bib)
|
148
|
+
index.search do |row|
|
149
|
+
id = row[:id].sub(TRRGX, "")
|
150
|
+
next if id != bibid || row[:id] == bib.docidentifier.first.id
|
151
|
+
|
152
|
+
create_relations bib, row[:file]
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
def search_translations(bibid, bib)
|
157
|
+
index.search do |row|
|
158
|
+
next unless row[:id].match?(/^#{bibid}#{TRRGX}/)
|
97
159
|
|
98
|
-
|
99
|
-
end
|
160
|
+
create_instance_relation bib, row[:file]
|
100
161
|
end
|
101
162
|
end
|
102
163
|
|
103
|
-
|
164
|
+
#
|
165
|
+
# Create translation or instance relation and save to file
|
166
|
+
#
|
167
|
+
# @param [RelatonCcsds::BibliographicItem] bib bibliographic item
|
168
|
+
# @param [String] file translation or instance file
|
169
|
+
#
|
170
|
+
# @return [void]
|
171
|
+
#
|
172
|
+
def create_relations(bib, file)
|
104
173
|
hash = YAML.load_file file
|
105
174
|
inst = BibliographicItem.from_hash hash
|
106
|
-
|
107
|
-
|
175
|
+
type1, type2 = translation_relation_types(inst)
|
176
|
+
bib.relation << create_relation(inst, type1)
|
177
|
+
inst.relation << create_relation(bib, type2)
|
178
|
+
File.write file, content(inst), encoding: "UTF-8"
|
179
|
+
end
|
180
|
+
|
181
|
+
#
|
182
|
+
# Translation or instance relation types
|
183
|
+
#
|
184
|
+
# @param [RelatonCcsds::BibliographicItem] bib bibliographic item
|
185
|
+
#
|
186
|
+
# @return [Array<String>] relation types
|
187
|
+
#
|
188
|
+
def translation_relation_types(bib)
|
189
|
+
if bib.docidentifier.first.id.match?(TRRGX)
|
190
|
+
["hasTranslation"] * 2
|
108
191
|
else
|
109
|
-
|
110
|
-
type2 = "hasInstance"
|
192
|
+
["instanceOf", "hasInstance"]
|
111
193
|
end
|
112
|
-
create_relation(bib, inst, type1)
|
113
|
-
create_relation(inst, bib, type2)
|
114
|
-
File.write file, content(inst), encoding: "UTF-8"
|
115
194
|
end
|
116
195
|
|
196
|
+
#
|
197
|
+
# Create instance relation and save to file
|
198
|
+
#
|
199
|
+
# @param [RelatonCcsds::BibliographicItem] bib bibliographic item
|
200
|
+
# @param [String] file file name
|
201
|
+
#
|
202
|
+
# @return [void]
|
203
|
+
#
|
117
204
|
def create_instance_relation(bib, file)
|
118
205
|
hash = YAML.load_file file
|
119
206
|
inst = BibliographicItem.from_hash hash
|
120
|
-
|
121
|
-
|
207
|
+
bib.relation << create_relation(inst, "hasInstance")
|
208
|
+
inst.relation << create_relation(bib, "instanceOf")
|
122
209
|
File.write file, content(inst), encoding: "UTF-8"
|
123
210
|
end
|
124
211
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
212
|
+
#
|
213
|
+
# Create relation
|
214
|
+
#
|
215
|
+
# @param [RelatonCcsds::BibliographicItem] bib the related bibliographic item
|
216
|
+
# @param [String] type type of relation
|
217
|
+
#
|
218
|
+
# @return [RelatonBib::DocumentRelation] relation
|
219
|
+
#
|
220
|
+
def create_relation(bib, type)
|
221
|
+
fref = RelatonBib::FormattedRef.new content: bib.docidentifier.first.id
|
222
|
+
rel = BibliographicItem.new docid: bib.docidentifier, formattedref: fref
|
223
|
+
RelatonBib::DocumentRelation.new(type: type, bibitem: rel)
|
129
224
|
end
|
130
225
|
|
226
|
+
#
|
227
|
+
# Merge identical documents with different links (updaes given bibitem)
|
228
|
+
#
|
229
|
+
# @param [RelatonCcsds::BibliographicItem] bib bibliographic item
|
230
|
+
# @param [String] file path to existing document
|
231
|
+
#
|
232
|
+
# @return [void]
|
233
|
+
#
|
131
234
|
def merge_links(bib, file) # rubocop:disable Metrics/AbcSize
|
132
235
|
hash = YAML.load_file file
|
133
236
|
bib2 = BibliographicItem.from_hash hash
|
@@ -139,6 +242,13 @@ module RelatonCcsds
|
|
139
242
|
bib.link << bib2.link[0]
|
140
243
|
end
|
141
244
|
|
245
|
+
#
|
246
|
+
# Srerialize bibliographic item
|
247
|
+
#
|
248
|
+
# @param [RelatonCcsds::BibliographicItem] bib <description>
|
249
|
+
#
|
250
|
+
# @return [String] serialized bibliographic item
|
251
|
+
#
|
142
252
|
def content(bib)
|
143
253
|
case @format
|
144
254
|
when "yaml" then bib.to_hash.to_yaml
|
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.16.
|
4
|
+
version: 1.16.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: 2023-
|
11
|
+
date: 2023-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mechanize
|
@@ -64,7 +64,6 @@ files:
|
|
64
64
|
- ".gitignore"
|
65
65
|
- ".rspec"
|
66
66
|
- ".rubocop.yml"
|
67
|
-
- ".vscode/launch.json"
|
68
67
|
- Gemfile
|
69
68
|
- README.adoc
|
70
69
|
- Rakefile
|
data/.vscode/launch.json
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
{
|
2
|
-
// Use IntelliSense to learn about possible attributes.
|
3
|
-
// Hover to view descriptions of existing attributes.
|
4
|
-
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
5
|
-
"version": "0.2.0",
|
6
|
-
"configurations": [
|
7
|
-
{
|
8
|
-
"name": "RSpec - all",
|
9
|
-
"type": "Ruby",
|
10
|
-
"request": "launch",
|
11
|
-
"program": "${workspaceRoot}/bin/rspec",
|
12
|
-
"args": [
|
13
|
-
"-I",
|
14
|
-
"${workspaceRoot}"
|
15
|
-
]
|
16
|
-
},
|
17
|
-
{
|
18
|
-
"name": "RSpec - file only",
|
19
|
-
"type": "Ruby",
|
20
|
-
"request": "launch",
|
21
|
-
"program": "${workspaceRoot}/bin/rspec",
|
22
|
-
"args": [
|
23
|
-
"-I",
|
24
|
-
"${workspaceRoot}",
|
25
|
-
"${file}"
|
26
|
-
]
|
27
|
-
},
|
28
|
-
{
|
29
|
-
"name": "RSpec - line only",
|
30
|
-
"type": "Ruby",
|
31
|
-
"request": "launch",
|
32
|
-
"program": "${workspaceRoot}/bin/rspec",
|
33
|
-
"args": [
|
34
|
-
"-I",
|
35
|
-
"${workspaceRoot}",
|
36
|
-
"${file}:${lineNumber}"
|
37
|
-
]
|
38
|
-
}
|
39
|
-
]
|
40
|
-
}
|