libis-tools 0.9.65 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +5 -23
  3. data/lib/libis/tools.rb +0 -1
  4. data/lib/libis/tools/version.rb +1 -1
  5. data/libis-tools.gemspec +1 -1
  6. metadata +4 -51
  7. data/lib/libis/tools/metadata.rb +0 -25
  8. data/lib/libis/tools/metadata/dublin_core_record.rb +0 -116
  9. data/lib/libis/tools/metadata/field_format.rb +0 -121
  10. data/lib/libis/tools/metadata/fix_field.rb +0 -35
  11. data/lib/libis/tools/metadata/mapper.rb +0 -81
  12. data/lib/libis/tools/metadata/mappers/flandrica.rb +0 -76
  13. data/lib/libis/tools/metadata/mappers/kuleuven.rb +0 -1929
  14. data/lib/libis/tools/metadata/mappers/scope.rb +0 -46
  15. data/lib/libis/tools/metadata/marc21_record.rb +0 -51
  16. data/lib/libis/tools/metadata/marc_record.rb +0 -287
  17. data/lib/libis/tools/metadata/parser/basic_parser.rb +0 -120
  18. data/lib/libis/tools/metadata/parser/dublin_core_parser.rb +0 -37
  19. data/lib/libis/tools/metadata/parser/marc21_parser.rb +0 -207
  20. data/lib/libis/tools/metadata/parser/marc_format_parser.rb +0 -53
  21. data/lib/libis/tools/metadata/parser/marc_rules.rb +0 -36
  22. data/lib/libis/tools/metadata/parser/marc_select_parser.rb +0 -26
  23. data/lib/libis/tools/metadata/parser/patch.rb +0 -22
  24. data/lib/libis/tools/metadata/parser/subfield_criteria_parser.rb +0 -72
  25. data/lib/libis/tools/metadata/parsers.rb +0 -12
  26. data/lib/libis/tools/metadata/sharepoint_mapping.rb +0 -119
  27. data/lib/libis/tools/metadata/sharepoint_record.rb +0 -262
  28. data/lib/libis/tools/metadata/var_field.rb +0 -242
  29. data/spec/data/MetadataMapping.xlsx +0 -0
  30. data/spec/metadata/123456789.marc +0 -18
  31. data/spec/metadata/8389207.marc +0 -117
  32. data/spec/metadata/BE_942855_1927_4898_corrected.XML +0 -11
  33. data/spec/metadata/BE_942855_1927_4898_md.XML +0 -11
  34. data/spec/metadata/dublin_core_parser_spec.rb +0 -48
  35. data/spec/metadata/dublin_core_spec.rb +0 -81
  36. data/spec/metadata/marc21_parser_data.rb +0 -382
  37. data/spec/metadata/marc21_parser_spec.rb +0 -67
  38. data/spec/metadata/marc21_spec.rb +0 -178
  39. data/spec/metadata/metadata_mapper_spec.rb +0 -23
  40. data/spec/metadata/scope_mapper_spec.rb +0 -29
  41. data/test.rb +0 -61
