Class: Relaton::Oasis::DataPartParser

Inherits:
Object
  • Object
show all
Includes:
DataParserUtils
Defined in:
lib/relaton/oasis/data_part_parser.rb

Overview

Parser for OASIS part document.

Constant Summary

Constants included from DataParserUtils

Relaton::Oasis::DataParserUtils::RETRIABLE_PAGE_ERRORS

Instance Method Summary collapse

Methods included from DataParserUtils

#create_contribution_info, #create_ext, #create_person, #decode_cf_email, #page, #parse_chairs, #parse_contributor, #parse_docid, #parse_doctype, #parse_editors, #parse_editors_from_text, #parse_errata, #parse_part, #parse_spec, #person_affiliation, #person_email, #publisher_oasis, #retry_page

Constructor Details

#initialize(node, errors = {}, agent: nil) ⇒ DataPartParser

Initialize parser.



12
13
14
15
16
# File 'lib/relaton/oasis/data_part_parser.rb', line 12

def initialize(node, errors = {}, agent: nil)
  @node = node
  @errors = errors
  @agent = agent
end

Instance Method Details



223
224
225
# File 'lib/relaton/oasis/data_part_parser.rb', line 223

def link_node
  @link_node = @node.at("./a|./following-sibling::p[1]/a")
end

#parseItemData

Parse document.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/relaton/oasis/data_part_parser.rb', line 51

def parse # rubocop:disable Metrics/MethodLength
  ItemData.new(
    type: "standard",
    title: parse_title,
    docidentifier: parse_docid,
    source: parse_link,
    docnumber: parse_docnumber,
    date: parse_date,
    abstract: parse_abstract,
    language: ["en"],
    script: ["Latn"],
    relation: parse_relation,
    contributor: parse_contributor,
    ext: create_ext,
  )
end

#parse_abstractObject

rubocop:disable Metrics/MethodLength



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/relaton/oasis/data_part_parser.rb', line 120

def parse_abstract # rubocop:disable Metrics/MethodLength
  result = if page
             xpath = "//p[preceding-sibling::p" \
                     "[starts-with(., 'Abstract')]][1]"
             page.xpath(xpath).map do |p|
               cnt = p.text.gsub(/[\r\n]+/, " ").strip
               Bib::Abstract.new(
                 content: cnt, language: "en", script: "Latn",
               )
             end
           else
             []
           end
  @errors[:part_abstract] &&= result.empty?
  result
end

#parse_authorizerObject

rubocop:disable Metrics/AbcSize, Metrics/MethodLength



194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/relaton/oasis/data_part_parser.rb', line 194

def parse_authorizer # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
  result = if page
             xpath = "//p[preceding-sibling::p" \
                     "[starts-with(., 'Technical')]][1]//a"
             page.xpath(xpath).map do |a|
               org_name = a.text.gsub(/[\r\n]+/, " ").strip
               org = Bib::Organization.new(
                 name: [Bib::TypedLocalizedString.new(
                   content: org_name,
                 )],
                 uri: [Bib::Uri.new(type: "uri",
                                    content: a[:href])],
               )
               desc = [Bib::LocalizedMarkedUpString.new(
                 content: "Committee",
               )]
               role = Bib::Contributor::Role.new(
                 type: "authorizer", description: desc,
               )
               Bib::Contributor.new(organization: org,
                                    role: [role])
             end
           else
             []
           end
  @errors[:part_authorizer] &&= result.empty?
  result
end

#parse_dateArray<Bib::Date>

Parse date.



113
114
115
116
117
118
# File 'lib/relaton/oasis/data_part_parser.rb', line 113

def parse_date
  match = text.match(/(?<on>\d{1,2}\s\w+\s\d{4})/)
  result = match ? [Bib::Date.new(at: Date.parse(match[:on]).to_s, type: "issued")] : []
  @errors[:part_date] &&= result.empty?
  result
end

#parse_docnumberString

Parse document number.



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

