relaton-render 0.5.13 → 0.5.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.adoc +1 -0
- data/lib/isodoc/i18n.rb +2 -2
- data/lib/isodoc-yaml/i18n-ar.yaml +1 -0
- data/lib/isodoc-yaml/i18n-de.yaml +1 -0
- data/lib/isodoc-yaml/i18n-en.yaml +1 -0
- data/lib/isodoc-yaml/i18n-es.yaml +1 -0
- data/lib/isodoc-yaml/i18n-fr.yaml +1 -0
- data/lib/isodoc-yaml/i18n-ja.yaml +46 -0
- data/lib/isodoc-yaml/i18n-ru.yaml +1 -0
- data/lib/isodoc-yaml/i18n-zh-Hans.yaml +1 -0
- data/lib/isodoc-yaml/i18n-zh-Hant.yaml +1 -0
- data/lib/relaton/render/general/config.yml +1 -1
- data/lib/relaton/render/general/render.rb +44 -0
- data/lib/relaton/render/parse/parse.rb +1 -1
- data/lib/relaton/render/parse/parse_contributors.rb +1 -1
- data/lib/relaton/render/parse/parse_extract.rb +22 -3
- data/lib/relaton/render/template/template.rb +7 -5
- data/lib/relaton/render/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0af6169e02ec5d26e446cde74cd73a1f46e35c8940d30f6c510f4be4de0088e6
|
|
4
|
+
data.tar.gz: f57803b06b0cdd09d3a0a7c88a2e33755fc976c4e32d15d5ad060442ac2a7c10
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ea4a04f26b246e60e332e6b77a9ebbdac20c0ae80e77b68e80446930a3eff08b12e598eec6d35919aebbc17e07d6ae4b56aa6b808b752d877ca1cb9f7ce10d16
|
|
7
|
+
data.tar.gz: 31712a34848e3564f871e7b41044d8082d2ee19036372b002a46670c4b8dc8ce9a206d6a4ae1fb783ea501fea20604753c2c9946e804afa36576a75b62aa74db
|
data/README.adoc
CHANGED
|
@@ -158,6 +158,7 @@ drawn from the bibliographic item:
|
|
|
158
158
|
| authorizer | ./contributor[role/@type = 'authorizer']/organization/name \| ./contributor[role/@type = 'publisher']/organization/name | | Y |
|
|
159
159
|
| authoritative_identifier | ./docidentifier[not(@type = 'metanorma' or @type = 'ordinal' or @type = 'ISBN' or @type = 'ISSN' or @type = 'DOI')] | Y | |
|
|
160
160
|
| other_identifier | ./docidentifier[@type = 'ISBN' or @type = 'ISSN' or @type = 'DOI'] | Y | | By default, each such identifier is prefixed with its type and colon
|
|
161
|
+
| doi | ./docidentifier[@type = 'DOI'] | Y | | No prefix supplied
|
|
161
162
|
| status | ./status | | | Rendering varies by flavour
|
|
162
163
|
| uri | ./uri[@type = 'citation' or @type = 'uri' or @type = 'src' or true] | | | If multiples, prioritise language match. Always exclude DOI: that is not where the resource is available from
|
|
163
164
|
| access_location | ./accessLocation | | Y |
|
data/lib/isodoc/i18n.rb
CHANGED
|
@@ -5,7 +5,7 @@ module IsoDoc
|
|
|
5
5
|
class RelatonRenderI18n < I18n
|
|
6
6
|
def load_yaml1(lang, script)
|
|
7
7
|
case lang
|
|
8
|
-
when "en", "fr", "ru", "de", "es", "ar"
|
|
8
|
+
when "en", "fr", "ru", "de", "es", "ar", "ja"
|
|
9
9
|
load_yaml2(lang)
|
|
10
10
|
when "zh"
|
|
11
11
|
case script
|
|
@@ -25,7 +25,7 @@ module IsoDoc
|
|
|
25
25
|
# because of the potential for script mixing
|
|
26
26
|
def cleanup_entities(hash, is_xml: true)
|
|
27
27
|
ret = super
|
|
28
|
-
if @lang == "ar" &&
|
|
28
|
+
if @lang == "ar" && ret.include?("%")
|
|
29
29
|
ret = "؜#{ret}؜"
|
|
30
30
|
end
|
|
31
31
|
ret
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
in:
|
|
2
|
+
at:
|
|
3
|
+
and: と
|
|
4
|
+
author_and: と
|
|
5
|
+
updated: 更新しました
|
|
6
|
+
viewed: 見た
|
|
7
|
+
version: バージョン
|
|
8
|
+
also_pub_as: 次のようにも出版されています
|
|
9
|
+
no_date: 日付なし。
|
|
10
|
+
no_place: 都市はありません。
|
|
11
|
+
date_formats:
|
|
12
|
+
month_year: yMMMM
|
|
13
|
+
day_month_year: to_long_s
|
|
14
|
+
date_time: to_long_s
|
|
15
|
+
ordinal_keys: []
|
|
16
|
+
OrdinalRules: digits-ordinal
|
|
17
|
+
edition: 版
|
|
18
|
+
edition_ordinal: "%Ordinal edition"
|
|
19
|
+
draft: "下書き %"
|
|
20
|
+
editor:
|
|
21
|
+
sg: 編
|
|
22
|
+
pl: 編
|
|
23
|
+
qq-open: <em>
|
|
24
|
+
qq-close: </em>
|
|
25
|
+
q-open:
|
|
26
|
+
q-close:
|
|
27
|
+
extent:
|
|
28
|
+
page:
|
|
29
|
+
sg: "ページ%"
|
|
30
|
+
pl: "ページ%"
|
|
31
|
+
volume:
|
|
32
|
+
sg: "巻%"
|
|
33
|
+
pl: "巻%"
|
|
34
|
+
issue:
|
|
35
|
+
sg: "いいえ%"
|
|
36
|
+
pl: "いいえ%"
|
|
37
|
+
size:
|
|
38
|
+
page:
|
|
39
|
+
sg: "ページ%"
|
|
40
|
+
pl: "ページ%"
|
|
41
|
+
volume:
|
|
42
|
+
sg: "巻%"
|
|
43
|
+
pl: "巻%"
|
|
44
|
+
issue:
|
|
45
|
+
sg: "いいえ%"
|
|
46
|
+
pl: "いいえ%"
|
|
@@ -48,7 +48,7 @@ template:
|
|
|
48
48
|
software: "{{ creatornames }} ({{ role}}) . {{labels['qq-open']}}{{ title }}{{labels['qq-close']}} . {{ labels['version'] | capitalize }}_{{ edition_raw }}. {{medium | capitalize}}. {{place}}: {{publisher}}. {{date}}. {{ labels['updated'] | capitalize }}:_{{date_updated}}. {{ authoritative_identifier | join: '. ' }}. {{ other_identifier | join: '. ' }}. {{ uri }}. {{size}}. {{ extent}}. [{{ labels['viewed'] }}:_{{date_accessed}}]. "
|
|
49
49
|
# TODO: omitted: author ids, subsidiary titles, subsidiary creators, copyright, license, distributor, system requirements, relationships
|
|
50
50
|
electronic resource: software
|
|
51
|
-
standard: "{{ creatornames }} ({{ role}}) . {{ authoritative_identifier | join '|' }}: {{labels['qq-open']}}{{ title }}{{labels['qq-close']}} . {{ labels['in'] | capitalize }}:_{{ series_title }}. {{ medium | capitalize }}. {{ edition | capitalize_first }}. {{ place }}: {{ publisher }}. {{date}}. {{size}}. {{ extent }}. {{ other_identifier | join: '. ' }}. {{ uri }}. {{ labels['at'] | capitalize}}:_{{ access_location }}. [{{ labels['viewed'] }}:_{{date_accessed}}]."
|
|
51
|
+
standard: "{{ creatornames }} ({{ role}}) . {{ authoritative_identifier | join: '|' }}: {{labels['qq-open']}}{{ title }}{{labels['qq-close']}} . {{ labels['in'] | capitalize }}:_{{ series_title }}. {{ medium | capitalize }}. {{ edition | capitalize_first }}. {{ place }}: {{ publisher }}. {{date}}. {{size}}. {{ extent }}. {{ other_identifier | join: '. ' }}. {{ uri }}. {{ labels['at'] | capitalize}}:_{{ access_location }}. [{{ labels['viewed'] }}:_{{date_accessed}}]."
|
|
52
52
|
# TODO: omitted: author ids, subsidiary titles, rights metadata, distributor, persistent identifier, item attributes, relationships
|
|
53
53
|
techreport: standard
|
|
54
54
|
dataset: "{{ creatornames }} ({{ role }}) . {{labels['qq-open']}}{{ title }}{{labels['qq-close']}} . {{ labels['version'] | capitalize }}_{{ edition_raw }}. {{medium | capitalize }}. {{ labels['in'] | capitalize }}:_{{series}}. {{date}}. {{ labels['updated'] | capitalize }}:_{{date_updated}}. {{ authoritative_identifier | join: '. ' }}. {{ other_identifier | join: '. ' }}. {{ uri }}. {{ size }}. {{ extent}}. [{{ labels['viewed'] }}:_{{date_accessed}}]. "
|
|
@@ -2,7 +2,9 @@ require_relative "render_classes"
|
|
|
2
2
|
require_relative "citations"
|
|
3
3
|
require "yaml"
|
|
4
4
|
require "liquid"
|
|
5
|
+
require "date"
|
|
5
6
|
require "relaton_bib"
|
|
7
|
+
require "net/http"
|
|
6
8
|
require_relative "../template/template"
|
|
7
9
|
require_relative "../../../isodoc/i18n"
|
|
8
10
|
|
|
@@ -131,8 +133,16 @@ module Relaton
|
|
|
131
133
|
end
|
|
132
134
|
|
|
133
135
|
def parse1(doc)
|
|
136
|
+
r = doc.relation.select { |x| x.type == "hasRepresentation" }
|
|
137
|
+
.map { |x| @i18n.also_pub_as + parse_single_bibitem(x.bibitem) }
|
|
138
|
+
out = [parse_single_bibitem(doc)] + r
|
|
139
|
+
@i18n.l10n(out.join(". ").gsub(".. ", ". "))
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def parse_single_bibitem(doc)
|
|
134
143
|
r = renderer(doc.type || "misc")
|
|
135
144
|
data = @parse.extract(doc)
|
|
145
|
+
enhance_data(data, r.template_raw)
|
|
136
146
|
data_liquid = @fieldsklass.new(renderer: self)
|
|
137
147
|
.compound_fields_format(data)
|
|
138
148
|
valid_parse(@i18n.l10n(r.render(data_liquid)))
|
|
@@ -173,6 +183,23 @@ module Relaton
|
|
|
173
183
|
end
|
|
174
184
|
end
|
|
175
185
|
|
|
186
|
+
# add to liquid data based on template
|
|
187
|
+
def enhance_data(data, template)
|
|
188
|
+
template.is_a?(String) or return
|
|
189
|
+
add_date_accessed(data, template)
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
def add_date_accessed(data, template)
|
|
193
|
+
(/\{\{\s*date_accessed\s*\}\}/.match?(template) &&
|
|
194
|
+
/\{\{\s*uri\s*\}\}/.match?(template) &&
|
|
195
|
+
data[:uri_raw] && !data[:date_accessed]) or return
|
|
196
|
+
if url_exist?(data[:uri_raw])
|
|
197
|
+
data[:date_accessed] = { on: ::Date.today.to_s }
|
|
198
|
+
else
|
|
199
|
+
warn "BIBLIOGRAPHY WARNING: cannot access #{data[:uri_raw]}"
|
|
200
|
+
end
|
|
201
|
+
end
|
|
202
|
+
|
|
176
203
|
private
|
|
177
204
|
|
|
178
205
|
def template_hash_fill(templates)
|
|
@@ -182,6 +209,23 @@ module Relaton
|
|
|
182
209
|
m[type] = template
|
|
183
210
|
end
|
|
184
211
|
end
|
|
212
|
+
|
|
213
|
+
def url_exist?(url_string)
|
|
214
|
+
res = access_url(url_string)
|
|
215
|
+
res.is_a?(Net::HTTPRedirection) and return url_exist?(res["location"])
|
|
216
|
+
res.code[0] != "4"
|
|
217
|
+
rescue Errno::ENOENT, SocketError
|
|
218
|
+
false # false if can't find the server
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
def access_url(url_string)
|
|
222
|
+
url = URI.parse(url_string)
|
|
223
|
+
req = Net::HTTP.new(url.host, url.port)
|
|
224
|
+
req.use_ssl = (url.scheme == "https")
|
|
225
|
+
path = url.path or return false
|
|
226
|
+
path.empty? and path = "/"
|
|
227
|
+
req.request_head(path)
|
|
228
|
+
end
|
|
185
229
|
end
|
|
186
230
|
end
|
|
187
231
|
end
|
|
@@ -22,7 +22,7 @@ module Relaton
|
|
|
22
22
|
def simple_xml2hash(doc)
|
|
23
23
|
creators, role = creatornames(doc)
|
|
24
24
|
{ type: type(doc), title: title(doc), extent_raw: extent(doc),
|
|
25
|
-
size_raw: size(doc), uri_raw: uri(doc),
|
|
25
|
+
size_raw: size(doc), uri_raw: uri(doc), doi: doi(doc),
|
|
26
26
|
authoritative_identifier: authoritative_identifier(doc),
|
|
27
27
|
other_identifier: other_identifier(doc),
|
|
28
28
|
status: status(doc), creators: creators, role_raw: role }
|
|
@@ -91,9 +91,15 @@ module Relaton
|
|
|
91
91
|
end
|
|
92
92
|
|
|
93
93
|
def authoritative_identifier(doc)
|
|
94
|
-
doc.docidentifier.each_with_object([]) do |id, ret|
|
|
95
|
-
|
|
94
|
+
out = doc.docidentifier.each_with_object([]) do |id, ret|
|
|
95
|
+
id.primary && !authoritative_identifier_exclude.include?(id.type) and
|
|
96
|
+
ret << id.id
|
|
97
|
+
end
|
|
98
|
+
out.empty? and out = doc.docidentifier.each_with_object([]) do |id, ret|
|
|
99
|
+
authoritative_identifier_exclude.include?(id_type_norm(id)) or
|
|
100
|
+
ret << id.id
|
|
96
101
|
end
|
|
102
|
+
out
|
|
97
103
|
end
|
|
98
104
|
|
|
99
105
|
def authoritative_identifier_exclude
|
|
@@ -102,7 +108,7 @@ module Relaton
|
|
|
102
108
|
|
|
103
109
|
def other_identifier(doc)
|
|
104
110
|
doc.docidentifier.each_with_object([]) do |id, ret|
|
|
105
|
-
type = id
|
|
111
|
+
type = id_type_norm(id)
|
|
106
112
|
other_identifier_include.include? type or next
|
|
107
113
|
ret << @i18n.l10n("#{type}: #{id.id}")
|
|
108
114
|
end
|
|
@@ -112,6 +118,19 @@ module Relaton
|
|
|
112
118
|
%w(ISSN ISBN DOI)
|
|
113
119
|
end
|
|
114
120
|
|
|
121
|
+
def doi(doc)
|
|
122
|
+
out = doc.docidentifier.each_with_object([]) do |id, ret|
|
|
123
|
+
type = id.type&.sub(/^(DOI)\..*$/i, "\\1") or next
|
|
124
|
+
type.casecmp("doi").zero? or next
|
|
125
|
+
ret << id.id
|
|
126
|
+
end
|
|
127
|
+
out.empty? ? nil : out
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def id_type_norm(id)
|
|
131
|
+
id.type&.sub(/^(ISBN|ISSN)\..*$/i) { $1.upcase }
|
|
132
|
+
end
|
|
133
|
+
|
|
115
134
|
def uri(doc)
|
|
116
135
|
uri = nil
|
|
117
136
|
%w(citation uri src).each do |t|
|
|
@@ -5,6 +5,8 @@ module Relaton
|
|
|
5
5
|
module Render
|
|
6
6
|
module Template
|
|
7
7
|
class General
|
|
8
|
+
attr_reader :template_raw
|
|
9
|
+
|
|
8
10
|
def initialize(opt = {})
|
|
9
11
|
@htmlentities = HTMLEntities.new
|
|
10
12
|
customise_liquid
|
|
@@ -43,7 +45,7 @@ module Relaton
|
|
|
43
45
|
|
|
44
46
|
def punct_field?(name)
|
|
45
47
|
name or return false
|
|
46
|
-
name = name.gsub(
|
|
48
|
+
name = name.gsub("'", '"')
|
|
47
49
|
%w(labels["qq-open"] labels["qq-close"] labels["q-open"]
|
|
48
50
|
labels["q-close"]).include?(name)
|
|
49
51
|
end
|
|
@@ -60,7 +62,7 @@ module Relaton
|
|
|
60
62
|
a[3] = "}}#{FIELD_DELIM}"
|
|
61
63
|
end
|
|
62
64
|
a.join
|
|
63
|
-
end.join.gsub(
|
|
65
|
+
end.join.gsub("\t", " ")
|
|
64
66
|
t.gsub(/\}\}#{FIELD_DELIM}\|/o, "}}#{FIELD_DELIM}\t")
|
|
65
67
|
.gsub(/\|#{FIELD_DELIM}\{\{/o, "\t#{FIELD_DELIM}{{")
|
|
66
68
|
end
|
|
@@ -96,7 +98,7 @@ module Relaton
|
|
|
96
98
|
.sub(/^\s*[,.:;]\s*/, "")
|
|
97
99
|
.sub(/[,:;]\s*$/, "")
|
|
98
100
|
.gsub(/(?<!\\)_/, " ")
|
|
99
|
-
.gsub(
|
|
101
|
+
.gsub("\\_", "_")
|
|
100
102
|
.gsub(/#{NON_SPACING_DELIM}/o, "").gsub(/\s+/, " ")
|
|
101
103
|
end
|
|
102
104
|
|
|
@@ -110,7 +112,7 @@ module Relaton
|
|
|
110
112
|
when Array
|
|
111
113
|
hash.map { |v| liquid_hash(v) }
|
|
112
114
|
when String
|
|
113
|
-
hash.empty? ? nil : hash.gsub(
|
|
115
|
+
hash.empty? ? nil : hash.gsub("_", "\\_").gsub(/ /, "_")
|
|
114
116
|
else hash
|
|
115
117
|
end
|
|
116
118
|
end
|
|
@@ -165,7 +167,7 @@ module Relaton
|
|
|
165
167
|
t = nametemplate_split(template)
|
|
166
168
|
|
|
167
169
|
mid = (1..size - 2).each_with_object([]) do |i, m|
|
|
168
|
-
m << t[1].gsub(
|
|
170
|
+
m << t[1].gsub("[1]", "[#{i}]")
|
|
169
171
|
end
|
|
170
172
|
t[1] = mid.join
|
|
171
173
|
t[2].gsub!(/\[\d+\]/, "[#{size - 1}]")
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: relaton-render
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.5.
|
|
4
|
+
version: 0.5.15
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2023-
|
|
11
|
+
date: 2023-09-29 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -201,6 +201,7 @@ files:
|
|
|
201
201
|
- lib/isodoc-yaml/i18n-en.yaml
|
|
202
202
|
- lib/isodoc-yaml/i18n-es.yaml
|
|
203
203
|
- lib/isodoc-yaml/i18n-fr.yaml
|
|
204
|
+
- lib/isodoc-yaml/i18n-ja.yaml
|
|
204
205
|
- lib/isodoc-yaml/i18n-ru.yaml
|
|
205
206
|
- lib/isodoc-yaml/i18n-zh-Hans.yaml
|
|
206
207
|
- lib/isodoc-yaml/i18n-zh-Hant.yaml
|