relaton-nist 1.9.4 → 1.9.6

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: 847b161ffdf47b18befc71b090e2397e815594f4c20820b057c93608d171487f
4
- data.tar.gz: 73748bbb1ff975876b6346f24a89ec235f4224d61aa4f714e13b8b981ece81cd
3
+ metadata.gz: c8d36c40a2b5307192f8d25cc103cbb5f08e0b21a0a88940c8e7688417c01f4d
4
+ data.tar.gz: '048f67e6cb6835f382973576d8c97048a7462a512d7b5f8469bed3af07ec594f'
5
5
  SHA512:
6
- metadata.gz: 57640ab1c61feddcf2ac798128d46aff89b190670efa11b624afe9270c94c832c4f53b1cae07dc44f2d189d14b828c1ef1cd1b55d40ac5b94bd65954cd875efa
7
- data.tar.gz: 8df687fcfae413e7efa74d6fbe1fbda4835d61b2c6e3751629365497e83e5f288ec5dcebce0b4472193b81a734d5f401babf1472c212370cfc817b8bc7d130bc
6
+ metadata.gz: e70ce8ef01f291b254e095c33ba639cfc8fcf23736357b1eed465498fc989f101fe1d05fc031726498b917f6bd227a6a3d7e1171d18ef455f693452da48a3495
7
+ data.tar.gz: f9e38480b0c3d73d48485988f86350cd50378489814328622cd7cf6da592056870ca74779feae53a607f737aa4fa2f5f8ae1323450f358d782133d9f48b6c6a1
@@ -11,6 +11,8 @@ module RelatonNist
11
11
  "isTranslationOf" => "translatedFrom",
12
12
  "hasPreprint" => "hasReprint",
13
13
  "isSupplementTo" => "complements",
14
+ "isPartOf" => "partOf",
15
+ "hasPart" => "hasPart",
14
16
  }.freeze
15
17
  URL = "https://raw.githubusercontent.com/usnistgov/NIST-Tech-Pubs/nist-pages/xml/allrecords.xml"
16
18
 
@@ -20,17 +22,32 @@ module RelatonNist
20
22
  @ext = format.sub(/^bib/, "")
21
23
  end
22
24
 
23
- def parse_docid(doc)
24
- doi = doc.at("doi_data/doi").text
25
- id = doc.at("publisher_item/item_number", "publisher_item/identifier").text.sub(%r{^/}, "")
26
- case doi
27
- when "10.6028/NBS.CIRC.12e2revjune" then id.sub!("13e", "12e")
28
- when "10.6028/NBS.CIRC.36e2" then id.sub!("46e", "36e")
29
- when "10.6028/NBS.HB.67suppJune1967" then id.sub!("1965", "1967")
30
- when "10.6028/NBS.HB.105-1r1990" then id.sub!("105-1-1990", "105-1r1990")
31
- when "10.6028/NIST.HB.150-10-1995" then id.sub!(/150-10$/, "150-10-1995")
32
- end
33
- [{ type: "NIST", id: id }, { type: "DOI", id: doi }]
25
+ def parse_docid(doc) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
26
+ # case doi
27
+ # when "10.6028/NBS.CIRC.12e2revjune" then doi.sub!("13e", "12e")
28
+ # when "10.6028/NBS.CIRC.36e2" then doi.sub!("46e", "36e")
29
+ # when "10.6028/NBS.HB.67suppJune1967" then doi.sub!("1965", "1967")
30
+ # when "10.6028/NBS.HB.105-1r1990" then doi.sub!("105-1-1990", "105-1r1990")
31
+ # when "10.6028/NIST.HB.150-10-1995" then doi.sub!(/150-10$/, "150-10-1995")
32
+ # end
33
+ # anchor = doi.split("/")[1..-1].join "/"
34
+ [
35
+ { type: "NIST", id: pub_id(doc) },
36
+ { type: "DOI", id: doi(doc) },
37
+ { type: "NIST", id: anchor(doc), scope: "anchor" },
38
+ ]
39
+ end
40
+
41
+ def pub_id(doc)
42
+ anchor(doc).gsub(".", " ")
43
+ end
44
+
45
+ def doi(doc)
46
+ doc.at("doi_data/doi").text
47
+ end
48
+
49
+ def anchor(doc)
50
+ doi(doc).split("/")[1..-1].join "/"
34
51
  end
35
52
 
36
53
  # @param doc [Nokogiri::XML::Element]
@@ -47,7 +64,7 @@ module RelatonNist
47
64
  t = doc.xpath("titles/title|titles/subtitle")
48
65
  return [] unless t.any?
49
66
 
50
- RelatonBib::TypedTitleString.from_string t.map(&:text).join(" "), "en", "Latn"
67
+ RelatonBib::TypedTitleString.from_string t.map(&:text).join, "en", "Latn"
51
68
  end
52
69
 
53
70
  # @param doc [Nokogiri::XML::Element]
@@ -76,12 +93,11 @@ module RelatonNist
76
93
  def fetch_relation(doc)
77
94
  ns = "http://www.crossref.org/relations.xsd"
78
95
  doc.xpath("./ns:program/ns:related_item", ns: ns).map do |rel|
79
- doi = rel.at_xpath("ns:intra_work_relation|ns:inter_work_relation", ns: ns)
80
- # ref = doi_to_id doi.text
81
- # ref, = parse_docid doc
82
- fref = RelatonBib::FormattedRef.new content: doi.text
96
+ rdoi = rel.at_xpath("ns:intra_work_relation|ns:inter_work_relation", ns: ns)
97
+ fref = RelatonBib::FormattedRef.new content: rdoi.text
83
98
  bibitem = RelatonBib::BibliographicItem.new formattedref: fref
