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.

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 = {}) ⇒ DataPartParser

Initialize parser.

Parameters:

  • node (Nokogiri::HTML::Element)

    document node



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

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

Instance Method Details



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

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

#parseItemData

Parse document.

Returns:

  • (ItemData)

    bibliographic item data



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

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



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

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



193
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
# File 'lib/relaton/oasis/data_part_parser.rb', line 193

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.

Returns:

  • (Array<Bib::Date>)

    bibliographic dates



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

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

#parse_docnumberString

Parse document number.

Returns:

  • (String)

    document number



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

def parse_docnumber
  ref = @node.at("./span[@class='citationLabel']/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.

Returns:

  • (Array<Bib::Contributor>)

    editorial group contributors



141
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
# File 'lib/relaton/oasis/data_part_parser.rb', line 141

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.

Returns:

  • (Array<Bib::Uri>)

    link



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

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.

Returns:

  • (Array<Bib::Relation>)

    document relations



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

def parse_relation
  parser = DataParser.new @node.at("./ancestor::details")
  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.

Returns:

  • (Array<String>)

    technology areas



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

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

#parse_titleArray<Bib::Title>

Parse title.

Returns:

  • (Array<Bib::Title>)

    title



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

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

#textObject



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

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



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

def title
  return @title if @title

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