Class: Relaton::ThreeGpp::Parser
- Inherits:
-
Object
- Object
- Relaton::ThreeGpp::Parser
- Defined in:
- lib/relaton/3gpp/parser.rb
Class Method Summary collapse
-
.parse(row, errors = {}) ⇒ RelatonBib:BibliographicItem?
Initialize document parser and run it.
Instance Method Summary collapse
- #address ⇒ Object
- #affiliation ⇒ Object
- #close_meeting ⇒ Object
- #contributor_role ⇒ Object
- #doctype_abbr ⇒ Object
- #editorial_group_contributor(wg_name, wg_type) ⇒ Object
- #forename ⇒ Object
-
#initialize(row, errors) ⇒ Parser
constructor
Document parser initalization.
-
#number ⇒ String
Generate number.
- #other_contribs ⇒ Object
-
#parse ⇒ Relaton3gpp:BibliographicItem?
Parse document.
-
#parse_contributor ⇒ Array<RelatonBib::ContributionInfo>
Create contributors.
-
#parse_date ⇒ Array<RelatonBib::BibliographicDate>
Parse date.
-
#parse_docid ⇒ Arra<RelatonBib::DocumentIdentifier>
Parse docidentifier.
- #parse_doctype ⇒ Object
- #parse_ext ⇒ Object
- #parse_place ⇒ Object
-
#parse_radiotechnology ⇒ String
Parse radio technology.
-
#parse_release ⇒ Relaton3gpp::Release?
Parse release.
-
#parse_source ⇒ Array<RelatonBib::TypedUri>
Parse link.
-
#parse_title ⇒ RelatonBib::TypedTitleStringCollection
Parse title.
- #parse_version ⇒ Object
- #person ⇒ Object
- #prime_contribs ⇒ Object
- #project_end ⇒ Object
- #project_start ⇒ Object
- #release ⇒ Object
- #stage1_freeze ⇒ Object
- #stage2_freeze ⇒ Object
- #stage3_freeze ⇒ Object
- #surname ⇒ Object
- #version ⇒ Object
- #wmp_code2g ⇒ Object
- #wmp_code3g ⇒ Object
Constructor Details
#initialize(row, errors) ⇒ Parser
Document parser initalization
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
26 27 28 |
# File 'lib/relaton/3gpp/parser.rb', line 26 def self.parse(row, errors = {}) new(row, errors).parse end |
Instance Method Details
#address ⇒ Object
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 |
#affiliation ⇒ Object
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_meeting ⇒ Object
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_role ⇒ Object
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_abbr ⇒ Object
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 |
#forename ⇒ Object
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 |
#number ⇒ String
Generate 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_contribs ⇒ Object
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 |
#parse ⇒ Relaton3gpp:BibliographicItem?
Parse document
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_contributor ⇒ Array<RelatonBib::ContributionInfo>
Create contributors
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_date ⇒ Array<RelatonBib::BibliographicDate>
Parse 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_docid ⇒ Arra<RelatonBib::DocumentIdentifier>
Parse 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_doctype ⇒ Object
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_ext ⇒ Object
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_place ⇒ Object
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_radiotechnology ⇒ String
Parse 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_release ⇒ Relaton3gpp::Release?
Parse 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_source ⇒ Array<RelatonBib::TypedUri>
Parse 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_title ⇒ RelatonBib::TypedTitleStringCollection
Parse 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_version ⇒ Object
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 |
#person ⇒ Object
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_contribs ⇒ Object
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_end ⇒ Object
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_start ⇒ Object
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 |
#release ⇒ Object
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_freeze ⇒ Object
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_freeze ⇒ Object
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_freeze ⇒ Object
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 |
#surname ⇒ Object
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 |
#version ⇒ Object
111 112 113 |
# File 'lib/relaton/3gpp/parser.rb', line 111 def version @row["Version"] end |
#wmp_code2g ⇒ Object
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_code3g ⇒ Object
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 |