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.
- checksums.yaml +4 -4
- data/README.md +5 -23
- data/lib/libis/tools.rb +0 -1
- data/lib/libis/tools/version.rb +1 -1
- data/libis-tools.gemspec +1 -1
- metadata +4 -51
- data/lib/libis/tools/metadata.rb +0 -25
- data/lib/libis/tools/metadata/dublin_core_record.rb +0 -116
- data/lib/libis/tools/metadata/field_format.rb +0 -121
- data/lib/libis/tools/metadata/fix_field.rb +0 -35
- data/lib/libis/tools/metadata/mapper.rb +0 -81
- data/lib/libis/tools/metadata/mappers/flandrica.rb +0 -76
- data/lib/libis/tools/metadata/mappers/kuleuven.rb +0 -1929
- data/lib/libis/tools/metadata/mappers/scope.rb +0 -46
- data/lib/libis/tools/metadata/marc21_record.rb +0 -51
- data/lib/libis/tools/metadata/marc_record.rb +0 -287
- data/lib/libis/tools/metadata/parser/basic_parser.rb +0 -120
- data/lib/libis/tools/metadata/parser/dublin_core_parser.rb +0 -37
- data/lib/libis/tools/metadata/parser/marc21_parser.rb +0 -207
- data/lib/libis/tools/metadata/parser/marc_format_parser.rb +0 -53
- data/lib/libis/tools/metadata/parser/marc_rules.rb +0 -36
- data/lib/libis/tools/metadata/parser/marc_select_parser.rb +0 -26
- data/lib/libis/tools/metadata/parser/patch.rb +0 -22
- data/lib/libis/tools/metadata/parser/subfield_criteria_parser.rb +0 -72
- data/lib/libis/tools/metadata/parsers.rb +0 -12
- data/lib/libis/tools/metadata/sharepoint_mapping.rb +0 -119
- data/lib/libis/tools/metadata/sharepoint_record.rb +0 -262
- data/lib/libis/tools/metadata/var_field.rb +0 -242
- data/spec/data/MetadataMapping.xlsx +0 -0
- data/spec/metadata/123456789.marc +0 -18
- data/spec/metadata/8389207.marc +0 -117
- data/spec/metadata/BE_942855_1927_4898_corrected.XML +0 -11
- data/spec/metadata/BE_942855_1927_4898_md.XML +0 -11
- data/spec/metadata/dublin_core_parser_spec.rb +0 -48
- data/spec/metadata/dublin_core_spec.rb +0 -81
- data/spec/metadata/marc21_parser_data.rb +0 -382
- data/spec/metadata/marc21_parser_spec.rb +0 -67
- data/spec/metadata/marc21_spec.rb +0 -178
- data/spec/metadata/metadata_mapper_spec.rb +0 -23
- data/spec/metadata/scope_mapper_spec.rb +0 -29
- data/test.rb +0 -61
@@ -1,67 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require_relative '../spec_helper'
|
3
|
-
require 'libis/tools/metadata/parser/marc21_parser'
|
4
|
-
require 'parslet/convenience'
|
5
|
-
require 'pp'
|
6
|
-
|
7
|
-
require_relative 'marc21_parser_data'
|
8
|
-
|
9
|
-
describe 'MARC 21 parser' do
|
10
|
-
subject(:parser) { Libis::Tools::Metadata::Marc21Parser.new }
|
11
|
-
|
12
|
-
context 'Syntax parser' do
|
13
|
-
|
14
|
-
marc21_parser_testdata.each do |expectation|
|
15
|
-
|
16
|
-
next unless expectation.has_key?(:tree)
|
17
|
-
|
18
|
-
if expectation[:tree] != :failure
|
19
|
-
it "parses #{expectation[:title]}" do
|
20
|
-
expect {
|
21
|
-
# noinspection RubyArgCount,RubyUnusedLocalVariable
|
22
|
-
tree = parser.select.parse(expectation[:input]) if expectation[:title] =~ /^select /
|
23
|
-
# noinspection RubyArgCount,RubyUnusedLocalVariable
|
24
|
-
tree = parser.format.parse(expectation[:input]) if expectation[:title] =~ /^format /
|
25
|
-
# pp tree
|
26
|
-
expect(tree).to be_a Hash
|
27
|
-
expect(tree).to match expectation[:tree]
|
28
|
-
}.to_not raise_error
|
29
|
-
end
|
30
|
-
else
|
31
|
-
it "does not parse #{expectation[:title]}" do
|
32
|
-
expect {
|
33
|
-
# noinspection RubyArgCount,RubyUnusedLocalVariable
|
34
|
-
tree = parser.select.parse(expectation[:input]) if expectation[:title] =~ /^select /
|
35
|
-
# noinspection RubyArgCount,RubyUnusedLocalVariable
|
36
|
-
tree = parser.format.parse(expectation[:input]) if expectation[:title] =~ /^format /
|
37
|
-
# pp tree
|
38
|
-
}.to raise_error(Parslet::ParseFailed)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
context 'Transformer' do
|
46
|
-
|
47
|
-
let(:transformer) { parser.transformer }
|
48
|
-
|
49
|
-
it 'can be created' do
|
50
|
-
expect(transformer).to be_a Libis::Tools::Metadata::Marc21Parser::Transformer
|
51
|
-
end
|
52
|
-
|
53
|
-
marc21_parser_testdata.each do |expectation|
|
54
|
-
|
55
|
-
next unless expectation.has_key?(:transform)
|
56
|
-
|
57
|
-
it "transforms #{expectation[:title]}" do
|
58
|
-
tree = parser.parse(expectation[:input])
|
59
|
-
# pp tree
|
60
|
-
expect(transformer.apply(tree)).to eq expectation[:transform]
|
61
|
-
end
|
62
|
-
|
63
|
-
end
|
64
|
-
|
65
|
-
end
|
66
|
-
|
67
|
-
end
|
@@ -1,178 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require_relative '../spec_helper'
|
3
|
-
require 'libis/tools/metadata/marc21_record'
|
4
|
-
require 'libis/tools/xml_document'
|
5
|
-
|
6
|
-
require 'rspec/matchers'
|
7
|
-
require 'equivalent-xml'
|
8
|
-
require 'libis/tools/extend/string'
|
9
|
-
|
10
|
-
describe 'Marc21Record' do
|
11
|
-
|
12
|
-
subject(:record) { Libis::Tools::Metadata::Marc21Record.new(data) {} }
|
13
|
-
let(:data) { xml.root }
|
14
|
-
|
15
|
-
context '8389207' do
|
16
|
-
let(:xml) { Libis::Tools::XmlDocument.open(File.join(File.dirname(__FILE__), '8389207.marc')) }
|
17
|
-
|
18
|
-
it 'load from xml' do
|
19
|
-
expect(record.marc_dump).to eq <<-STR.align_left
|
20
|
-
LDR:'01068nam 2200241u 4500'
|
21
|
-
005:'20150701153710.0'
|
22
|
-
008:'000608m17221724xx |||| | 000|0 lat c'
|
23
|
-
001:'9921543960101471'
|
24
|
-
035: : :
|
25
|
-
\ta:["(BeLVLBS)002154396LBS01-Aleph"]
|
26
|
-
035: : :
|
27
|
-
\ta:["8389207"]
|
28
|
-
245:0:0:
|
29
|
-
\ta:["Anecdota Graeca, sacra et profana /"]
|
30
|
-
\tc:["ex codicibus manu exaratis nunc primum in lucem edita, versione Latina donata, et notis\\n illustrata a Io. Christophoro Wolfio ... Tom. I [-IIII]\\n "]
|
31
|
-
264: :1:
|
32
|
-
\ta:["Hamburgi"]
|
33
|
-
\tb:["apud Theodorum Christophorum Felginer,"]
|
34
|
-
\tc:["1722-1724"]
|
35
|
-
300: : :
|
36
|
-
\ta:["8o: 4 v.; [22], 298, [8]; [16], 354, [1]; [16], 299, [7]; [16], 271, [5] p."]
|
37
|
-
336: : :
|
38
|
-
\ta:["text"]
|
39
|
-
\t2:["rdacontent"]
|
40
|
-
337: : :
|
41
|
-
\ta:["unmediated"]
|
42
|
-
\t2:["rdamedia"]
|
43
|
-
338: : :
|
44
|
-
\ta:["volume"]
|
45
|
-
\t2:["rdacarrier"]
|
46
|
-
500: : :
|
47
|
-
\ta:["Ded. Petrus Theodorus Seelmann; Erdmannus Neumeister; Thomas Claussen; Joannes Grammius\\n "]
|
48
|
-
500: : :
|
49
|
-
\ta:["Elk deel heeft eigen titelp. in roodzwartdruk, met drukkersmerk"]
|
50
|
-
650: :7:
|
51
|
-
\t2:["UDC"]
|
52
|
-
\ta:["276 =75"]
|
53
|
-
\tx:["Griekse patrologie"]
|
54
|
-
650: :7:
|
55
|
-
\t2:["KADOC"]
|
56
|
-
\ta:["Bisdom Antwerpen (1961-heden)"]
|
57
|
-
\t6:["(ODIS-ORG)9284"]
|
58
|
-
650: :7:
|
59
|
-
\t2:["KADOC"]
|
60
|
-
\ta:["Studiecentrum voor Zielzorg en Predicatie"]
|
61
|
-
\t6:["(ODIS-ORG)24894"]
|
62
|
-
650: :7:
|
63
|
-
\t2:["KADOC"]
|
64
|
-
\ta:["Antwerpen [deelgemeente in gemeente Antwerpen - BE]"]
|
65
|
-
\t6:["(ODIS-GEO)10560000006504"]
|
66
|
-
650: :7:
|
67
|
-
\t2:["KADOC"]
|
68
|
-
\ta:["C1"]
|
69
|
-
\tx:["Kerken en religie"]
|
70
|
-
\t6:["(ODIS-HT)"]
|
71
|
-
653: :6:
|
72
|
-
\ta:["Books before 1840"]
|
73
|
-
700:1: :
|
74
|
-
\ta:["Wolf, Johann Christoph"]
|
75
|
-
\td:["1683-1739"]
|
76
|
-
\t4:["aut"]
|
77
|
-
953: : :
|
78
|
-
\ta:["1701-1750"]
|
79
|
-
998: : :
|
80
|
-
\ta:["LBS01"]
|
81
|
-
\tb:["bib_200501.mrc.2.av"]
|
82
|
-
INST: : :
|
83
|
-
\ta:["32KUL_LIBIS_NETWORK"]
|
84
|
-
\tb:["P"]
|
85
|
-
\tc:["71134440820001471"]
|
86
|
-
INST: : :
|
87
|
-
\ta:["32KUL_KUL"]
|
88
|
-
\tb:["P"]
|
89
|
-
\tc:["21304345390001488"]
|
90
|
-
AVA: : :
|
91
|
-
\ta:["32KUL_KUL"]
|
92
|
-
\tb:["GBIB"]
|
93
|
-
\tc:["GBIB: Godgeleerdheid"]
|
94
|
-
\td:["276.030.4 WOLF Anec"]
|
95
|
-
\te:["available"]
|
96
|
-
\tf:["1"]
|
97
|
-
\tg:["0"]
|
98
|
-
\tj:["GBIB"]
|
99
|
-
\tp:["1"]
|
100
|
-
MMS: : :
|
101
|
-
\tb:["9921543960101471"]
|
102
|
-
\ta:["32KUL_LIBIS_NETWORK"]
|
103
|
-
MMS: : :
|
104
|
-
\tb:["9921543960101488"]
|
105
|
-
\ta:["32KUL_KUL"]
|
106
|
-
STR
|
107
|
-
end
|
108
|
-
|
109
|
-
it 'convert to dublin core' do
|
110
|
-
record.extend Libis::Tools::Metadata::Mappers::Kuleuven
|
111
|
-
xml_doc = Libis::Tools::XmlDocument.parse <<STR
|
112
|
-
<?xml version="1.0" encoding="utf-8"?>
|
113
|
-
<dc:record xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/">
|
114
|
-
<dc:identifier>urn:ControlNumber:9921543960101471</dc:identifier>
|
115
|
-
<dc:identifier>(BeLVLBS)002154396LBS01-Aleph</dc:identifier>
|
116
|
-
<dc:identifier>8389207</dc:identifier>
|
117
|
-
<dc:title>Anecdota Graeca, sacra et profana /</dc:title>
|
118
|
-
<dc:creator>Wolf, Johann Christoph, 1683-1739, (author)</dc:creator>
|
119
|
-
<dc:subject xsi:type="http://purl.org/dc/terms/UDC">276 =75 Griekse patrologie</dc:subject>
|
120
|
-
<dc:subject xsi:type="dcterms:URI">http://www.odis.be/lnk/or_9284#Bisdom+Antwerpen+%281961-heden%29</dc:subject>
|
121
|
-
<dc:subject xsi:type="dcterms:URI">http://www.odis.be/lnk/or_24894#Studiecentrum+voor+Zielzorg+en+Predicatie</dc:subject>
|
122
|
-
<dc:temporal>1701-1750</dc:temporal>
|
123
|
-
<dc:description>Ded. Petrus Theodorus Seelmann; Erdmannus Neumeister; Thomas Claussen; Joannes Grammius\n \nElk deel heeft eigen titelp. in roodzwartdruk, met drukkersmerk</dc:description>
|
124
|
-
<dc:date>1722 - 1724</dc:date>
|
125
|
-
<dc:type xml:lang="en">Books before 1840</dc:type>
|
126
|
-
<dcterms:extent>8o: 4 v.; [22], 298, [8]; [16], 354, [1]; [16], 299, [7]; [16], 271, [5] p.</dcterms:extent>
|
127
|
-
<dc:language>la</dc:language>
|
128
|
-
<dc:coverage>Antwerpen [deelgemeente in gemeente Antwerpen - BE] [(ODIS-GEO)10560000006504]</dc:coverage>
|
129
|
-
</dc:record>
|
130
|
-
STR
|
131
|
-
record.to_dc.root.elements.each_with_index do |element, i|
|
132
|
-
expect(element).to be_equivalent_to(xml_doc.root.elements[i])
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
context '123456789' do
|
138
|
-
let(:xml) { Libis::Tools::XmlDocument.open(File.join(File.dirname(__FILE__), '123456789.marc')) }
|
139
|
-
|
140
|
-
it 'load from xml' do
|
141
|
-
# puts record.marc_dump
|
142
|
-
expect(record.marc_dump).to eq <<-STR.align_left
|
143
|
-
LDR:'01068nam 2200241u 4500'
|
144
|
-
005:'20150701153710.0'
|
145
|
-
008:'000608m17221724xx |||| | 000|0 lat c'
|
146
|
-
001:'9901234567890471'
|
147
|
-
035: : :
|
148
|
-
\ta:["(BeLVLBS)123456789LBS01-Aleph"]
|
149
|
-
035: : :
|
150
|
-
\ta:["123456789"]
|
151
|
-
245:0:0:
|
152
|
-
\ta:["Title with special chars: 'éÄçñåúðäíö' / \\\"ߥ²¤€®©œøæ’×½¼þ«»¶ǽµ¢ŒÆØŒ§Ð\\\" < & % $ # >"]
|
153
|
-
\tc:["subtitle with special chars: \\\"ߥ²¤€®©œøæ’×½¼þ«»¶ǽµ¢ŒÆØŒ§Ð\\\" < & % $ # >"]
|
154
|
-
STR
|
155
|
-
end
|
156
|
-
|
157
|
-
it 'convert to dublin core' do
|
158
|
-
record.extend Libis::Tools::Metadata::Mappers::Kuleuven
|
159
|
-
xml_doc = Libis::Tools::XmlDocument.parse <<STR
|
160
|
-
<?xml version="1.0" encoding="utf-8"?>
|
161
|
-
<dc:record xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/">
|
162
|
-
<dc:identifier>urn:ControlNumber:9901234567890471</dc:identifier>
|
163
|
-
<dc:identifier>(BeLVLBS)123456789LBS01-Aleph</dc:identifier>
|
164
|
-
<dc:identifier>123456789</dc:identifier>
|
165
|
-
<dc:title>Title with special chars: 'éÄçñåúðäíö' / "ߥ²¤€®©œøæ’×½¼þ«»¶ǽµ¢ŒÆØŒ§Ð" < & % $ # ></dc:title>
|
166
|
-
<dc:date>1722 - 1724</dc:date>
|
167
|
-
<dc:language>la</dc:language>
|
168
|
-
</dc:record>
|
169
|
-
STR
|
170
|
-
# puts puts record.to_dc.to_xml
|
171
|
-
record.to_dc.root.elements.each_with_index do |element, i|
|
172
|
-
expect(element).to be_equivalent_to(xml_doc.root.elements[i])
|
173
|
-
end
|
174
|
-
end
|
175
|
-
end
|
176
|
-
|
177
|
-
end
|
178
|
-
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require_relative '../spec_helper'
|
3
|
-
require 'libis/tools/metadata/mapper'
|
4
|
-
require 'libis/tools/metadata/parsers'
|
5
|
-
require 'parslet'
|
6
|
-
require 'parslet/convenience'
|
7
|
-
require 'pp'
|
8
|
-
|
9
|
-
$DEBUG = false
|
10
|
-
|
11
|
-
describe 'Metadata Mapper' do
|
12
|
-
|
13
|
-
subject(:mapper) { Libis::Tools::Metadata::Mapper.new(
|
14
|
-
Libis::Tools::Metadata::Marc21Parser.new,
|
15
|
-
Libis::Tools::Metadata::DublinCoreParser.new,
|
16
|
-
Libis::Tools::Metadata::Marc21Parser.new,
|
17
|
-
File.join(File.dirname(__FILE__), '..', 'data', 'MetadataMapping.xlsx')) }
|
18
|
-
|
19
|
-
it 'Initialization' do
|
20
|
-
expect(mapper).to_not be_nil
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require_relative '../spec_helper'
|
2
|
-
require 'libis/tools'
|
3
|
-
|
4
|
-
require 'rspec/matchers'
|
5
|
-
require 'equivalent-xml'
|
6
|
-
|
7
|
-
describe 'ScopeMapper' do
|
8
|
-
|
9
|
-
let(:input) { File.join(File.dirname(__FILE__), 'BE_942855_1927_4898_md.XML')}
|
10
|
-
let(:output) { File.join(File.dirname(__FILE__), 'BE_942855_1927_4898_corrected.XML')}
|
11
|
-
|
12
|
-
it 'Correct Scope output' do
|
13
|
-
|
14
|
-
input_dc = Libis::Tools::Metadata::DublinCoreRecord.new(input)
|
15
|
-
expect(input_dc).to be_a Libis::Tools::Metadata::DublinCoreRecord
|
16
|
-
|
17
|
-
output_dc = Libis::Tools::Metadata::DublinCoreRecord.new(output)
|
18
|
-
expect(output_dc).to be_a Libis::Tools::Metadata::DublinCoreRecord
|
19
|
-
|
20
|
-
input_dc.extend Libis::Tools::Metadata::Mappers::Scope
|
21
|
-
converted_dc = input_dc.to_dc
|
22
|
-
expect(converted_dc).to be_a Libis::Tools::Metadata::DublinCoreRecord
|
23
|
-
|
24
|
-
converted_dc.root.elements.each_with_index do |element, i|
|
25
|
-
expect(element).to be_equivalent_to(output_dc.root.elements[i])
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
end
|
data/test.rb
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
require 'libis-tools'
|
2
|
-
require 'parslet'
|
3
|
-
require 'parslet/convenience'
|
4
|
-
|
5
|
-
# noinspection RubyResolve
|
6
|
-
class FieldSpecParser < Libis::Tools::Metadata::BasicParser
|
7
|
-
|
8
|
-
root(:criteria)
|
9
|
-
|
10
|
-
rule(:criteria) { selection >> ( spaces >> selection ).repeat }
|
11
|
-
|
12
|
-
rule(:selection) { must >> must_not.maybe }
|
13
|
-
|
14
|
-
rule(:must) { names.as(:must).maybe >> (one_of | only_one_of).maybe }
|
15
|
-
rule(:must_not) { minus >> must.as(:not) }
|
16
|
-
|
17
|
-
rule(:one_of) { lrparen >> names.as(:one_of) >> rrparen }
|
18
|
-
rule(:only_one_of) { lcparen >> names.as(:only_one_of) >> rcparen }
|
19
|
-
|
20
|
-
rule(:names) { (character | number).repeat(1) }
|
21
|
-
|
22
|
-
def self.criteria_to_s(criteria)
|
23
|
-
case criteria
|
24
|
-
when Array
|
25
|
-
# leave as is
|
26
|
-
when Hash
|
27
|
-
criteria = [criteria]
|
28
|
-
else
|
29
|
-
return criteria
|
30
|
-
end
|
31
|
-
criteria.map { |selection| selection_to_s(selection) }.join(' ')
|
32
|
-
end
|
33
|
-
|
34
|
-
def self.selection_to_s(selection)
|
35
|
-
return selection unless selection.is_a? Hash
|
36
|
-
result = "#{selection[:must]}"
|
37
|
-
result += "(#{selection[:one_of]})" if selection[:one_of]
|
38
|
-
result += "{#{selection[:only_one_of]}}" if selection[:only_one_of]
|
39
|
-
result += "-#{selection_to_s(selection[:not])}" if selection[:not]
|
40
|
-
result
|
41
|
-
end
|
42
|
-
|
43
|
-
end
|
44
|
-
|
45
|
-
require 'awesome_print'
|
46
|
-
|
47
|
-
def parse(string)
|
48
|
-
tree = FieldSpecParser.new.parse_with_debug(string)
|
49
|
-
puts "parse '#{FieldSpecParser.criteria_to_s(tree)}'"
|
50
|
-
ap tree
|
51
|
-
end
|
52
|
-
|
53
|
-
parse ''
|
54
|
-
parse 'abc'
|
55
|
-
parse 'abc-de'
|
56
|
-
parse 'abc(de)'
|
57
|
-
parse 'abc{de}'
|
58
|
-
parse 'a(bc)-de'
|
59
|
-
parse 'a-b c-d'
|
60
|
-
parse 'a-(bc)'
|
61
|
-
parse 'a-{bc}'
|