relaton-gb 0.11.0 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/grammars/basicdoc.rng +12 -55
- data/grammars/biblio.rng +109 -44
- data/grammars/gbstandard.rng +4 -1
- data/grammars/isodoc.rng +575 -28
- data/grammars/isostandard.rng +137 -472
- data/lib/relaton_gb/gb_bibliography.rb +13 -10
- data/lib/relaton_gb/scrapper.rb +16 -6
- data/lib/relaton_gb/version.rb +1 -1
- data/lib/relaton_gb/xml_parser.rb +5 -1
- data/relaton_gb.gemspec +1 -1
- metadata +6 -6
@@ -54,8 +54,8 @@ module RelatonGb
|
|
54
54
|
ret = get1(code, year, opts)
|
55
55
|
return nil if ret.nil?
|
56
56
|
|
57
|
-
ret.to_most_recent_reference unless year
|
58
|
-
ret.to_all_parts if opts[:all_parts]
|
57
|
+
ret = ret.to_most_recent_reference unless year
|
58
|
+
ret = ret.to_all_parts if opts[:all_parts]
|
59
59
|
ret
|
60
60
|
end
|
61
61
|
|
@@ -63,15 +63,15 @@ module RelatonGb
|
|
63
63
|
|
64
64
|
def fetch_ref_err(code, year, missed_years)
|
65
65
|
id = year ? "#{code}:#{year}" : code
|
66
|
-
warn "WARNING: no match found on the GB website for #{id}. "\
|
66
|
+
warn "[relaton-gb] WARNING: no match found on the GB website for #{id}. "\
|
67
67
|
"The code must be exactly like it is on the website."
|
68
|
-
warn "(There was no match for #{year}, though there were matches "\
|
68
|
+
warn "[relaton-gb] (There was no match for #{year}, though there were matches "\
|
69
69
|
"found for #{missed_years.join(', ')}.)" unless missed_years.empty?
|
70
70
|
if /\d-\d/ =~ code
|
71
|
-
warn "The provided document part may not exist, or the document "\
|
71
|
+
warn "[relaton-gb] The provided document part may not exist, or the document "\
|
72
72
|
"may no longer be published in parts."
|
73
73
|
else
|
74
|
-
warn "If you wanted to cite all document parts for the reference, "\
|
74
|
+
warn "[relaton-gb] If you wanted to cite all document parts for the reference, "\
|
75
75
|
"use \"#{code} (all parts)\".\nIf the document is not a standard, "\
|
76
76
|
"use its document type abbreviation (TS, TR, PAS, Guide)."
|
77
77
|
end
|
@@ -83,15 +83,18 @@ module RelatonGb
|
|
83
83
|
searchcode = code + (year.nil? ? "" : "-#{year}")
|
84
84
|
result = search_filter(searchcode) || return
|
85
85
|
ret = results_filter(result, year)
|
86
|
-
|
87
|
-
|
88
|
-
|
86
|
+
if ret[:ret]
|
87
|
+
warn "[relaton-gb] (\"#{code}\") found #{ret[:ret].docidentifier.first.id}"
|
88
|
+
ret[:ret]
|
89
|
+
else
|
90
|
+
fetch_ref_err(code, year, ret[:years])
|
91
|
+
end
|
89
92
|
end
|
90
93
|
|
91
94
|
def search_filter(code)
|
92
95
|
# search filter needs to incorporate year
|
93
96
|
docidrx = %r{^[^\s]+\s[\d\.-]+}
|
94
|
-
warn "
|
97
|
+
warn "[relaton-gb] (\"#{code}\") fetching..."
|
95
98
|
result = search(code)
|
96
99
|
result.select do |hit|
|
97
100
|
hit.docref && hit.docref.match(docidrx).to_s.include?(code)
|
data/lib/relaton_gb/scrapper.rb
CHANGED
@@ -55,18 +55,28 @@ module RelatonGb
|
|
55
55
|
# @param docref [Strings]
|
56
56
|
# @return [Array<Hash>]
|
57
57
|
def get_contributors(doc, docref)
|
58
|
-
gb_en = GbAgencies::Agencies.new("en", {}, "")
|
59
|
-
gb_zh = GbAgencies::Agencies.new("zh", {}, "")
|
60
58
|
name = docref.match(/^[^\s]+/).to_s
|
61
59
|
name.sub!(%r{/[TZ]$}, "") unless name =~ /^GB/
|
62
60
|
gbtype = get_gbtype(doc, docref)
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
61
|
+
orgs = %w[en zh].map { |l| org(l, name, gbtype) }.compact
|
62
|
+
return [] unless orgs.any?
|
63
|
+
|
64
|
+
entity = RelatonBib::Organization.new name: orgs
|
67
65
|
[{ entity: entity, role: [type: "publisher"] }]
|
68
66
|
end
|
69
67
|
|
68
|
+
# @param lang [String]
|
69
|
+
# @param name [String]
|
70
|
+
# @param gbtype [Hash]
|
71
|
+
# @return [Hash]
|
72
|
+
def org(lang, name, gbtype)
|
73
|
+
ag = GbAgencies::Agencies.new(lang, {}, "")
|
74
|
+
content = ag.standard_agency1(gbtype[:scope], name, gbtype[:mandate])
|
75
|
+
return unless content
|
76
|
+
|
77
|
+
{ language: lang, content: content }
|
78
|
+
end
|
79
|
+
|
70
80
|
# @param doc [Nokogiri::HTML::Document]
|
71
81
|
# @return [Array<Hash>]
|
72
82
|
# * :title_intro [String]
|
data/lib/relaton_gb/version.rb
CHANGED
@@ -6,7 +6,11 @@ module RelatonGb
|
|
6
6
|
def from_xml(xml)
|
7
7
|
doc = Nokogiri::XML(xml)
|
8
8
|
gbitem = doc.at "/bibitem|/bibdata"
|
9
|
-
|
9
|
+
if gbitem
|
10
|
+
GbBibliographicItem.new item_data(gbitem)
|
11
|
+
else
|
12
|
+
warn "[relato-gb] can't find bibitem or bibdata element in the XML"
|
13
|
+
end
|
10
14
|
end
|
11
15
|
|
12
16
|
private
|
data/relaton_gb.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: relaton-gb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: debase
|
@@ -182,16 +182,16 @@ dependencies:
|
|
182
182
|
name: relaton-iso-bib
|
183
183
|
requirement: !ruby/object:Gem::Requirement
|
184
184
|
requirements:
|
185
|
-
- - "
|
185
|
+
- - ">="
|
186
186
|
- !ruby/object:Gem::Version
|
187
|
-
version: 0.
|
187
|
+
version: 1.0.1
|
188
188
|
type: :runtime
|
189
189
|
prerelease: false
|
190
190
|
version_requirements: !ruby/object:Gem::Requirement
|
191
191
|
requirements:
|
192
|
-
- - "
|
192
|
+
- - ">="
|
193
193
|
- !ruby/object:Gem::Version
|
194
|
-
version: 0.
|
194
|
+
version: 1.0.1
|
195
195
|
description: 'RelatonGb: retrieve Chinese GB Standards for bibliographic use using
|
196
196
|
the BibliographicItem model.'
|
197
197
|
email:
|