Class: Relaton::ThreeGpp::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, errors) ⇒ Parser

Document parser initalization

Parameters:

  • row (CSV::Row)

    CSV row



13
14
15
16
# File 'lib/relaton/3gpp/parser.rb', line 13

def initialize(row, errors)
  @row = row
  @errors = errors
end

Class Method Details

.parse(row, errors = {}) ⇒ RelatonBib:BibliographicItem?

Initialize document parser and run it

Parameters:

  • row (CSV:Row)

    CSV row

  • errors (Hash) (defaults to: {})

    collection of parsing errors

Returns:

  • (RelatonBib:BibliographicItem, nil)

    bibliographic item



26
27
28
# File 'lib/relaton/3gpp/parser.rb', line 26

def self.parse(row, errors = {})
  new(row, errors).parse
end

Instance Method Details

#addressObject



242
243
244
245
246
247
# File 'lib/relaton/3gpp/parser.rb', line 242

def address
  Bib::Address.new(
    street: ["c/o ETSI 650, route des Lucioles", "3GPP Mobile Competence Centre"],
    postcode: "06921", city: "Sophia Antipolis Cedex", country: "France"
  )
end

#affiliationObject



278
279
280
281
282
283
284
285
286
287
288
# File 'lib/relaton/3gpp/parser.rb', line 278

def affiliation
  if @row["Organisation"].nil? || @row["Organisation"].empty?
    @errors[:contributor_person_affiliation] &&= true
    return []
  end

  @errors[:contributor_person_affiliation] &&= false
  name = Bib::TypedLocalizedString.new(content: @row["Organisation"])
  org = Bib::Organization.new(name: [name])
  [Bib::Affiliation.new(organization: org)]
end

#close_meetingObject



378
379
380
381
# File 'lib/relaton/3gpp/parser.rb', line 378

def close_meeting
  @errors[:close_meeting] &&= @row["Close Meeting"].nil? || @row["Close Meeting"].empty?
  @row["Close Meeting"]
end

#contributor_roleObject



249
250
251
# File 'lib/relaton/3gpp/parser.rb', line 249

def contributor_role
  [Bib::Contributor::Role.new(type: "author"), Bib::Contributor::Role.new(type: "publisher")]
end

#doctype_abbrObject



120
121
122
# File 'lib/relaton/3gpp/parser.rb', line 120

def doctype_abbr
  @row["Is TS"] == "1" ? "TS" : "TR"
end

#editorial_group_contributor(wg_name, wg_type) ⇒ Object



226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/relaton/3gpp/parser.rb', line 226

def editorial_group_contributor(wg_name, wg_type)
  Bib::Contributor.new(
    role: [Bib::Contributor::Role.new(
      type: "author",
      description: [Bib::LocalizedMarkedUpString.new(content: "committee")],
    )],
    organization: Bib::Organization.new(
      subdivision: [Bib::Subdivision.new(
        type: "technical-committee",
        subtype: wg_type,
        name: [Bib::TypedLocalizedString.new(content: wg_name)],
      )],
    ),
  )
end

#forenameObject



268
269
270
271
272
273
274
275
276
# File 'lib/relaton/3gpp/parser.rb', line 268

def forename
  if @row["First Name"].nil? || @row["First Name"].empty?
    @errors[:contributor_person_forename] &&= true
    return nil
  end

  @errors[:contributor_person_forename] &&= false
  Bib::FullNameType::Forename.new content: @row["First Name"], language: "en", script: "Latn"
end

#numberString

Generate number

Returns:

  • (String)

    number



105
106
107
108
109
# File 'lib/relaton/3gpp/parser.rb', line 105

def number
  num = "#{doctype_abbr} #{@row[0]}"
  num += ":#{release}" if release
  "#{num}/#{version}"
end

#other_contribsObject



207
208
209
210
211
212
213
# File 'lib/relaton/3gpp/parser.rb', line 207

def other_contribs
  contribs = @row["Responsible Secondary"].strip.split(", ").map do |wg|
    editorial_group_contributor(wg, "other")
  end
  @errors[:editorial_group_contributor_other] &&= contribs.empty?
  contribs
end

#parseRelaton3gpp:BibliographicItem?

Parse document

Returns:

  • (Relaton3gpp:BibliographicItem, nil)

    bibliographic item



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/relaton/3gpp/parser.rb', line 35

def parse # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
  ItemData.new(
    type: "standard",
    language: ["en"],
    script: ["Latn"],
    title: parse_title,
    source: parse_source,
    # abstract: parse_abstract,
    docidentifier: parse_docid,
    docnumber: number,
    date: parse_date,
    version: parse_version,
    contributor: parse_contributor,
    place: parse_place,
    ext: parse_ext,
    # biblionote: parse_note,
    # docstatus: parse_status,
    # common_ims_spec: @spec[:ComIMS] == "1",
    # internal: @spec[:"For publication"] == "0",
  )