@@ -1,37 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'parslet'
4
-
5
- require_relative 'basic_parser'
6
-
7
- module Libis
8
- module Tools
9
- module Metadata
10
- # noinspection RubyResolve
11
-
12
- # New style parsers and converters for metadata. New, not finished and untested.
13
- class DublinCoreParser < Libis::Tools::Metadata::BasicParser
14
- rule(:namespace) { match('[^:]').repeat(1).as(:namespace) >> str(':') }
15
- rule(:namespace?) { namespace.maybe }
16
-
17
- rule(:attribute) { namespace? >> name_string.as(:name) >> str('=') >> str('"') >> match('[^"]').repeat(1).as(:value) >> str('"') }
18
- rule(:attributes) { attribute >> (spaces >> attribute).repeat }
19
- rule(:attributes?) { attributes.maybe }
20
- rule(:element) { name_string.as(:element) }
21
- rule(:DC) { namespace >> element >> (spaces >> attributes.as(:attributes)).maybe }
22
-
23
- root(:DC)
24
-
25
- def to_target(tree)
26
- tree = tree[:DC]
27
- return nil unless tree
28
- result = "xml['#{tree[:namespace]}'].#{tree[:element]}("
29
- tree[:attributes].each { |attribute| result += "'#{attribute[:name]}' => '#{attribute[:value]}'" }
30
- result + ').text'
31
- end
32
-
33
- end
34
-
35
- end
36
- end
37
- end
@@ -1,207 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'parslet'
4
-
5
- require_relative 'basic_parser'
6
- require_relative 'marc_rules'
7
-
8
- module Libis
9
- module Tools
10
- module Metadata
11
- # noinspection RubyResolve
12
-
13
- # New style parsers and converters for metadata. New, not finished and untested.
14
- class Marc21Parser < Libis::Tools::Metadata::BasicParser
15
-
16
- root(:marc21)
17
- rule(:marc21) { select.as(:select) | format.as(:format) }
18
-
19
- # select syntax
20
- rule(:select) do
21
- str('MARC') >>
22
- spaces? >> tag.as(:tag) >>
23
- spaces? >> indicator.maybe.as(:ind1) >> indicator.maybe.as(:ind2) >>
24
- spaces? >> subfield.maybe.as(:subfield) >>
25
- spaces? >> condition.maybe.as(:condition)
26
- end
27
- rule(:condition) { grouped_anonymous(cond_format.as(:cond_format)) }
28
- rule(:cond_format) { cond_entry.repeat(1).maybe.as(:entry) >> postfix.maybe.as(:postfix) }
29
- rule(:cond_entry) { sf_reference | method_call | cond_group }
30
- rule(:cond_group) { (prefix.maybe.as(:prefix) >> grouped(cond_format)).as(:cond_group) }
31
-
32
- # Formatting syntax
33
- rule(:format) { entry.repeat(1).maybe.as(:entry) >> postfix.maybe.as(:postfix) }
34
-
35
- rule(:entry) { sf_reference | method_call | group }
36
- # noinspection RubyArgCount
37
- rule(:group) { (prefix.maybe.as(:prefix) >> grouped(format)).as(:group) }
38
- # noinspection RubyArgCount
39
- rule(:method_call) { (prefix.maybe.as(:prefix) >> sf_indicator >> grouped_anonymous(format, lrparen)).as(:method_call) }
40
-
41
- # pre- and postfix
42
- rule(:prefix) { other.repeat(1) }
43
- rule(:prefix) { text }
44
- rule(:postfix) { other.repeat(1) }
45
- rule(:postfix) { text }
46
-
47
- # subfield reference
48
- rule(:sf_reference) { sf_variable.as(:subfield) | sf_fixed.as(:fixfield) }
49
-
50
- rule(:sf_variable) { prefix.maybe.as(:prefix) >> sf_indicator >> sf_repeat.maybe.as(:repeat) >> sf_name }
51
- rule(:sf_repeat) { star >> any_quoted(:separator).maybe }
52
-
53
- rule(:sf_fixed) { prefix.maybe.as(:prefix) >> sf_indicator >> lsparen >> (sf_range | sf_position | sf_star) >> rsparen }
54
- rule(:sf_star) { star.as(:all) }
55
- rule(:sf_position) { integer.as(:position) }
56
- rule(:sf_range) { integer.as(:first) >> minus >> integer.as(:last) }
57
-
58
- rule(:other) { paren.absent? >> dollar.absent? >> any | litteral_dollar }
59
-
60
- # tag
61
- rule(:tag) { tag_numeric | tag_alpha }
62
- rule(:tag_numeric) { number.repeat(3, 3) }
63
- rule(:tag_alpha) { character.repeat(3, 3) }
64
-
65
- # indicator
66
- rule(:indicator) { hashtag | underscore | number | character }
67
-
68
- # subfield
69
- rule(:sf_indicator) { dollar }
70
- rule(:sf_name) { (character | number).as(:name) }
71
- rule(:sf_names) { (character | number).repeat(1).as(:names) }
72
- rule(:subfield) { sf_indicator >> sf_name }
73
- rule(:litteral_dollar) { dollar >> dollar }
74
-
75
- # noinspection RubyResolve
76
- class Transformer < Parslet::Transform
77
- rule(name: simple(:name)) { "#{name}" }
78
- # select transformation rules
79
- rule(cond_group: {
80
- prefix: simple(:prefix),
81
- lparen: simple(:lparen),
82
- entry: simple(:entry),
83
- postfix: simple(:postfix),
84
- rparen: simple(:rparen)}) {
85
- "#{prefix}#{lparen}#{entry}#{postfix}#{rparen}"
86
- }
87
- rule(cond_group: {
88
- prefix: simple(:prefix),
89
- lparen: simple(:lparen),
90
- entry: sequence(:entry),
91
- postfix: simple(:postfix),
92
- rparen: simple(:rparen)}) {
93
- "#{prefix}#{lparen}#{entry.join}#{postfix}#{rparen}"
94
- }
95
- rule(cond_format: {
96
- entry: sequence(:entry),
97
- postfix: simple(:postfix)
98
- }) { ", Proc.new { |f| #{entry.join}#{postfix} }" }
99
- rule(select: {
100
- tag: simple(:tag),
101
- ind1: simple(:ind1),
102
- ind2: simple(:ind2),
103
- subfield: simple(:subfield),
104
- condition: simple(:condition)
105
- }) { "record.select_fields('#{tag}#{ind1 || '#'}#{ind2 || '#'}#{subfield}'#{condition || ''})" }
106
- # format transformation rules
107
- rule(format: {
108
- entry: sequence(:entries),
109
- postfix: simple(:postfix)
110
- }) do
111
- if entries.size == 1 && postfix.nil?
112
- entries.first
113
- else
114
- "field_format(#{entries.join(',')}#{", postfix: '#{postfix}'" if postfix}).to_s"
115
- end
116
- end
117
- rule(group: {
118
- prefix: simple(:prefix),
119
- lparen: simple(:lparen),
120
- entry: nil,
121
- postfix: simple(:postfix),
122
- rparen: simple(:rparen)}) {
123
- "#{prefix}#{lparen}#{postfix}#{rparen}"
124
- }
125
- rule(group: {
126
- prefix: simple(:prefix),
127
- lparen: simple(:lparen),
128
- entry: '',
129
- postfix: simple(:postfix),
130
- rparen: simple(:rparen)}) {
131
- "#{prefix}#{lparen}#{postfix}#{rparen}"
132
- }
133
- rule(group: {
134
- prefix: simple(:prefix),
135
- lparen: simple(:lparen),
136
- entry: simple(:entry),
137
- postfix: simple(:postfix),
138
- rparen: simple(:rparen)}) {
139
- "field_format(#{entry}#{", prefix: '#{prefix}#{lparen}'" if prefix || lparen}#{", postfix: '#{postfix}#{rparen}'" if postfix || rparen}).to_s"
140
- }
141
- rule(group: {
142
- prefix: simple(:prefix),
143
- lparen: simple(:lparen),
144
- entry: sequence(:entries),
145
- postfix: simple(:postfix),
146
- rparen: simple(:rparen)}) {
147
- "field_format(#{entries.join(',')}#{", prefix: '#{prefix}#{lparen}'" if prefix || lparen}#{", postfix: '#{postfix}#{rparen}'" if postfix || rparen}).to_s"
148
- }
149
- rule(fixfield: {
150
- prefix: nil,
151
- all: '*'
152
- }) { 'f[]' }
153
- rule(fixfield: {
154
- prefix: simple(:prefix),
155
- all: '*'
156
- }) { "field_format(f[], prefix: '#{prefix}').to_s" }
157
- rule(fixfield: {
158
- prefix: nil,
159
- position: simple(:position)
160
- }) { "f[#{position}]" }
161
- rule(fixfield: {
162
- prefix: simple(:prefix),
163
- position: simple(:position)
164
- }) do
165
- if prefix
166
- "field_format(f[#{position}], prefix: '#{prefix}').to_s"
167
- else
168
- "f[#{position}]"
169
- end
170
- end
171
- rule(fixfield: {
172
- prefix: nil,
173
- first: simple(:from),
174
- last: simple(:to)
175
- }) { "f[#{from},#{to}]" }
176
- rule(fixfield: {
177
- prefix: simple(:prefix),
178
- first: simple(:from),
179
- last: simple(:to)
180
- }) { "field_format(f[#{from},#{to}], prefix: '#{prefix}').to_s" }
181
- rule(subfield: {
182
- prefix: simple(:prefix),
183
- repeat: nil,
184
- name: simple(:name),
185
- }) { "field_format(f.subfield('#{name}'), prefix: '#{prefix}').to_s" }
186
- rule(subfield: {
187
- prefix: simple(:prefix),
188
- repeat: {separator: simple(:separator)},
189
- name: simple(:name),
190
- }) { "field_format(f.subfield_array('#{name}')#{", prefix: '#{prefix}'" if prefix}, join: '#{separator}').to_s" }
191
- rule(subfield: {
192
- prefix: simple(:prefix),
193
- repeat: '*',
194
- name: simple(:name),
195
- }) { "field_format(f.subfield_array('#{name}')#{", prefix: '#{prefix}'" if prefix}, join: ';').to_s" }
196
- rule(subfield: {
197
- prefix: nil,
198
- repeat: nil,
199
- name: simple(:name),
200
- }) { "f.subfield('#{name}')" }
201
- end
202
-
203
- end
204
-
205
- end
206
- end
207
- end
@@ -1,53 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'parslet'
4
-
5
- require_relative 'basic_parser'
6
- require_relative 'marc_rules'
7
-
8
- module Libis
9
- module Tools
10
- module Metadata
11
- # noinspection RubyResolve
12
-
13
- # New style parsers and converters for metadata. New, not finished and untested.
14
- class MarcFormatParser < Libis::Tools::Metadata::BasicParser
15
- include Libis::Tools::Metadata::MarcRules
16
-
17
- root(:mapping)
18
-
19
- rule(:mapping) { entry.repeat(1).as(:entry) >> postfix?.as(:postfix) }
20
-
21
- rule(:entry) { group.as(:group) | sf_reference }
22
- rule(:group) { prefix?.as(:prefix) >> grouped(mapping) }
23
-
24
- # pre- and postfix
25
- rule(:prefix) { other.repeat(1) }
26
- rule(:prefix) { text }
27
- rule(:prefix?) { prefix.maybe }
28
- rule(:postfix) { other.repeat(1) }
29
- rule(:postfix) { text }
30
- rule(:postfix?) { postfix.maybe }
31
-
32
- # subfield reference
33
- rule(:sf_reference) { sf_variable.as(:subfield) | sf_fixed.as(:fixfield) }
34
-
35
- rule(:sf_variable) { prefix?.as(:prefix) >> sf_indicator >> sf_repeat?.as(:repeat) >> sf_name }
36
- rule(:sf_repeat) { star >>
37
- (dquote >> not_dquote.repeat.as(:separator) >> dquote |
38
- squote >> not_squote.repeat.as(:separator) >> squote
39
- ).maybe
40
- }
41
- rule(:sf_repeat?) { sf_repeat.maybe }
42
-
43
- rule(:sf_fixed) { prefix?.as(:prefix) >> sf_indicator >> str('@') >> (sf_position | sf_range | sf_star) }
44
- rule(:sf_position) { lsparen >> integer.as(:position) >> rsparen }
45
- rule(:sf_range) { lsparen >> integer.as(:first) >> minus >> integer.as(:last) >> rsparen }
46
- rule(:sf_star) { star.as(:all) }
47
-
48
- rule(:other) { paren.absent? >> dollar.absent? >> any | str('$$') }
49
- end
50
-
51
- end
52
- end
53
- end
@@ -1,36 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'parslet'
4
-
5
- module Libis
6
- module Tools
7
- module Metadata
8
- # noinspection RubyResolve
9
-
10
- # New style parsers and converters for metadata. New, not finished and untested.
11
- module MarcRules
12
- include Parslet
13
-
14
- # tag
15
- rule(:tag) { tag_numeric | tag_alpha }
16
- rule(:tag_numeric) { number.repeat(3, 3) }
17
- rule(:tag_alpha) { character.repeat(3, 3) }
18
-
19
- # indicator
20
- rule(:indicator) { hashtag | underscore | number | character }
21
- rule(:indicator?) { indicator.maybe }
22
- rule(:indicators) { indicator?.as(:ind1) >> indicator?.as(:ind2) }
23
-
24
- # subfield
25
- rule(:sf_indicator) { dollar }
26
- rule(:sf_name) { (character | number).as(:name) }
27
- rule(:sf_name?) { sf_name.maybe }
28
- rule(:sf_names) { (character | number).repeat(1).as(:names) }
29
- rule(:sf_names?) { sf_names.maybe }
30
- rule(:subfield) { sf_indicator >> sf_name }
31
-
32
- end
33
-
34
- end
35
- end
36
- end
@@ -1,26 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'parslet'
4
-
5
- require_relative 'basic_parser'
6
- require_relative 'marc_rules'
7
-
8
- module Libis
9
- module Tools
10
- module Metadata
11
- # noinspection RubyResolve
12
-
13
- # New style parsers and converters for metadata. New, not finished and untested.
14
- class MarcSelectParser < Libis::Tools::Metadata::BasicParser
15
- include Libis::Tools::Metadata::MarcRules
16
- root(:MARC)
17
- rule(:MARC) { str('MARC') >> spaces? >> tag.as(:tag) >> spaces? >> indicators >> spaces? >> subfield.maybe.as(:subfield) }
18
-
19
- # subfield
20
- # rule(:sf_condition) { sf_indicator >> sf_names >> (space >> sf_names).repeat }
21
- # rule(:sf_names) { sf_name.repeat(1) }
22
- end
23
-
24
- end
25
- end
26
- end
@@ -1,22 +0,0 @@
1
- # New style parsers and converters for metadata. New, not finished and untested.
2
- class Parslet::Pattern
3
-
4
- def element_match_hash(tree, exp, bindings)
5
- return false if exp.size < tree.size
6
- exp.each do |expected_key, expected_value|
7
- if expected_key.to_s =~ /^(.*)\?$/
8
- expected_key = expected_key.is_a?(Symbol) ? $1.to_sym : $1
9
- return true unless tree.has_key? expected_key
10
- end
11
-
12
- return false unless tree.has_key? expected_key
13
-
14
- # Recurse into the value and stop early on failure
15
- value = tree[expected_key]
16
- return false unless element_match(value, expected_value, bindings)
17
- end
18
-
19
- true
20
- end
21
-
22
- end
@@ -1,72 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'parslet'
4
-
5
- require_relative 'basic_parser'
6
-
7
- module Libis
8
- module Tools
9
- module Metadata
10
- # noinspection RubyResolve
11
-
12
- # New style parsers and converters for metadata. New, not finished and untested.
13
- class SubfieldCriteriaParser < Libis::Tools::Metadata::BasicParser
14
-
15
- root(:criteria)
16
-
17
- rule(:criteria) { selection >> (spaces >> selection).repeat }
18
-
19
- rule(:selection) { must >> must_not.maybe }
20
-
21
- rule(:must) { names.as(:must).maybe >> (one_of | only_one_of).maybe }
22
- rule(:must_not) { minus >> must.as(:not) }
23
-
24
- rule(:one_of) { lrparen >> names.as(:one_of) >> rrparen }
25
- rule(:only_one_of) { lcparen >> names.as(:only_one_of) >> rcparen }
26
-
27
- rule(:names) { (character | number).repeat(1) }
28
-
29
- def criteria_to_s(criteria)
30
- case criteria
31
- when Array
32
- # leave as is
33
- when Hash
34
- criteria = [criteria]
35
- else
36
- return criteria
37
- end
38
- criteria.map { |selection| selection_to_s(selection) }.join(' ')
39
- end
40
-
41
- def selection_to_s(selection)
42
- return selection unless selection.is_a? Hash
43
- result = "#{selection[:must]}"
44
- result += "(#{selection[:one_of]})" if selection[:one_of]
45
- result += "{#{selection[:only_one_of]}}" if selection[:only_one_of]
46
- result += "-#{selection_to_s(selection[:not])}" if selection[:not]
47
- result
48
- end
49
-
50
- def match_criteria(criteria, data)
51
- tree = self.new.parse(criteria)
52
- return true if tree.is_a? String
53
- tree = [tree] unless tree.is_a? Array
54
- tree.map { |selection| match_selection(selection, data) }.any?
55
- end
56
-
57
- def match_selection(selection, data)
58
- must_match = selection[:must].to_s.split('')
59
- return false unless must_match == (must_match & data)
60
- one_of = selection[:one_of].to_s.split('')
61
- return false unless one_of.empty? || (one_of & data).any?
62
- only_one_of = selection[:only_one_of].to_s.split('')
63
- return false unless only_one_of.empty? || (only_one_of & data).size != 1
64
- return false if match_selection(selection[:not], data) if selection[:not]
65
- true
66
- end
67
-
68
- end
69
-
70
- end
71
- end
72
- end