Class: Relaton::Ieee::IdamsParser

Inherits:
Object
  • Object
show all
Includes:
Core::ArrayWrapper
Defined in:
lib/relaton/ieee/idams_parser.rb

Constant Summary collapse

ATTRS =
%i[
  docnumber title date docidentifier contributor abstract copyright status
  relation source keyword ext
].freeze
CONTROL_PLACEHOLDER_RE =

Upstream IDAMS abstracts sometimes carry escaped ASCII control characters as printable tokens like ‘<<ETX>>`. They are meaningless in output, and `<<…>>` blows up XML serialization downstream (libxml2 reads `<<` as the start of a tag). Strip the whole family.

/<<[A-Z]{2,5}>>/.freeze

Instance Method Summary collapse

Constructor Details

#initialize(doc, fetcher, errors = {}) ⇒ IdamsParser

Returns a new instance of IdamsParser.



20
21
22
23
24
# File 'lib/relaton/ieee/idams_parser.rb', line 20

def initialize(doc, fetcher, errors = {})
  @doc = doc
  @fetcher = fetcher
  @errors = errors
end

Instance Method Details

#create_committee_contributor(committee) ⇒ Relaton::Bib::Contributor

Create a committee contributor

Parameters:

  • committee (String)

    committee name

Returns:

  • (Relaton::Bib::Contributor)


146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/relaton/ieee/idams_parser.rb', line 146

def create_committee_contributor(committee)
  desc = Bib::LocalizedMarkedUpString.new(content: "committee", language: "en", script: "Latn")
  role = Bib::Contributor::Role.new(type: "author", description: [desc])

  # Create IEEE organization with committee as subdivision
  orgname = Bib::TypedLocalizedString.new(
    content: "Institute of Electrical and Electronics Engineers", language: "en", script: "Latn"
  )
  abbr = Bib::LocalizedString.new(content: "IEEE")

  # Create subdivision for the committee
  subdiv_name = Bib::TypedLocalizedString.new(content: CGI.unescapeHTML(committee), language: "en", script: "Latn")
  subdivision = Bib::Subdivision.new(type: "committee", name: [subdiv_name])

  org = Bib::Organization.new(name: [orgname], abbreviation: abbr, subdivision: [subdivision])
  Relaton::Bib::Contributor.new(organization: org, role: [role])
end

#docnumberString

Parse docnumber

Returns:

  • (String)

    PubID



48
49
50
# File 'lib/relaton/ieee/idams_parser.rb', line 48

def docnumber
  @docnumber ||= pubid&.to_id
end

#parseRelaton::Ieee::ItemData

Parse IEEE document

Returns:



31
32
33
34
35
# File 'lib/relaton/ieee/idams_parser.rb', line 31

def parse
  args = { type: "standard", language: ["en"], script: ["Latn"] }
  ATTRS.each { |attr| args[attr] = send("parse_#{attr}") }
  ItemData.new(**args)
end

#parse_abstractArray<Relaton::Bib::LocalizedMarkedUpString>

Parse abstract

Returns:

  • (Array<Relaton::Bib::LocalizedMarkedUpString>)


169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/relaton/ieee/idams_parser.rb', line 169

def parse_abstract
  result = @doc.volume.article..abstract.each_with_object([]) do |abs, acc|
    next unless abs.abstract_type == "Standard"

    content = abs.value.gsub(CONTROL_PLACEHOLDER_RE, "").strip
    next if content.empty?

    acc << Bib::Abstract.new(content: content, language: "en", script: "Latn")
  end
  @errors[:abstract] &&= result.empty?
  result
end

#parse_committee_contributorsArray<Relaton::Bib::Contributor>

Parse committee contributors from editorial group

Returns:

  • (Array<Relaton::Bib::Contributor>)


128
129
130
131
132
133
134
135
136
137
# File 'lib/relaton/ieee/idams_parser.rb', line 128

def parse_committee_contributors
  committees = @doc.editorialgroup
  return [] unless committees

  result = committees.map do |committee|
    create_committee_contributor(committee)
  end
  @errors[:committee] &&= result.empty?
  result
end

#parse_contributorArray<Relaton::Bib::Contributor>

Parse contributors

Returns:

  • (Array<Relaton::Bib::Contributor>)


108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/relaton/ieee/idams_parser.rb', line 108

def parse_contributor
  contributors = []

  # Add publisher contributor
  name, addr = @doc.contrib_name_addr { |args| Relaton::Bib::Address.new(**args) }
  org = create_org name, addr
  role = Bib::Contributor::Role.new type: "publisher"
  contributors << Relaton::Bib::Contributor.new(organization: org, role: [role])

  # Add committee contributors from editorial group
  result = contributors + parse_committee_contributors
  @errors[:contributor] &&= result.empty?
  result
end

Parse copyright

Returns:

  • (Array<Relaton::Bib::Copyright>)


187
188
189
190
191
192
193
194
# File 'lib/relaton/ieee/idams_parser.rb', line 187

def parse_copyright
  result = @doc.copyright.map do |owner, year|
    contrib = owner.map { |own| Bib::ContributionInfo.new organization: create_org(own) }
    Bib::Copyright.new(owner: contrib, from: year)
  end
  @errors[:copyright] &&= result.empty?
  result
end

#parse_dateArray<Relaton::Bib::Date>

Parse date

Returns:

  • (Array<Relaton::Bib::Date>)


81
82
83
84
85
# File 'lib/relaton/ieee/idams_parser.rb', line 81

def parse_date
  result = @doc.bdate.map { |args| Bib::Date.new(type: args[:type], at: args[:on]) }
  @errors[:date] &&= result.empty?
  result
end

#parse_docidentifierArray<Relaton::Bib::Docidentifier>

Parse identifiers

Returns:

  • (Array<Relaton::Bib::Docidentifier>)


92
93
94
95
96
97
98
99
100
101
# File 'lib/relaton/ieee/idams_parser.rb', line 92

def parse_docidentifier # rubocop:disable Metrics/MethodLength
  ids = @doc.isbn_doi.map { |id| id[:content] = id.delete(:id); id }

  ids.unshift(content: pubid.to_s(trademark: true), scope: "trademark", type: "IEEE", primary: true)
  ids.unshift(content: pubid.to_s, type: "IEEE", primary: true)

  result = ids.map { |dcid| Bib::Docidentifier.new(**dcid) }
  @errors[:docidentifier] &&= result.empty?
  result
end

#parse_docnumberObject



37
38
39
40
41
# File 'lib/relaton/ieee/idams_parser.rb', line 37

def parse_docnumber
  result = docnumber
  @errors[:docnumber] &&= result.nil?
  result
end

#parse_keywordArray<Strign>

Parse keyword

Returns:

  • (Array<Strign>)


243
244
245
246
247
248
249
# File 'lib/relaton/ieee/idams_parser.rb', line 243

def parse_keyword
  result = @doc.keyword.map do |kw|
    Bib::Keyword.new(vocab: Bib::LocalizedString.new(content: CGI.unescapeHTML(kw), language: "en", script: "Latn"))
  end
  @errors[:keyword] &&= result.empty?
  result
end

#parse_relationArray<Relaton::Bib::Relation>

Parse relation

Returns:

  • (Array<Relaton::Bib::Relation>)


214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/relaton/ieee/idams_parser.rb', line 214

def parse_relation # rubocop:disable Metrics/AbcSize
  result = array(@doc.publicationinfo.standard_relationship).each_with_object([]) do |relation, acc|
    if (ref = @fetcher.backrefs[relation.date_string])
      rel = @fetcher.create_relation(relation.type, ref)
      acc << rel if rel
    elsif !relation.date_string.include?("Inactive Date") && docnumber
      @fetcher.add_crossref(docnumber, relation)
    end
  end
  @errors[:relation] &&= result.empty?
  result
end

#parse_sourceArray<Relaton::Bib::Uri>

Parce source link

Returns:

  • (Array<Relaton::Bib::Uri>)


232
233
234
235
236
# File 'lib/relaton/ieee/idams_parser.rb', line 232

def parse_source
  result = @doc.link { |url| Bib::Uri.new(content: url, type: "src") }
  @errors[:source] &&= result.empty?
  result
end

#parse_statusRelaton::Bib::Status?

Parse status

Returns:

  • (Relaton::Bib::Status, nil)


201
202
203
204
205
206
207
# File 'lib/relaton/ieee/idams_parser.rb', line 201

def parse_status
  return if @doc.docstatus.nil? || @doc.docstatus.empty?

  @errors[:status] &&= @doc.docstatus[:stage].nil?
  stage = Bib::Status::Stage.new content: @doc.docstatus[:stage]
  Bib::Status.new stage: stage
end

#parse_titleArray<Relaton::Bib::Title>

Parse title

Returns:

  • (Array<Relaton::Bib::Title>)


70
71
72
73
74
# File 'lib/relaton/ieee/idams_parser.rb', line 70

def parse_title
  result = @doc.btitle.map { |args| Bib::Title.new(**args) }
  @errors[:title] &&= result.empty?
  result
end

#pubidRelaton::Ieee::RawbibIdParser

Create PubID

Returns:



57
58
59
60
61
62
63
# File 'lib/relaton/ieee/idams_parser.rb', line 57

def pubid
  @pubid ||= begin
    normtitle = @doc.normtitle
    stdnumber = @doc.publicationinfo.stdnumber
    RawbibIdParser.parse(normtitle, stdnumber)
  end
end