end

#parse_contributorArray<RelatonBib::ContributionInfo>

Create contributors

Returns:

  • (Array<RelatonBib::ContributionInfo>)

    contributor



194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/relaton/3gpp/parser.rb', line 194

def parse_contributor # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
  name = Bib::TypedLocalizedString.new(content: "3rd Generation Partnership Project")
  abbrev = Bib::LocalizedString.new content: "3GPP"
  org = Bib::Organization.new(name: [name], abbreviation: abbrev, address: [address])
  contribs = [Bib::Contributor.new(organization: org, role: contributor_role)]
  if @row["Last Name"] && @row["Last Name"] != "Vacant"
    role = Bib::Contributor::Role.new type: "author"
    contribs << Bib::Contributor.new(person: person, role: [role])
  end
  @errors[:contributor] &&= contribs.empty?
  contribs + prime_contribs + other_contribs
end

#parse_dateArray<RelatonBib::BibliographicDate>

Parse date

Returns:

  • (Array<RelatonBib::BibliographicDate>)

    date



150
151
152
153
154
155
156
157
158
# File 'lib/relaton/3gpp/parser.rb', line 150

def parse_date
  dates = []
  if @row["Date"]
    on = Date.parse(@row["Date"]).to_s
    dates << Bib::Date.new(type: "published", at: on)
  end
  @errors[:date] &&= dates.empty?
  dates
end

#parse_docidArra<RelatonBib::DocumentIdentifier>

Parse docidentifier

Returns:

  • (Arra<RelatonBib::DocumentIdentifier>)

    docidentifier



95
96
97
98
# File 'lib/relaton/3gpp/parser.rb', line 95

def parse_docid
  @errors[:docid] &&= @row[0].nil? || @row[0].empty?
  [Bib::Docidentifier.new(type: "3GPP", content: "3GPP #{number}", primary: true)]
end

#parse_doctypeObject



304
305
306
307
308
# File 'lib/relaton/3gpp/parser.rb', line 304

def parse_doctype
  # type = DOCTYPES[doctype_abbr]
  # Doctype.new(abbreviation: doctype_abbr, content: type)
  Doctype.new(content: doctype_abbr) # 3GPP grammar alloves only TS and TR content
end

#parse_extObject



295
296
297
298
299
300
301
302
# File 'lib/relaton/3gpp/parser.rb', line 295

def parse_ext
  Ext.new(
    doctype: parse_doctype,
    flavor: "3gpp",
    radiotechnology: parse_radiotechnology,
    release: parse_release,
  )
end

#parse_placeObject



290
291
292
293
# File 'lib/relaton/3gpp/parser.rb', line 290

def parse_place
  country = Bib::Place::RegionType.new(content: "France", iso: "FR")
  [Bib::Place.new(city: "Sophia Antipolis Cedex", country: [country])]
end

#parse_radiotechnologyString

Parse radio technology

Returns:

  • (String)

    radio technology



315
316
317
318
319
320
321
322
323
324
# File 'lib/relaton/3gpp/parser.rb', line 315

def parse_radiotechnology
  result = case @row["WPM Code 3G"]
           when /5G/ then "5G"
           when /4G/ then "LTE"
           when /3G/ then "3G"
           else @row["WPM Code 2G"] && "2G"
           end
  @errors[:radiotechnology] &&= result.nil?
  result
end

#parse_releaseRelaton3gpp::Release?

Parse release

Returns:

  • (Relaton3gpp::Release, nil)

    release



331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
# File 'lib/relaton/3gpp/parser.rb', line 331

def parse_release # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
  unless wmp_code2g || wmp_code3g || stage1_freeze || stage2_freeze ||
      stage3_freeze || close_meeting || project_start || project_end
    return
  end

  Release.new(
    # version2g: @rel[:version_2g],
    # version3g: @rel[:version_3g],
    # defunct: @rel[:defunct] == "1",
    wpm_code_2g: wmp_code2g,
    wpm_code_3g: wmp_code3g,
    # freeze_meeting: @rel[:"freeze meeting"],
    freeze_stage1_meeting: stage1_freeze,
    freeze_stage2_meeting: stage2_freeze,
    freeze_stage3_meeting: stage3_freeze,
    close_meeting: close_meeting,
    project_start: project_start,
    project_end: project_end,
  )
end

#parse_sourceArray<RelatonBib::TypedUri>

Parse link

Returns:

  • (Array<RelatonBib::TypedUri>)

    link



72
73
74
75
76
77
# File 'lib/relaton/3gpp/parser.rb', line 72

