relaton-plateau 1.19.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,69 @@
1
+ module Relaton
2
+ module Plateau
3
+ class Parser
4
+ ATTRIS = %i[docid title abstract cover edition type doctype subdoctype
5
+ date link filesize keyword structuredidentifier].freeze
6
+
7
+ def initialize(item)
8
+ @item = item
9
+ end
10
+
11
+ def parse
12
+ args = ATTRIS.each_with_object({}) do |attr, hash|
13
+ hash[attr] = send("parse_#{attr}")
14
+ end
15
+ BibItem.new(**args)
16
+ end
17
+
18
+ private
19
+
20
+ def parse_docid; [] end
21
+
22
+ def create_docid(id)
23
+ RelatonBib::DocumentIdentifier.new(type: "PLATEAU", id: id, primary: true)
24
+ end
25
+
26
+ def create_formatted_string(content, lang = "ja", script = "Jpan")
27
+ RelatonBib::FormattedString.new(content: content, language: lang, script: script)
28
+ end
29
+
30
+ def parse_title
31
+ [create_title(@item["title"], "ja", "Jpan")]
32
+ end
33
+
34
+ def create_title(title, lang, script)
35
+ RelatonBib::TypedTitleString.new(type: "main", content: title, language: lang, script: script)
36
+ end
37
+
38
+ def parse_abstract; [] end
39
+
40
+ def parse_cover
41
+ image_ext = @item["thumbnail"]["mediaItemUrl"].split(".").last
42
+ mimetype = "image/"
43
+ mimetype += image_ext == "jpg" ? "jpeg" : image_ext
44
+ src = "https://www.mlit.go.jp/#{@item["thumbnail"]["mediaItemUrl"]}"
45
+ image = RelatonBib::Image.new(src: src, mimetype: mimetype)
46
+ Cover.new(image)
47
+ end
48
+
49
+ def parse_edition; raise "Not implemented" end
50
+ def parse_type; "standard" end
51
+ def parse_doctype; nil end
52
+ def parse_subdoctype; nil end
53
+ def parse_date; [] end
54
+ def parse_link; [] end
55
+
56
+ def create_date(date, type = "published")
57
+ RelatonBib::BibliographicDate.new(type: type, on: date)
58
+ end
59
+
60
+ def create_link(url, type)
61
+ RelatonBib::TypedUri.new(type: type, content: url)
62
+ end
63
+
64
+ def parse_filesize; raise "Not implemented" end
65
+ def parse_keyword; [] end
66
+ def parse_structuredidentifier; raise "Not implemented" end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,69 @@
1
+ require "relaton/processor"
2
+
3
+ module Relaton
4
+ module Plateau
5
+ class Processor < Relaton::Processor
6
+ attr_reader :idtype
7
+
8
+ def initialize # rubocop:disable Lint/MissingSuper
9
+ @short = :"relaton/plateau"
10
+ @prefix = "PLATEAU"
11
+ @defaultprefix = /^PLATEAU\s/
12
+ @idtype = "PLATEAU"
13
+ @datasets = %w[plateau-handbooks plateau-technical-reports]
14
+ end
15
+
16
+ # @param code [String]
17
+ # @param date [String, nil] year
18
+ # @param opts [Hash]
19
+ # @return [Relaton::Plateau::BibliographicItem
20
+ def get(code, date, opts)
21
+ ::Relaton::Plateau::Bibliography.get(code, date, opts)
22
+ end
23
+
24
+ #
25
+ # Fetch all the documents from www.mlit.go.jp/plateau
26
+ #
27
+ # @param [String] source source name (plateau-handbooks, paleteau-technical-reports)
28
+ # @param [Hash] opts
29
+ # @option opts [String] :output directory to output documents
30
+ # @option opts [String] :format output format (xml, yaml, bibxml)
31
+ #
32
+ def fetch_data(source, opts)
33
+ Fetcher.fetch(source, **opts)
34
+ end
35
+
36
+ # @param xml [String]
37
+ # @return [Relaton::Plateau::BibItem]
38
+ def from_xml(xml)
39
+ ::Relaton::Plateau::XMLParser.from_xml xml
40
+ end
41
+
42
+ # @param hash [Hash]
43
+ # @return [Relaton:Plateau::BibItem]
44
+ def hash_to_bib(hash)
45
+ item_hash = HashConverter.hash_to_bib(hash)
46
+ ::Relaton::Plateau::BibItem.new(**item_hash)
47
+ end
48
+
49
+ # Returns hash of XML grammar
50
+ # @return [String]
51
+ def grammar_hash
52
+ @grammar_hash ||= ::Relaton::Plateau.grammar_hash
53
+ end
54
+
55
+ # Returns number of workers
56
+ # @return [Integer]
57
+ def threads
58
+ 3
59
+ end
60
+
61
+ #
62
+ # Remove index file
63
+ #
64
+ def remove_index_file
65
+ Relaton::Index.find_or_create(:plateau, url: true, file: "#{Bibliography::INDEXFILE}.yaml").remove_file
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,42 @@
1
+ module Relaton
2
+ module Plateau
3
+ class Stagename
4
+ # @return [String]
5
+ attr_reader :content
6
+
7
+ # @return [String, nil]
8
+ attr_reader :abbreviation
9
+
10
+ #
11
+ # Initialize the Stagename object
12
+ #
13
+ # @param [String] content name of the stage
14
+ # @param [String] abbreviation abbreviation of the stage
15
+ #
16
+ def initialize(content:, abbreviation: nil)
17
+ @content = content
18
+ @abbreviation = abbreviation
19
+ end
20
+
21
+ def to_xml(builder)
22
+ builder.stagename do |b|
23
+ b.parent[:abbreviation] = abbreviation if abbreviation
24
+ b.text content
25
+ end
26
+ end
27
+
28
+ def to_hash
29
+ hash = { content: content }
30
+ hash[:abbreviation] = abbreviation if abbreviation
31
+ hash
32
+ end
33
+
34
+ def to_asciibib(prefix = "")
35
+ pref = prefix.empty? ? "stagename" : "#{prefix}.stagename"
36
+ output = "#{pref}.content:: #{content}\n"
37
+ output += "#{pref}.abbreviation:: #{abbreviation}\n" if abbreviation
38
+ output
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,55 @@
1
+ module Relaton
2
+ module Plateau
3
+ class TechnicalReportParser < Parser
4
+ def initialize(entry)
5
+ @entry = entry
6
+ super entry["technicalReport"]
7
+ end
8
+
9
+ private
10
+
11
+ def parse_docid
12
+ super << create_docid("PLATEAU Tech Report ##{@entry["slug"]}")
13
+ end
14
+
15
+ def parse_abstract
16
+ super << create_formatted_string(@item["subtitle"])
17
+ end
18
+
19
+ def parse_edition
20
+ RelatonBib::Edition.new content: "1.0", number: "1.0"
21
+ end
22
+
23
+ def parse_doctype
24
+ DocumentType.new type: "technical-report"
25
+ end
26
+
27
+ def parse_subdoctype
28
+ @entry["technicalReportCategories"]["nodes"].dig(0, "name")
29
+ end
30
+
31
+ def parse_date
32
+ super << create_date(@entry["date"])
33
+ end
34
+
35
+ def parse_link
36
+ super << create_link(@item["pdf"], "pdf")
37
+ end
38
+
39
+ def parse_filesize
40
+ @item["filesize"].to_i
41
+ end
42
+
43
+ def parse_keyword
44
+ @entry["globalTags"]["nodes"].map { |tag| tag["name"] }
45
+ end
46
+
47
+ def parse_structuredidentifier
48
+ strid = RelatonBib::StructuredIdentifier.new(
49
+ type: "Tech Report", class: parse_subdoctype, agency: ["PLATEAU"], docnumber: @entry["slug"]
50
+ )
51
+ RelatonBib::StructuredIdentifierCollection.new [strid]
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,8 @@
1
+ module Relaton
2
+ module Plateau
3
+ module Util
4
+ extend RelatonBib::Util
5
+ PROGNAME = "relaton-plateau".freeze
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Relaton
4
+ module Plateau
5
+ VERSION = "1.19.0"
6
+ end
7
+ end
@@ -0,0 +1,63 @@
1
+ module Relaton
2
+ module Plateau
3
+ class XMLParser < RelatonBib::XMLParser
4
+ class << self
5
+ private
6
+
7
+ #
8
+ # Parse bibitem data
9
+ #
10
+ # @param bibitem [Nokogiri::XML::Element] bibitem element
11
+ #
12
+ # @return [Hash] bibitem data
13
+ #
14
+ def item_data(doc)
15
+ resp = super
16
+ ext = doc.at("./ext")
17
+ return resp unless ext
18
+
19
+ resp[:cover] = fetch_cover ext
20
+ resp[:filesize] = fetch_filesize ext
21
+ resp[:stagename] = fetch_stagename ext
22
+ resp
23
+ end
24
+
25
+ def fetch_cover(ext)
26
+ img = ext.at("./cover/image")
27
+ return unless img
28
+
29
+ Cover.new fetch_image(img)
30
+ end
31
+
32
+ def fetch_filesize(elm)
33
+ fs = elm.at("./filesize")
34
+ return unless fs
35
+
36
+ fs.text.to_i
37
+ end
38
+
39
+ def fetch_stagename(ext)
40
+ sn = ext.at("./stagename")
41
+ return unless sn
42
+
43
+ Stagename.new content: sn.text, abbreviation: sn[:abbreviation]
44
+ end
45
+
46
+ #
47
+ # override RelatonBib::XMLParser#bib_item method
48
+ #
49
+ # @param item_hash [Hash]
50
+ #
51
+ # @return [RelatonCcsds::BibliographicItem]
52
+ #
53
+ def bib_item(item_hash)
54
+ BibItem.new(**item_hash)
55
+ end
56
+
57
+ def create_doctype(type)
58
+ DocumentType.new type: type.text, abbreviation: type[:abbreviation]
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,22 @@
1
+ require "net/http"
2
+ require "uri"
3
+ require "relaton/index"
4
+ require "relaton_bib"
5
+ require_relative "plateau/version"
6
+ require_relative "plateau/util"
7
+ require_relative "plateau/document_type"
8
+ require_relative "plateau/bibitem"
9
+ require_relative "plateau/bibliography"
10
+ require_relative "plateau/xml_parser"
11
+ require_relative "plateau/hash_converter"
12
+ require_relative "plateau/fetcher"
13
+
14
+ module Relaton
15
+ module Plateau
16
+ class Error < StandardError; end
17
+
18
+ def self.grammar_hash
19
+ Digest::MD5.hexdigest Relaton::Plateau::VERSION + RelatonBib::VERSION # grammars
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/relaton/plateau/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "relaton-plateau"
7
+ spec.version = Relaton::Plateau::VERSION
8
+ spec.authors = ["Ribose Inc."]
9
+ spec.email = ["open.source@ribose.com"]
10
+
11
+ spec.summary = "RelatonPlateau: retrieve Project PLATEAU bibliographic " \
12
+ "items"
13
+ spec.description = "Retrieve Project PLATEAU bibliographic items."
14
+
15
+ spec.homepage = "https://github.com/relaton/relaton-plateau"
16
+ spec.license = "BSD-2-Clause"
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
19
+ f.match(%r{^(test|spec|features)/})
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+ spec.required_ruby_version = Gem::Requirement.new(">= 3.0.0")
25
+
26
+ # spec.add_dependency "pubid", "~> 0.1.1"
27
+ spec.add_dependency "relaton-index", "~> 0.2.12"
28
+ spec.add_dependency "relaton-logger", "~> 0.2.0"
29
+ spec.add_dependency "relaton-bib", "~> 1.19.3"
30
+ end
@@ -0,0 +1,6 @@
1
+ module Relaton
2
+ module Plateau
3
+ VERSION: String
4
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: relaton-plateau
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.19.0
5
+ platform: ruby
6
+ authors:
7
+ - Ribose Inc.
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-07-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: relaton-index
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.2.12
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.2.12
27
+ - !ruby/object:Gem::Dependency
28
+ name: relaton-logger
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.2.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.2.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: relaton-bib
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.19.3
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.19.3
55
+ description: Retrieve Project PLATEAU bibliographic items.
56
+ email:
57
+ - open.source@ribose.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".github/workflows/rake.yml"
63
+ - ".github/workflows/release.yml"
64
+ - ".gitignore"
65
+ - ".rspec"
66
+ - ".rubocop.yml"
67
+ - CODE_OF_CONDUCT.md
68
+ - Gemfile
69
+ - README.adoc
70
+ - Rakefile
71
+ - bin/console
72
+ - bin/setup
73
+ - grammar/basicdoc.rng
74
+ - grammar/biblio-standoc.rng
75
+ - grammar/biblio.rng
76
+ - grammar/relaton-plateau-compile.rng
77
+ - grammar/relaton-plateau.rng
78
+ - lib/relaton/plateau.rb
79
+ - lib/relaton/plateau/bibitem.rb
80
+ - lib/relaton/plateau/bibliography.rb
81
+ - lib/relaton/plateau/cover.rb
82
+ - lib/relaton/plateau/document_type.rb
83
+ - lib/relaton/plateau/fetcher.rb
84
+ - lib/relaton/plateau/handbook_parser.rb
85
+ - lib/relaton/plateau/hash_converter.rb
86
+ - lib/relaton/plateau/parser.rb
87
+ - lib/relaton/plateau/processor.rb
88
+ - lib/relaton/plateau/stagename.rb
89
+ - lib/relaton/plateau/technical_report_parser.rb
90
+ - lib/relaton/plateau/util.rb
91
+ - lib/relaton/plateau/version.rb
92
+ - lib/relaton/plateau/xml_parser.rb
93
+ - relaton-plateau.gemspec
94
+ - sig/relaton/plateau.rbs
95
+ homepage: https://github.com/relaton/relaton-plateau
96
+ licenses:
97
+ - BSD-2-Clause
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: 3.0.0
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubygems_version: 3.3.27
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: 'RelatonPlateau: retrieve Project PLATEAU bibliographic items'
118
+ test_files: []