Class: Relaton3gpp::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/relaton_3gpp/parser.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(row, specs, specrels, releases, tstatus) ⇒ Parser

Document parser initalization

Parameters:

  • row (Hash)

    row

  • specrels (Array<Hash>)

    Spec + Release table

  • relaeases (Array<Hash>)

    Releases table

  • specs (Array<Hash>)

    Specs table

  • tstatus (Array<Hash>)

    temp status-table



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/relaton_3gpp/parser.rb', line 12

def initialize(row, specs, specrels, releases, tstatus) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
  @row = row
  @spec = specs.detect { |s| s[:Number] == row[:spec] }
  if @spec
    @specrel = specrels.detect do |sr|
      sr[:Spec] == row[:spec] && sr[:Release] == row[:release]
    end
    @rel = releases.detect { |r| r[:Release_code] == row[:release] }
  end
  @tstatus = tstatus.detect { |t| t[:Number] == row[:spec] }
end

Class Method Details

.parse(row, specs, specrels, relaeases, tstatus) ⇒ RelatonBib:BibliographicItem?

Initialize document parser and run it

Parameters:

  • row (Hash)

    row

  • specrels (Array<Hash>)

    Spec + Release table

  • relaeases (Array<Hash>)

    Releases table

  • specs (Array<Hash>)

    Specs table

  • tstatus (Array<Hash>)

    temp status-table

Returns:

  • (RelatonBib:BibliographicItem, nil)

    bibliographic item



35
36
37
# File 'lib/relaton_3gpp/parser.rb', line 35

def self.parse(row, specs, specrels, relaeases, tstatus)
  new(row, specs, specrels, relaeases, tstatus).parse
end

Instance Method Details

#create_workgroup(name, type) ⇒ Object



166
167
168
169
# File 'lib/relaton_3gpp/parser.rb', line 166

def create_workgroup(name, type)
  wgf = RelatonBib::WorkGroup.new(name: name, type: type)
  RelatonBib::TechnicalCommittee.new(wgf)
end

#numberString

Generate number

Returns:

  • (String)

    number



117
118
119
# File 'lib/relaton_3gpp/parser.rb', line 117

def number
  "#{@spec[:Type]} #{@row[:spec]}:#{@row[:release]}/#{version}"
end

#parseRelaton3gpp:BibliographicItem?

Parse document

Returns:

  • (Relaton3gpp:BibliographicItem, nil)

    bibliographic item



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/relaton_3gpp/parser.rb', line 44

def parse # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
  return unless @spec && @row[:"3guId"]

  Relaton3gpp::BibliographicItem.new(
    type: "standard",
    language: ["en"],
    script: ["Latn"],
    title: parse_title,
    link: parse_link,
    abstract: parse_abstract,
    docid: parse_docid,
    docnumber: number,
    date: parse_date,
    doctype: DocumentType.new(type: @spec[:Type]),
    editorialgroup: parse_editorialgroup,
    biblionote: parse_note,
    docstatus: parse_status,
    radiotechnology: parse_radiotechnology,
    common_ims_spec: @spec[:ComIMS] == "1",
    # internal: @spec[:"For publication"] == "0",
    release: parse_release,
    contributor: parse_contributor,
    place: ["Sophia Antipolis Cedex, France"],
  )
end

#parse_abstractArray<RelatonBib::FormattedString>

Parse abstract

Returns:

  • (Array<RelatonBib::FormattedString>)


97
98
99
100
101
# File 'lib/relaton_3gpp/parser.rb', line 97

def parse_abstract
  return [] unless @spec[:description]

  [RelatonBib::FormattedString.new(content: @spec[:description])]
end

#parse_contributorArray<RelatonBib::ContributionInfo>

Create contributors

Returns:

  • (Array<RelatonBib::ContributionInfo>)

    contributor



244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
# File 'lib/relaton_3gpp/parser.rb', line 244

def parse_contributor # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
  address = RelatonBib::Address.new(
    street: ["c/o ETSI 650, route des Lucioles", "3GPP Mobile Competence Centre"],
    postcode: "06921", city: "Sophia Antipolis Cedex", country: "France"
  )
  org = RelatonBib::Organization.new(
    name: "3rd Generation Partnership Project", abbreviation: "3GPP", contact: [address],
  )
  roles = [{ type: "author" }, { type: "publisher" }]
  contribs = [RelatonBib::ContributionInfo.new(entity: org, role: roles)]
  return contribs unless @tstatus && @tstatus[:rapporteur]

  aff = []
  if @tstatus[:"rapp org"]
    org = RelatonBib::Organization.new(name: @tstatus[:"rapp org"])
    cn = RelatonBib::LocalizedString.new @tstatus[:rapporteur], "en", "Latn"
    name = RelatonBib::FullName.new(completename: cn)
    aff << RelatonBib::Affiliation.new(organization: org)
  end
  person = RelatonBib::Person.new(name: name, affiliation: aff)
  role = { type: "author" }
  contribs << RelatonBib::ContributionInfo.new(entity: person, role: [role])
end

#parse_dateArray<RelatonBib::BibliographicDate>

Parse date

Returns:

  • (Array<RelatonBib::BibliographicDate>)

    date



135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/relaton_3gpp/parser.rb', line 135