def parse_docnumber
  ref = @node.at("./span/strong|./strong|./b/span")
  num = ref.text.match(/[^\[\]]+/).to_s
  id = parse_errata(num)
  # some part refs need "Pt" to distinguish from root doc
  id += "-Pt" if %w[CMIS-v1.1 DocBook-5.0 XACML-V3.0 mqtt-v3.1.1
                    OData-JSON-Format-v4.0].include?(id)
  result = parse_part parse_spec id
  @errors[:part_docnumber] &&= result.nil?
  result
end

#parse_editorialgroup_contributorArray<Bib::Contributor>

Parse editorial group as contributors.



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/relaton/oasis/data_part_parser.rb', line 142

def parse_editorialgroup_contributor # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
  result = if page
             xpath = "//p[preceding-sibling::p" \
                     "[starts-with(., 'Technical')]][1]//a"
             tcs = page.xpath(xpath)
             if tcs.empty?
               []
             else
               subdivisions = tcs.map do |a|
                 name = [Bib::TypedLocalizedString.new(
                   content: a.text.strip,
                 )]
                 Bib::Subdivision.new(
                   type: "technical-committee", name: name,
                 )
               end
               org = Bib::Organization.new(
                 name: [Bib::TypedLocalizedString.new(
                   content: "OASIS",
                 )],
                 subdivision: subdivisions,
               )
               desc = [Bib::LocalizedMarkedUpString.new(
                 content: "committee",
               )]
               role = Bib::Contributor::Role.new(
                 type: "author", description: desc,
               )
               [Bib::Contributor.new(organization: org,
                                     role: [role])]
             end
           else
             []
           end
  @errors[:part_editorialgroup_contributor] &&= result.empty?
  result
end

Parse link.



102
103
104
105
106
# File 'lib/relaton/oasis/data_part_parser.rb', line 102

def parse_link
  result = [Bib::Uri.new(type: "src", content: link_node[:href])]
  @errors[:part_link] &&= result.empty?
  result
end

#parse_relationArray<Bib::Relation>

Parse relation.



185
186
187
188
189
190
191
192
# File 'lib/relaton/oasis/data_part_parser.rb', line 185

def parse_relation
  parser = DataParser.new(@node.at("./ancestor::details"), @errors, agent: @agent)
  fref = parser.parse_docid[0].content
  bib = ItemData.new(formattedref: Bib::Formattedref.new(content: fref))
  result = [Bib::Relation.new(type: "partOf", bibitem: bib)]
  @errors[:part_relation] &&= result.empty?
  result
end

#parse_technology_areaArray<String>

Parse technology area.



232
233
234
235
236
# File 'lib/relaton/oasis/data_part_parser.rb', line 232

def parse_technology_area
  result = super(@node.at("./ancestor::details"))
  @errors[:part_technology_area] &&= result.empty?
  result
end

#parse_titleArray<Bib::Title>

Parse title.



73
74
75
76
77
78
# File 'lib/relaton/oasis/data_part_parser.rb', line 73

def parse_title
  result = [Bib::Title.new(type: "main", content: title,
                           language: "en", script: "Latn")]
  @errors[:part_title] &&= result.empty?
  result
end

#textObject



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/relaton/oasis/data_part_parser.rb', line 18

def text
  return @text if @text

  sibling_xpath = "./strong/following-sibling::text()" \
                  "|./span[strong]/following-sibling::text()"
  if @node.at(sibling_xpath)
    nodes_xpath = "./strong/following-sibling::node()" \
                  "|./span[strong]/following-sibling::node()"
    @text = @node.xpath(nodes_xpath).text.strip
  else
    @text = @node.xpath("./following-sibling::p[1][em]").text.strip
  end
end

#titleObject



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/relaton/oasis/data_part_parser.rb', line 32

def title
  return @title if @title

  xpath = "./span[@class='citationTitle' " \
          "or @class='citeTitle']|./em|./i"
  t = @node.at(xpath)
  @title = if t
             t.text
           else
             m = text.match(/(?<content>.+)\s(?:Edited|\d{2}\s\w+\d{4})/)
             m ? m[:content] : text
           end.strip
end