relaton-render 0.1.0 → 3.0.0.pre.alpha.25
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/.github/workflows/rake.yml +4 -1
- data/.github/workflows/release.yml +24 -0
- data/.gitignore +14 -0
- data/.rubocop.yml +2 -2
- data/Gemfile +17 -1
- data/README.adoc +61 -197
- data/docs/citation-style-pack.adoc +367 -0
- data/lib/relaton/render/general.rb +305 -0
- data/lib/relaton/render/iso690/element.rb +153 -0
- data/lib/relaton/render/iso690/elements/access.rb +44 -0
- data/lib/relaton/render/iso690/elements/authorizer.rb +30 -0
- data/lib/relaton/render/iso690/elements/citeid.rb +39 -0
- data/lib/relaton/render/iso690/elements/component_part.rb +99 -0
- data/lib/relaton/render/iso690/elements/creator.rb +258 -0
- data/lib/relaton/render/iso690/elements/edition.rb +92 -0
- data/lib/relaton/render/iso690/elements/extent.rb +71 -0
- data/lib/relaton/render/iso690/elements/identifier.rb +46 -0
- data/lib/relaton/render/iso690/elements/location.rb +73 -0
- data/lib/relaton/render/iso690/elements/medium.rb +32 -0
- data/lib/relaton/render/iso690/elements/numeration.rb +26 -0
- data/lib/relaton/render/iso690/elements/production.rb +92 -0
- data/lib/relaton/render/iso690/elements/pub_date.rb +56 -0
- data/lib/relaton/render/iso690/elements/series.rb +66 -0
- data/lib/relaton/render/iso690/elements/size.rb +41 -0
- data/lib/relaton/render/iso690/elements/status.rb +30 -0
- data/lib/relaton/render/iso690/elements/stddoc.rb +40 -0
- data/lib/relaton/render/iso690/elements/title.rb +56 -0
- data/lib/relaton/render/iso690/elements/updated.rb +38 -0
- data/lib/relaton/render/iso690/elements.rb +67 -0
- data/lib/relaton/render/iso690/fields.rb +142 -0
- data/lib/relaton/render/iso690/i18n/en.yml +47 -0
- data/lib/relaton/render/iso690/i18n/fr.yml +14 -0
- data/lib/relaton/render/iso690/i18n/ja.yml +38 -0
- data/lib/relaton/render/iso690/i18n.rb +83 -0
- data/lib/relaton/render/iso690/identifier_kinds.rb +29 -0
- data/lib/relaton/render/iso690/index_renderer.rb +57 -0
- data/lib/relaton/render/iso690/kinds.rb +53 -0
- data/lib/relaton/render/iso690/renderer.rb +148 -0
- data/lib/relaton/render/iso690/style/locale.rb +53 -0
- data/lib/relaton/render/iso690/style/name_form.rb +87 -0
- data/lib/relaton/render/iso690/style/scheme.rb +33 -0
- data/lib/relaton/render/iso690/style/sort_rule.rb +25 -0
- data/lib/relaton/render/iso690/style/template_map.rb +40 -0
- data/lib/relaton/render/iso690/style/type_template.rb +37 -0
- data/lib/relaton/render/iso690/style.rb +119 -0
- data/lib/relaton/render/iso690/styles/author-date.yml +31 -0
- data/lib/relaton/render/iso690/template.rb +248 -0
- data/lib/relaton/render/iso690.rb +26 -0
- data/lib/relaton/render/version.rb +5 -0
- data/lib/relaton-render.rb +12 -5
- data/relaton-render.gemspec +7 -11
- metadata +57 -86
- data/lib/isodoc/i18n.rb +0 -24
- data/lib/isodoc-yaml/i18n-ar.yaml +0 -2
- data/lib/isodoc-yaml/i18n-de.yaml +0 -2
- data/lib/isodoc-yaml/i18n-en.yaml +0 -22
- data/lib/isodoc-yaml/i18n-es.yaml +0 -2
- data/lib/isodoc-yaml/i18n-fr.yaml +0 -2
- data/lib/isodoc-yaml/i18n-ru.yaml +0 -23
- data/lib/isodoc-yaml/i18n-zh-Hans.yaml +0 -2
- data/lib/parse/parse.rb +0 -54
- data/lib/parse/parse_contributors.rb +0 -96
- data/lib/parse/parse_extract.rb +0 -155
- data/lib/relaton/config.yml +0 -67
- data/lib/relaton/render.rb +0 -123
- data/lib/relaton/render_classes.rb +0 -126
- data/lib/relaton/render_fields.rb +0 -151
- data/lib/relaton/version.rb +0 -5
- data/lib/template/template.rb +0 -152
- data/lib/utils/utils.rb +0 -27
data/lib/parse/parse.rb
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
require "nokogiri"
|
|
2
|
-
require "twitter_cldr"
|
|
3
|
-
require_relative "parse_contributors"
|
|
4
|
-
require_relative "parse_extract"
|
|
5
|
-
|
|
6
|
-
class Iso690Parse
|
|
7
|
-
def initialize; end
|
|
8
|
-
|
|
9
|
-
def extract(doc)
|
|
10
|
-
host = doc.at("./relation[@type = 'includedIn']/bibitem")
|
|
11
|
-
simple_xml2hash(doc).merge(simple_or_host_xml2hash(doc, host))
|
|
12
|
-
.merge(host_xml2hash(host))
|
|
13
|
-
.merge(series_xml2hash(doc, host))
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def simple_xml2hash(doc)
|
|
17
|
-
creators, role = creatornames(doc)
|
|
18
|
-
{ type: type(doc), title: title(doc), extent_raw: extent(doc),
|
|
19
|
-
standardidentifier: standardidentifier(doc), uri: uri(doc),
|
|
20
|
-
status: status(doc), creators: creators, role_raw: role }
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def simple_or_host_xml2hash(doc, host)
|
|
24
|
-
{ edition_raw: edition(doc, host), medium: medium(doc, host),
|
|
25
|
-
place: place(doc, host), publisher: publisher(doc, host),
|
|
26
|
-
distributor: distributor(doc, host),
|
|
27
|
-
access_location: access_location(doc, host),
|
|
28
|
-
date: date(doc, host), date_updated: date_updated(doc, host),
|
|
29
|
-
date_accessed: date_accessed(doc, host) }
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def host_xml2hash(host)
|
|
33
|
-
creators, role = creatornames(host)
|
|
34
|
-
{ host_creators: creators, host_role_raw: role, host_title: title(host) }
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def series_xml2hash(doc, host)
|
|
38
|
-
series = doc.at("./series[@type = 'main']") ||
|
|
39
|
-
doc.at("./series[not(@type)]") || doc.at("./series")
|
|
40
|
-
host and series ||=
|
|
41
|
-
host.at("./series[@type = 'main']") ||
|
|
42
|
-
host.at("./series[not(@type)]") || host.at("./series")
|
|
43
|
-
|
|
44
|
-
series_xml2hash1(series)
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def series_xml2hash1(series)
|
|
48
|
-
return {} unless series
|
|
49
|
-
|
|
50
|
-
{ series_title: series_title(series), series_abbr: series_abbr(series),
|
|
51
|
-
series_run: series_run(series), series_num: series_num(series),
|
|
52
|
-
series_partnumber: series_partnumber(series) }
|
|
53
|
-
end
|
|
54
|
-
end
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
class Iso690Parse
|
|
2
|
-
def extract_orgname(org)
|
|
3
|
-
name = org.at("./name")
|
|
4
|
-
name&.text
|
|
5
|
-
end
|
|
6
|
-
|
|
7
|
-
def extract_personname(person)
|
|
8
|
-
surname = person.at("./name/surname") || person.at("./name/completename")
|
|
9
|
-
given, middle, initials = given_and_middle_name(person)
|
|
10
|
-
{ surname: surname&.text,
|
|
11
|
-
given: given,
|
|
12
|
-
middle: middle,
|
|
13
|
-
initials: initials }
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def given_and_middle_name(person)
|
|
17
|
-
forenames = person.xpath("./name/forename")&.map(&:text)
|
|
18
|
-
initials = person.xpath("./name/initial")&.map(&:text)
|
|
19
|
-
forenames.empty? and initials.empty? and return [nil, nil, nil]
|
|
20
|
-
forenames.empty? and forenames = initials.dup
|
|
21
|
-
initials.empty? and initials = forenames.map { |x| x[0] }
|
|
22
|
-
[forenames.first, forenames[1..-1], initials]
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def extractname(contributor)
|
|
26
|
-
org = contributor.at("./organization")
|
|
27
|
-
person = contributor.at("./person")
|
|
28
|
-
return { surname: extract_orgname(org) } if org
|
|
29
|
-
return extract_personname(person) if person
|
|
30
|
-
|
|
31
|
-
nil
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def contributor_role(contributors)
|
|
35
|
-
return nil unless contributors.length.positive?
|
|
36
|
-
|
|
37
|
-
desc = contributors[0].at("role/description")&.text
|
|
38
|
-
type = contributors[0].at("role/@type")&.text
|
|
39
|
-
return nil if %w(author publisher).include?(type) && desc.nil?
|
|
40
|
-
|
|
41
|
-
type
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def creatornames(doc)
|
|
45
|
-
cr = creatornames1(doc)
|
|
46
|
-
cr.empty? and return [nil, nil]
|
|
47
|
-
[cr.map { |x| extractname(x) }, contributor_role(cr)]
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
def creatornames1(doc)
|
|
51
|
-
cr = []
|
|
52
|
-
return cr if doc.nil?
|
|
53
|
-
|
|
54
|
-
%w(author performer adapter translator editor publisher distributor)
|
|
55
|
-
.each do |r|
|
|
56
|
-
add = doc.xpath("./contributor[role/@type = '#{r}']")
|
|
57
|
-
next if add.empty?
|
|
58
|
-
|
|
59
|
-
cr = add and break
|
|
60
|
-
end
|
|
61
|
-
cr.empty? and cr = doc.xpath("./contributor")
|
|
62
|
-
cr
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def date1(date)
|
|
66
|
-
on = date.at("./on")
|
|
67
|
-
from = date.at("./from")
|
|
68
|
-
to = date.at("./to")
|
|
69
|
-
return { on: on.text } if on
|
|
70
|
-
return { from: from.text, to: to&.text } if from
|
|
71
|
-
|
|
72
|
-
nil
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
def date(doc, host)
|
|
76
|
-
x = doc.at("./date[@type = 'issued']") ||
|
|
77
|
-
doc.at("./date[@type = 'circulated']") ||
|
|
78
|
-
doc.at("./date") ||
|
|
79
|
-
host&.at("./date[@type = 'issued']") ||
|
|
80
|
-
host&.at("./date[@type = 'circulated']") ||
|
|
81
|
-
host&.at("./date") or return nil
|
|
82
|
-
date1(x)
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
def date_updated(doc, host)
|
|
86
|
-
x = doc.at("./date[@type = 'updated']") ||
|
|
87
|
-
host&.at("./date[@type = 'updated']") or return nil
|
|
88
|
-
date1(x)
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
def date_accessed(doc, host)
|
|
92
|
-
x = doc.at("./date[@type = 'accessed']") ||
|
|
93
|
-
host&.at("./date[@type = 'accessed']") or return nil
|
|
94
|
-
date1(x)
|
|
95
|
-
end
|
|
96
|
-
end
|
data/lib/parse/parse_extract.rb
DELETED
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
class Iso690Parse
|
|
2
|
-
def title(doc)
|
|
3
|
-
doc&.at("./title")&.text
|
|
4
|
-
end
|
|
5
|
-
|
|
6
|
-
def medium(doc, host)
|
|
7
|
-
x = doc.at("./medium") || host&.at("./medium") or return nil
|
|
8
|
-
|
|
9
|
-
%w(content genre form carrier size scale).each_with_object([]) do |i, m|
|
|
10
|
-
m << x.at("./#{i}")&.text
|
|
11
|
-
end.compact.join(", ")
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def blank?(text)
|
|
15
|
-
text.nil? || text.empty?
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def edition(doc, host)
|
|
19
|
-
x = doc.at("./edition") || host&.at("./edition") or return nil
|
|
20
|
-
|
|
21
|
-
x.text
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def place(doc, host)
|
|
25
|
-
x = doc.at("./place") || host&.at("./place") or return nil
|
|
26
|
-
|
|
27
|
-
x.text
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def publisher(doc, host)
|
|
31
|
-
x = doc.at("./contributor[role/@type = 'publisher']/organization/name") ||
|
|
32
|
-
host&.at("./contributor[role/@type = 'publisher']/organization/name") or
|
|
33
|
-
return nil
|
|
34
|
-
x.text
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def distributor(doc, host)
|
|
38
|
-
x = doc.at("./contributor[role/@type = 'distributor']/organization/name") ||
|
|
39
|
-
host&.at("./contributor[role/@type = 'distributor']/organization/name") or
|
|
40
|
-
return nil
|
|
41
|
-
x.text
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def series_title(doc)
|
|
45
|
-
doc&.at("./title")&.text || doc&.at("./formattedref")&.text
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def series_abbr(doc)
|
|
49
|
-
doc&.at("./abbreviation")&.text
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def series_num(doc)
|
|
53
|
-
doc&.at("./number")&.text
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
def series_partnumber(doc)
|
|
57
|
-
doc&.at("./partnumber")&.text
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
def series_run(doc)
|
|
61
|
-
doc&.at("./run")&.text
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def standardidentifier(doc)
|
|
65
|
-
doc.xpath("./docidentifier").each_with_object([]) do |id, ret|
|
|
66
|
-
ret << id.text unless %w(metanorma metanorma-ordinal).include? id["type"]
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
def uri(doc)
|
|
71
|
-
uri = doc.at("./uri[@type = 'doi']") || doc.at("./uri[@type = 'uri']") ||
|
|
72
|
-
doc.at("./uri[@type = 'src']") || doc.at("./uri")
|
|
73
|
-
uri&.text
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
def access_location(doc, host)
|
|
77
|
-
x = doc.at("./accessLocation") || host&.at("./accessLocation") or
|
|
78
|
-
return nil
|
|
79
|
-
x.text
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
def included(type)
|
|
83
|
-
["article", "inbook", "incollection", "inproceedings"].include? type
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
def wrap(text, startdelim = " ", enddelim = ".")
|
|
87
|
-
return "" if blank?(text)
|
|
88
|
-
|
|
89
|
-
"#{startdelim}#{text}#{enddelim}"
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
def type(doc)
|
|
93
|
-
type = doc.at("./@type") and return type&.text
|
|
94
|
-
doc.at("./relation[@type = 'includedIn']") and return "inbook"
|
|
95
|
-
"book"
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
def extent1(localities)
|
|
99
|
-
localities.each_with_object({}) do |l, ret|
|
|
100
|
-
ret[(l["type"] || "page").to_sym] = {
|
|
101
|
-
from: l.at("./referenceFrom")&.text,
|
|
102
|
-
to: l.at("./referenceTo")&.text,
|
|
103
|
-
}
|
|
104
|
-
end
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
def extent0(elem, acc, ret1)
|
|
108
|
-
case elem.name
|
|
109
|
-
when "localityStack"
|
|
110
|
-
acc << ret1
|
|
111
|
-
ret1 = {}
|
|
112
|
-
acc << extent1(elem.elements)
|
|
113
|
-
when "locality" then ret1.merge!(extent1([elem]))
|
|
114
|
-
when "referenceFrom" then ret1.merge!(extent1([elem.parent]))
|
|
115
|
-
end
|
|
116
|
-
[acc, ret1]
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
def extent(doc)
|
|
120
|
-
ret1 = {}
|
|
121
|
-
ret = doc.xpath("./extent").each_with_object([]) do |e, acc|
|
|
122
|
-
e.elements.each do |l|
|
|
123
|
-
acc, ret1 = extent0(l, acc, ret1)
|
|
124
|
-
break if l.name == "referenceFrom"
|
|
125
|
-
end
|
|
126
|
-
end
|
|
127
|
-
ret << ret1
|
|
128
|
-
ret.reject(&:empty?)
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
def draft(doc)
|
|
132
|
-
dr = doc&.at("./status/stage")&.text
|
|
133
|
-
|
|
134
|
-
iterord = iter_ordinal(doc)
|
|
135
|
-
status = status_print(dr)
|
|
136
|
-
status = "#{iterord} #{status}" if iterord
|
|
137
|
-
status
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
def iter_ordinal(isoxml)
|
|
141
|
-
return nil unless isoxml.at(("./status/iteration"))
|
|
142
|
-
|
|
143
|
-
iter = isoxml.at(("./status/iteration"))&.text || "1"
|
|
144
|
-
iter.to_i.localize.to_rbnf_s("SpelloutRules",
|
|
145
|
-
"spellout-ordinal").capitalize
|
|
146
|
-
end
|
|
147
|
-
|
|
148
|
-
def status_print(status)
|
|
149
|
-
status
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
def status(doc)
|
|
153
|
-
doc&.at("./status/stage")&.text
|
|
154
|
-
end
|
|
155
|
-
end
|
data/lib/relaton/config.yml
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
nametemplate:
|
|
2
|
-
one: "{{surname[0] | upcase }}, {{given[0]}} {{middle[0}}"
|
|
3
|
-
two: "{{surname[0] | upcase}}, {{given[0]}} {{middle[0]}} {{ labels['and'] }} {{given[1]}} {{middle[1]}} {{surname[1] | upcase}}"
|
|
4
|
-
more: "{{surname[0] | upcase}}, {{given[0]}} {{middle[0}} , {{given[1]}} {{middle[1]}} {{surname[1] | upcase}} {{ labels['and'] }} {{given[2]}} {{middle[2]}} {{surname[2] | upcase}}"
|
|
5
|
-
# disabled the following: they should be provided in inheriting calls
|
|
6
|
-
# etal: "{{surname[0] | upcase}}, {{given[0]}} {{middle[0]}}, {{given[1]}} {{middle[1]}} {{surname[1] | upcase}} <em>et al.</em>"
|
|
7
|
-
# etal_count: 5
|
|
8
|
-
seriestemplate: "{% if series_abbr %}{{series_abbr}}{% else %}{{series_title}}{% endif %} ({{series_run}}) {{series_num}}|({{series_partnumber}})"
|
|
9
|
-
journaltemplate: "<em>{% if series_abbr %}{{series_abbr}}{% else %}{{series_title}}{% endif %}</em> ({{series_run}}) {{ labels['volume'] }}_{{series_num}} {{ labels['part'] }}_{{series_partnumber}}"
|
|
10
|
-
extenttemplate:
|
|
11
|
-
book: "{{ volume }}_{{ labels['extent']['volume'] }}, {{ page }}_{{ labels['extent']['page'] }}"
|
|
12
|
-
booklet: book
|
|
13
|
-
proceedings: book
|
|
14
|
-
journal: book
|
|
15
|
-
standard: book
|
|
16
|
-
techreport: book
|
|
17
|
-
inbook: "{{ volume }}: {{ page }}"
|
|
18
|
-
misc: "{{ labels['extent']['volume'] }}_{{ volume }}, {{ labels['extent']['page'] }}_{{ page }}"
|
|
19
|
-
# TODO: software extent
|
|
20
|
-
language: en
|
|
21
|
-
script: Latn
|
|
22
|
-
template:
|
|
23
|
-
book: "{{ creatornames }} ({{role}}) . <em>{{ title }}</em> [{{medium}}] . {{ edition | capitalize }}. ({{ series }}.) {{place}}: {{publisher}}. {{date}}. {{ labels['updated'] | capitalize }}:_{{date_updated}}. {{ standardidentifier | first }}. {{ uri }}. {{ labels['at'] | capitalize}}:_{{ access_location }}. [{{ labels['viewed'] }}:_{{date_accessed}}]. {{extent}}."
|
|
24
|
-
# TODO: omitted: author ids, subsidiary titles, subsidiary creators, rights metadata, distributor, item attributes, relationships
|
|
25
|
-
booklet: book
|
|
26
|
-
manual: book
|
|
27
|
-
proceedings: book
|
|
28
|
-
inbook: "{{ creatornames }} ({{role}}) . {{ title }} . {{ labels['in'] | capitalize }}: {{ host_creatornames}} ({{ host_role}}) : <em>{{host_title}}</em> [{{medium}}] . {{ edition | capitalize }}. ({{ series }}.) {{place}}: {{publisher}}. {{date}}. {{extent}}. {{ labels['updated'] | capitalize }}:_{{date_updated}}. {{ standardidentifier | first }}. {{ uri }}. {{ labels['at'] | capitalize}}:_{{ access_location }}. [{{ labels['viewed'] }}:_{{date_accessed}}]."
|
|
29
|
-
inproceedings: inbook
|
|
30
|
-
incollection: inbook
|
|
31
|
-
# TODO: omitted: author ids, additional info for component part, subsidiary titles of host resource, rights metadata, distributor, relationships
|
|
32
|
-
journal: "<em>{{ title}}</em> [{{medium}}] . {{ edition | capitalize }}. {{place}}: {{publisher}}. {{date}}. {{extent}}. {{ standardidentifier | first }}. {{ uri }}. {{ labels['at'] | capitalize}}:_{{ access_location }}. [{{ labels['viewed'] }}:_{{date_accessed}}]."
|
|
33
|
-
# TODO subsidiary titles, rights metadata, item attributes, relationships
|
|
34
|
-
article: "{{ creatornames }} ({{role}}) . {{ title }}. {{ series }} [{{medium}}] . {{ edition | capitalize }}. {{ extent }}. {{place}}: {{publisher}}. {{date}}. {{ labels['updated'] | capitalize }}:_{{date_updated}}. {{ standardidentifier | first }}. {{ uri }}. {{ labels['at'] | capitalize}}:_{{ access_location }}. [{{ labels['viewed'] }}:_{{date_accessed}}]."
|
|
35
|
-
# TODO: omitted: author ids, subsidiary titles, rights metadata, distributor, item attributes, relationships; newspapers
|
|
36
|
-
software: "{{ creatornames }} ({{ role}}) . <em>{{ title }}</em> . {{ labels['version'] | capitalize }}_{{ edition_raw }}. {{medium | capitalize}}. {{place}}: {{publisher}}. {{date}}. {{ labels['updated'] | capitalize }}:_{{date_updated}}. {{ standardidentifier | first }}. {{ uri }}. {{ extent}}. [{{ labels['viewed'] }}:_{{date_accessed}}]. "
|
|
37
|
-
# TODO: omitted: author ids, subsidiary titles, subsidiary creators, copyright, license, distributor, system requirements, relationships
|
|
38
|
-
electronic resource: software
|
|
39
|
-
standard: "{{ creatornames }} ({{ role}}) . <em>{{ title }}</em> . {{ labels['in'] | capitalize }}:_{{ series_title }}. {{ medium | capitalize }}. {{ edition | capitalize }}. {{place}}: {{publisher}}. {{date}}. {{ extent }}. {{ standardidentifier | first }}. {{ uri }}. {{ labels['at'] | capitalize}}:_{{ access_location }}. [{{ labels['viewed'] }}:_{{date_accessed}}]."
|
|
40
|
-
# TODO: omitted: author ids, subsidiary titles, rights metadata, distributor, persistent identifier, item attributes, relationships
|
|
41
|
-
techreport: standard
|
|
42
|
-
dataset: "{{ creatornames }} ({{ role }}) . <em>{{ title }}</em> . {{ labels['version'] | capitalize }}_{{ edition_raw }}. {{medium | capitalize }}. {{ labels['in'] | capitalize }}:_{{series}}. {{date}}. {{ labels['updated'] | capitalize }}:_{{date_updated}}. {{ standardidentifier | first }}. {{ uri }}. {{ extent}}. [{{ labels['viewed'] }}:_{{date_accessed}}]. "
|
|
43
|
-
# TODO: omitted: author ids, system requirements, host archive, copyright, license, data source, distributor, usage instructions, relationships, provenance
|
|
44
|
-
website: "{{ creatornames }} ({{ role }}) . <em>{{ title }}</em> . {{ labels['version'] | capitalize }}_{{ edition_raw }}. {{medium | capitalize }}. {{ place }}: {{ publisher }}. {{date}}. {{ labels['updated'] | capitalize }}:_{{date_updated}}. {{ standardidentifier | first }}. {{ uri }}. [{{ labels['viewed'] }}:_{{date_accessed}}]. "
|
|
45
|
-
# TODO: omitted: author ids, page title, system requirements, subsidiary creator, rights metadata, distributor, persistent identifier, archive location, archive date and time, relationships
|
|
46
|
-
webresource: website
|
|
47
|
-
# TODO: component part
|
|
48
|
-
unpublished: "{{ creatornames }} ({{ role }}) . <em>{{ title }}</em> . {{ medium | capitalize }}. {{ date }}. {{ labels['at'] | capitalize}}:_{{ access_location }}. {{ standardidentifier | first }}. {{ uri }}. [{{ labels['viewed'] }}:_{{date_accessed}}]."
|
|
49
|
-
# TODO: omitted: author ids, subsidiary titles, subsidiary creators, host archive, item attributes, relationships
|
|
50
|
-
presentation: unpublished
|
|
51
|
-
thesis: "{{ creatornames }} ({{ role }}) . <em>{{ title }}</em> . {{ medium | capitalize }}. {{ place }}: {{ publisher }}. {{ date }}. {{ labels['at'] | capitalize}}:_{{ access_location }}. {{ standardidentifier | first }}. {{ uri }}. [{{ labels['viewed'] }}:_{{date_accessed}}]."
|
|
52
|
-
# unsupported types:
|
|
53
|
-
# map: ""
|
|
54
|
-
# audiovisual: ""
|
|
55
|
-
# film: ""
|
|
56
|
-
# video: ""
|
|
57
|
-
# broadcast: ""
|
|
58
|
-
# graphic_work: ""
|
|
59
|
-
# music: ""
|
|
60
|
-
# performance: "" (not in Relaton)
|
|
61
|
-
# patent: ""
|
|
62
|
-
# archival: ""
|
|
63
|
-
# social_media: ""
|
|
64
|
-
# alert: ""
|
|
65
|
-
# message: ""
|
|
66
|
-
# conversation: ""
|
|
67
|
-
# misc: ""
|
data/lib/relaton/render.rb
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
require_relative "render_classes"
|
|
2
|
-
require_relative "render_fields"
|
|
3
|
-
require "yaml"
|
|
4
|
-
require "liquid"
|
|
5
|
-
require_relative "../isodoc/i18n"
|
|
6
|
-
require_relative "../utils/utils"
|
|
7
|
-
|
|
8
|
-
module Relaton
|
|
9
|
-
module Render
|
|
10
|
-
class General
|
|
11
|
-
attr_reader :template, :journaltemplate, :seriestemplate, :nametemplate,
|
|
12
|
-
:extenttemplate, :lang, :script, :edition, :edition_number,
|
|
13
|
-
:date
|
|
14
|
-
|
|
15
|
-
def initialize(opt = {})
|
|
16
|
-
options = YAML.load_file(File.join(File.dirname(__FILE__),
|
|
17
|
-
"config.yml"))
|
|
18
|
-
.merge(Utils::string_keys(opt))
|
|
19
|
-
@type = self.class.name.downcase.sub(/relaton::render::/, "")
|
|
20
|
-
root_initalize(options)
|
|
21
|
-
render_initialize(options)
|
|
22
|
-
@parse ||= options["parse"]
|
|
23
|
-
@i18n ||= options["i18n"]
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def root_initalize(opt)
|
|
27
|
-
i18n_initialize(opt)
|
|
28
|
-
@parse = Iso690Parse.new
|
|
29
|
-
@nametemplate = Iso690NameTemplate
|
|
30
|
-
.new(template: opt["nametemplate"], i18n: @i18n)
|
|
31
|
-
@seriestemplate = Iso690SeriesTemplate
|
|
32
|
-
.new(template: opt["seriestemplate"], i18n: @i18n)
|
|
33
|
-
@journaltemplate = Iso690SeriesTemplate
|
|
34
|
-
.new(template: opt["journaltemplate"], i18n: @i18n)
|
|
35
|
-
@extenttemplate = extentrenderers(opt)
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def i18n_initialize(opt)
|
|
39
|
-
@lang = opt["language"]
|
|
40
|
-
@script = opt["script"]
|
|
41
|
-
@i18n = i18n(opt["language"], opt["script"])
|
|
42
|
-
@edition_number = opt["edition_number"] || @i18n.edition_number
|
|
43
|
-
@edition = opt["edition"] || @i18n.edition
|
|
44
|
-
@date = opt["date"] || @i18n.date
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def render_initialize(opt)
|
|
48
|
-
case opt["template"]
|
|
49
|
-
when String
|
|
50
|
-
@template = Iso690Template.new(template: opt["template"],
|
|
51
|
-
i18n: @i18n)
|
|
52
|
-
when Hash
|
|
53
|
-
@render = renderers(opt)
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def renderers(opt)
|
|
58
|
-
template_hash_fill(opt["template"]).each_with_object({}) do |(k, v), m|
|
|
59
|
-
@type == "general" || @type == k or next
|
|
60
|
-
m[k] = General.subclass(k)
|
|
61
|
-
.new(template: v, parse: @parse, i18n: @i18n,
|
|
62
|
-
language: @lang, script: @script)
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
def extentrenderers(opt)
|
|
67
|
-
Iso690ExtentTemplate
|
|
68
|
-
.new(template: template_hash_fill(opt["extenttemplate"]), i18n: @i18n)
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
def default_template
|
|
72
|
-
"{{creatornames}}. {{title}}. {{date}}."
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
def i18n(lang = "en", script = "Latn")
|
|
76
|
-
::IsoDoc::I18n.new(lang, script)
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
def render(bib, embedded: false)
|
|
80
|
-
docxml = Nokogiri::XML(bib)
|
|
81
|
-
docxml.remove_namespaces!
|
|
82
|
-
parse(docxml.root, embedded: embedded)
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
def parse(doc, embedded: false)
|
|
86
|
-
f = doc.at("./formattedref") and
|
|
87
|
-
return embedded ? f.children.to_xml : doc.to_xml
|
|
88
|
-
|
|
89
|
-
ret = parse1(doc)
|
|
90
|
-
embedded and return ret
|
|
91
|
-
"<formattedref>#{ret}</formattedref>"
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
def renderer(doc)
|
|
95
|
-
unless ret = @template || @render[doc["type"]]&.template
|
|
96
|
-
raise "No renderer defined for #{doc['type']}"
|
|
97
|
-
end
|
|
98
|
-
unless @type == "general" || @type == doc["type"]
|
|
99
|
-
raise "No renderer defined for #{doc['type']}"
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
ret
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
def parse1(doc)
|
|
106
|
-
r = renderer(doc)
|
|
107
|
-
data = @parse.extract(doc)
|
|
108
|
-
data_liquid = Fields.new(renderer: self).compound_fields_format(data)
|
|
109
|
-
@i18n.l10n(r.render(data_liquid))
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
private
|
|
113
|
-
|
|
114
|
-
def template_hash_fill(templates)
|
|
115
|
-
BIBTYPE.each_with_object({}) do |type, m|
|
|
116
|
-
template = templates[type] || templates["misc"] || default_template
|
|
117
|
-
BIBTYPE.include?(template) and template = templates[template]
|
|
118
|
-
m[type] = template
|
|
119
|
-
end
|
|
120
|
-
end
|
|
121
|
-
end
|
|
122
|
-
end
|
|
123
|
-
end
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
module Relaton
|
|
2
|
-
module Render
|
|
3
|
-
BIBTYPE =
|
|
4
|
-
%w(article book booklet manual proceedings presentation thesis techreport
|
|
5
|
-
standard unpublished map electronic_resource audiovisual film video
|
|
6
|
-
broadcast software graphic_work music patent inbook incollection
|
|
7
|
-
inproceedings journal website webresource dataset archival social_media
|
|
8
|
-
alert message conversation misc).freeze
|
|
9
|
-
|
|
10
|
-
class General
|
|
11
|
-
singleton_class.send(:attr_reader, :descendants)
|
|
12
|
-
@descendants = {}
|
|
13
|
-
|
|
14
|
-
def self.inherited(subclass) # rubocop:disable Lint/MissingSuper
|
|
15
|
-
type = subclass.name.downcase.sub(/relaton::render::/, "")
|
|
16
|
-
General.descendants[type] = subclass
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def self.subclass(type)
|
|
20
|
-
@descendants[type]
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
class Book < General
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
class Journal < General
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
class Booklet < General
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
class Manual < General
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
class Proceedings < General
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
class Presentation < General
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
class Thesis < General
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
class Techreport < General
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
class Standard < General
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
class Unpublished < General
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
class Map < General
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
class Electronic_resource < General
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
class Software < Electronic_resource
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
class Webresource < Electronic_resource
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
class Website < Webresource
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
class Dataset < Electronic_resource
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
class Social_media < Electronic_resource
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
class Alert < Social_media
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
class Message < Social_media
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
class Audiovisual < General
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
class Film < Audiovisual
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
class Video < Audiovisual
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
class Broadcast < Audiovisual
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
class Graphic_work < General
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
class Music < General
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
class Patent < General
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
class Hosted < General
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
class Article < Hosted
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
class InBook < Hosted
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
class InCollection < Hosted
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
class InProceedings < Hosted
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
class Archival < General
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
class Conversation < General
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
class Misc < General
|
|
124
|
-
end
|
|
125
|
-
end
|
|
126
|
-
end
|