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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of IdamsParser.



14
15
16
17
18
# File 'lib/relaton/ieee/idams_parser.rb', line 14

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)


140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/relaton/ieee/idams_parser.rb', line 140

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



42
43
44
# File 'lib/relaton/ieee/idams_parser.rb', line 42

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

#parseRelaton::Ieee::ItemData

Parse IEEE document

Returns:



25
26
27
28
29
# File 'lib/relaton/ieee/idams_parser.rb', line 25

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>)


163
164
165
166
167
168
169
170
171
# File 'lib/relaton/ieee/idams_parser.rb', line 163

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

    acc << Bib::Abstract.new(content: abs.value, 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>)


122
123
124
125
126
127
128
129
130
131
# File 'lib/relaton/ieee/idams_parser.rb', line 122

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>)


102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/relaton/ieee/idams_parser.rb', line 102

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>)


178
179
180
181
182
183
184
185
# File 'lib/relaton/ieee/idams_parser.rb', line 178

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>)


75
76
77
78
79
# File 'lib/relaton/ieee/idams_parser.rb', line 75

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>)


86
87
88
89
90
91
92
93
94
95
# File 'lib/relaton/ieee/idams_parser.rb', line 86

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



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

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

#parse_keywordArray<Strign>

Parse keyword

Returns:

  • (Array<Strign>)


234
235
236
237
238
239
240
# File 'lib/relaton/ieee/idams_parser.rb', line 234

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>)


205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/relaton/ieee/idams_parser.rb', line 205

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>)


223
224
225
226
227
# File 'lib/relaton/ieee/idams_parser.rb', line 223

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)


192
193
194
195
196
197
198
# File 'lib/relaton/ieee/idams_parser.rb', line 192

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>)


64
65
66
67
68
# File 'lib/relaton/ieee/idams_parser.rb', line 64

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

#pubidRelaton::Ieee::RawbibIdParser

Create PubID

Returns:



51
52
53
54
55
56
57
# File 'lib/relaton/ieee/idams_parser.rb', line 51

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