def parse_date
  dates = { completed: "created", ACHIEVED_DATE: "published" }.each_with_object([]) do |(k, t), d|
  # if @row[:completed]
    next unless @row[k]

    cd = Date.parse(@row[k]).to_s
    d << RelatonBib::BibliographicDate.new(type: t, on: cd)
  end
  if @spec[:"title verified"]
    td = Date.parse(@spec[:"title verified"]).to_s
    dates << RelatonBib::BibliographicDate.new(type: "confirmed", on: td)
  end
  dates
end

#parse_docidArra<RelatonBib::DocumentIdentifier>

Parse docidentifier

Returns:

  • (Arra<RelatonBib::DocumentIdentifier>)

    docidentifier



108
109
110
# File 'lib/relaton_3gpp/parser.rb', line 108

def parse_docid
  [RelatonBib::DocumentIdentifier.new(type: "3GPP", id: "3GPP #{number}", primary: true)]
end

#parse_editorialgroupRelatonBib::EditorialGroup

Parse editorialgroup

Returns:

  • (RelatonBib::EditorialGroup)

    editorialgroups



155
156
157
158
159
160
161
162
163
164
# File 'lib/relaton_3gpp/parser.rb', line 155

def parse_editorialgroup # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
  eg = [create_workgroup(@spec[:"WG prime"], "prime")]
  if @spec[:"WG other"] && @spec[:"WG other"] != "-"
    eg << create_workgroup(@spec[:"WG other"], "other")
  end
  if @spec[:"former WG"]
    eg << create_workgroup(@spec[:"former WG"], "former")
  end
  RelatonBib::EditorialGroup.new eg
end

Parse link

Returns:

  • (Array<RelatonBib::TypedUri>)

    link



85
86
87
88
89
90
# File 'lib/relaton_3gpp/parser.rb', line 85

def parse_link
  return [] unless @row[:location]

  content = @row[:location].split("#").last
  [RelatonBib::TypedUri.new(type: "src", content: content)]
end

#parse_noteRelatonBib::BiblioNoteCollection

Parse note

Returns:

  • (RelatonBib::BiblioNoteCollection)

    notes



176
177
178
179
180
181
182
183
184
185
# File 'lib/relaton_3gpp/parser.rb', line 176

def parse_note
  n = []
  if @specrel && @specrel[:remarks] && @specrel[:remarks] != "."
    n << RelatonBib::BiblioNote.new(type: "remark", content: @specrel[:remarks])
  end
  if @row[:comment] && @row[:comment] != "."
    n << RelatonBib::BiblioNote.new(type: "comment", content: @row[:comment])
  end
  RelatonBib::BiblioNoteCollection.new n
end

#parse_radiotechnologyString

Parse radio technology

Returns:

  • (String)

    radio technology



205
206
207
208
209
210
211
# File 'lib/relaton_3gpp/parser.rb', line 205

def parse_radiotechnology
  if @spec[:"2g"] == "1" then "2G"
  elsif @spec[:"3g"] == "1" then "3G"
  elsif @spec[:LTE] == "1" then "LTE"
  elsif @spec[:"5G"] == "1" then "5G"
  end
end

#parse_releaseRelaton3gpp::Release?

Parse release

Returns:



218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/relaton_3gpp/parser.rb', line 218

def parse_release # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
  if @rel
    project_start = Date.parse(@rel[:"rel-proj-start"]).to_s if @rel[:"rel-proj-start"]
    project_end = Date.parse(@rel[:"rel-proj-end"]).to_s if @rel[:"rel-proj-end"]
    Release.new(
      version2g: @rel[:version_2g],
      version3g: @rel[:version_3g],
      defunct: @rel[:defunct] == "1",
      wpm_code_2g: @rel[:wpm_code_2g],
      wpm_code_3g: @rel[:wpm_code_3g],
      freeze_meeting: @rel[:"freeze meeting"],
      freeze_stage1_meeting: @rel[:Stage1_freeze],
      freeze_stage2_meeting: @rel[:Stage2_freeze],
      freeze_stage3_meeting: @rel[:Stage3_freeze],
      close_meeting: @rel[:Closed],
      project_start: project_start,
      project_end: project_end,
    )
  end
end

#parse_statusRelatnoBib::DocumentStatus?

Prase status

Returns:

  • (RelatnoBib::DocumentStatus, nil)

    status



192
193
194
195
196
197
198
# File 'lib/relaton_3gpp/parser.rb', line 192

def parse_status
  if @specrel && @specrel[:withdrawn] == "1"
    RelatonBib::DocumentStatus.new stage: "withdrawn"
  elsif @spec[:"For publication"] == "1"
    RelatonBib::DocumentStatus.new stage: "published"
  end
end

#parse_titleRelatonBib::TypedTitleStringCollection

Parse title

Returns:

  • (RelatonBib::TypedTitleStringCollection)

    title



75
76
77
78
# File 'lib/relaton_3gpp/parser.rb', line 75

def parse_title
  t = RelatonBib::TypedTitleString.new content: @spec[:Title], type: "main"
  RelatonBib::TypedTitleStringCollection.new [t]
end

#versionString

Version

Returns:

  • (String)

    version



126
127
128
# File 'lib/relaton_3gpp/parser.rb', line 126

def version
  "#{@row[:MAJOR_VERSION_NB]}.#{@row[:TECHNICAL_VERSION_NB]}.#{@row[:EDITORIAL_VERSION_NB]}"
end