def parse_source
  @errors[:source] &&= @row["Link"].nil? || @row["Link"].empty?
  return [] unless @row["Link"]

  [Bib::Uri.new(type: "src", content: @row["Link"])]
end

#parse_titleRelatonBib::TypedTitleStringCollection

Parse title

Returns:

  • (RelatonBib::TypedTitleStringCollection)

    title



62
63
64
65
# File 'lib/relaton/3gpp/parser.rb', line 62

def parse_title
  @errors[:title] &&= @row["Title"].nil? || @row["Title"].empty?
  [Bib::Title.new(content: @row["Title"], type: "main")]
end

#parse_versionObject



115
116
117
118
# File 'lib/relaton/3gpp/parser.rb', line 115

def parse_version
  @errors[:version] &&= version.nil? || version.empty?
  [Bib::Version.new(draft: version)]
end

#personObject



253
254
255
256
# File 'lib/relaton/3gpp/parser.rb', line 253

def person
  name = Bib::FullName.new(surname: surname, forename: [forename])
  Bib::Person.new(name: name, affiliation: affiliation)
end

#prime_contribsObject



215
216
217
218
219
220
221
222
223
224
# File 'lib/relaton/3gpp/parser.rb', line 215

def prime_contribs
  prime = @row["Responsible Primary"]
  if prime.nil? || prime.empty?
    @errors[:editorial_group_contributor_prime] &&= true
    return []
  end

  @errors[:editorial_group_contributor_prime] &&= false
  [editorial_group_contributor(prime, "prime")]
end

#project_endObject



388
389
390
391
# File 'lib/relaton/3gpp/parser.rb', line 388

def project_end
  @errors[:project_end] &&= @row["Project End"].nil? || @row["Project End"].empty?
  Date.parse(@row["Project End"]) if @row["Project End"]
end

#project_startObject



383
384
385
386
# File 'lib/relaton/3gpp/parser.rb', line 383

def project_start
  @errors[:project_start] &&= @row["Project Start"].nil? || @row["Project Start"].empty?
  Date.parse(@row["Project Start"]) if @row["Project Start"]
end

#releaseObject



124
125
126
127
128
129
130
131
132
133
134
# File 'lib/relaton/3gpp/parser.rb', line 124

def release
  @release ||= begin
    r = case @row["WPM Code 2G"]
        when /Release_(\d+)/ then "REL-#{$1}"
        when /PH(\d+)/ then "Ph#{$1}"
        else @row["Release"]
        end
    @errors[:release] &&= r.nil? || r.empty?
    r
  end
end

#stage1_freezeObject



363
364
365
366
# File 'lib/relaton/3gpp/parser.rb', line 363

def stage1_freeze
  @errors[:freeze_stage1_meeting] &&= @row["Stage 1 Freeze"].nil? || @row["Stage 1 Freeze"].empty?
  @row["Stage 1 Freeze"]
end

#stage2_freezeObject



368
369
370
371
# File 'lib/relaton/3gpp/parser.rb', line 368

def stage2_freeze
  @errors[:freeze_stage2_meeting] &&= @row["Stage 2 Freeze"].nil? || @row["Stage 2 Freeze"].empty?
  @row["Stage 2 Freeze"]
end

#stage3_freezeObject



373
374
375
376
# File 'lib/relaton/3gpp/parser.rb', line 373

def stage3_freeze
  @errors[:freeze_stage3_meeting] &&= @row["Stage 3 Freeze"].nil? || @row["Stage 3 Freeze"].empty?
  @row["Stage 3 Freeze"]
end

#surnameObject



258
259
260
261
262
263
264
265
266
# File 'lib/relaton/3gpp/parser.rb', line 258

def surname
  if @row["Last Name"].nil? || @row["Last Name"].empty?
    @errors[:contributor_person_surname] &&= true
    return nil
  end

  @errors[:contributor_person_surname] &&= false
  Bib::LocalizedString.new content: @row["Last Name"], language: "en", script: "Latn"
end

#versionObject



111
112
113
# File 'lib/relaton/3gpp/parser.rb', line 111

def version
  @row["Version"]
end

#wmp_code2gObject



353
354
355
356
# File 'lib/relaton/3gpp/parser.rb', line 353

def wmp_code2g
  @errors[:wmp_code_2g] &&= @row["WPM Code 2G"].nil? || @row["WPM Code 2G"].empty?
  @row["WPM Code 2G"]
end

#wmp_code3gObject



358
359
360
361
# File 'lib/relaton/3gpp/parser.rb', line 358

def wmp_code3g
  @errors[:wmp_code_3g] &&= @row["WPM Code 3G"].nil? || @row["WPM Code 3G"].empty?
  @row["WPM Code 3G"]
end