84
- type = RELATION_TYPES[doi["relationship-type"]]
99
+ type = RELATION_TYPES[rdoi["relationship-type"]]
100
+ warn "Relation type #{rdoi['relationship-type']} not found" unless type
85
101
  { type: type, bibitem: bibitem }
86
102
  end
87
103
  end
@@ -123,22 +139,42 @@ module RelatonNist
123
139
  fullname = RelatonBib::FullName.new(
124
140
  surname: surname, forename: forename, initial: initial, identifier: ident,
125
141
  )
126
- person = RelatonBib::Person.new name: fullname
142
+ person = RelatonBib::Person.new name: fullname, affiliation: affiliation(doc)
127
143
  { entity: person, role: [{ type: p["contributor_role"] }] }
128
144
  end
129
145
  contribs + doc.xpath("publisher").map do |p|
130
146
  abbr = p.at("../institution/institution_acronym")&.text
131
- org = RelatonBib::Organization.new(name: p.at("publisher_name").text, abbreviation: abbr)
147
+ place = p.at("./publisher_place")
148
+ cont = []
149
+ if place
150
+ city, state = place.text.split(", ")
151
+ cont << RelatonBib::Address.new(street: [], city: city, state: state, country: "US")
152
+ end
153
+ org = RelatonBib::Organization.new(
154
+ name: p.at("publisher_name").text, abbreviation: abbr, contact: cont,
155
+ )
132
156
  { entity: org, role: [{ type: "publisher" }] }
133
157
  end
134
158
  end
135
159
 
160
+ def affiliation(doc)
161
+ doc.xpath("./institution/institution_department").map do |id|
162
+ org = RelatonBib::Organization.new name: id.text
163
+ RelatonBib::Affiliation.new organization: org
164
+ end
165
+ end
166
+
136
167
  # @param doc [Nokogiri::XML::Element]
137
168
  # @return [Array<String>]
138
169
  def fetch_place(doc)
139
170
  doc.xpath("institution/institution_place").map(&:text)
140
171
  end
141
172
 
173
+ def fetch_series(doc)
174
+ title = RelatonBib::TypedTitleString.new(content: "NIST")
175
+ [RelatonBib::Series.new(title: title, number: pub_id(doc))]
176
+ end
177
+
142
178
  #
143
179
  # Save document
144
180
  #
@@ -174,14 +210,15 @@ module RelatonNist
174
210
  link: fetch_link(doc), abstract: fetch_abstract(doc),
175
211
  date: fetch_date(doc), edition: fetch_edition(doc),
176
212
  contributor: fetch_contributor(doc), relation: fetch_relation(doc),
177
- place: fetch_place(doc),
213
+ place: fetch_place(doc), series: fetch_series(doc),
178
214
  language: [doc["language"]], script: ["Latn"], doctype: "standard"
179
215
  )
180
216
  write_file item
181
217
  rescue StandardError => e
182
218
  warn "Document: #{doc.at('doi').text}"
183
219
  warn e.message
184
- raise e
220
+ warn e.backtrace[0..5].join("\n")
221
+ # raise e
185
222
  end
186
223
 
187
224
  #
@@ -202,6 +239,7 @@ module RelatonNist
202
239
  puts "Done in: #{(t2 - t1).round} sec."
203
240
  rescue StandardError => e
204
241
  warn e.message
242
+ warn e.backtrace[0..5].join("\n")
205
243
  end
206
244
 
207
245
  #
@@ -28,17 +28,18 @@ module RelatonNist
28
28
  # @option opts [TrueClass, FalseClass] :bibdata
29
29
  #
30
30
  # @return [String] Relaton XML serialisation of reference
31
- def get(code, year = nil, opts = {})
32
- return fetch_ref_err(code, year, []) if code.match? /\sEP$/
31
+ def get(code, year = nil, opts = {}) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
32
+ return fetch_ref_err(code, year, []) if code.match?(/\sEP$/)
33
33
 
34
- /^(?<code2>[^\(]+)(\((?<date2>\w+\s(\d{2},\s)?\d{4})\))?\s?\(?((?<=\()(?<stage>[^\)]+))?/ =~ code
34
+ /^(?<code2>[^(]+)(?:\((?<date2>\w+\s(?:\d{2},\s)?\d{4})\))?\s?\(?(?:(?<=\()(?<stage>[^\)]+))?/ =~ code
35
35
  stage ||= /(?<=\.)PD-\w+(?=\.)/.match(code)&.to_s
36
36
  if code2
37
37
  code = code2.strip
38
38
  if date2
39
- if /\w+\s\d{4}/.match? date2
39
+ case date2
40
+ when /\w+\s\d{4}/
40
41
  opts[:issued_date] = Date.strptime date2, "%B %Y"
41
- elsif /\w+\s\d{2},\s\d{4}/.match? date2
42
+ when /\w+\s\d{2},\s\d{4}/
42
43
  opts[:updated_date] = Date.strptime date2, "%B %d, %Y"
43
44
  end
44
45
  end
@@ -1,3 +1,3 @@
1
1
  module RelatonNist
2
- VERSION = "1.9.4".freeze
2
+ VERSION = "1.9.6".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-nist
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.4
4
+ version: 1.9.6
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-01-12 00:00:00.000000000 Z
11
+ date: 2022-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: equivalent-xml