-
Notifications
You must be signed in to change notification settings - Fork 0
/
dao-role-extractor-multi.rb
executable file
·70 lines (56 loc) · 1.73 KB
/
dao-role-extractor-multi.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env ruby
# For each dao element in an XML file, this script outputs the set of
# role attribute values across all daos.
# e.g.,
# <dao xlink:actuate="onLoad"
# xlink:href="https://aeon.library.nyu.edu/Logon?Action=10&Form=31&Value=http://dlib.nyu.edu/findingaids/ead/fales/mss_601.xml&view=xml"
# xlink:role="electronic-records-service"
# xlink:show="new"
# xlink:title="General Information on VoCA Talks Series"
# xlink:type="simple"
#>
require 'set'
require_relative '../lib/nyudl/ead'
if ARGV.length != 1
$stderr.puts "ERROR: incorrect argument count"
$stderr.puts "usage: #{$0} <path to file containing paths of EADs to include in analysis>"
$stderr.puts " e.g.: #{$0} file-list.txt"
exit 1
end
paths_file = ARGV.shift
unless File.file?(paths_file)
$stderr.puts "ERROR: file '#{paths_file}' does not exist"
exit 1
end
grand_master_set = Set.new()
global_status = 0
global_errors = []
File.foreach(paths_file) do | file |
file.chomp!
unless File.file?(file)
$stderr.puts "ERROR: file '#{file}' does not exist"
global_status = 1
next
end
$stderr.puts "processing #{file}"
file_handle = File.open(file)
options = {
element_of_interest: 'dao',
attribute_of_interest: 'xlink:role',
filename: file
}
parser = NYUDL::EAD::ElementAttributeAnalyzer.new(options)
Nokogiri::XML::SAX::Parser.new(parser).parse(file_handle)
grand_master_set.merge(parser.attribute_values)
unless parser.errors.length == 0
global_status = 1
global_errors << "file: #{file} has #{parser.errors.length} error(s)"
global_errors << parser.errors
end
end
puts "ROLES:"
puts grand_master_set.sort
puts ""
puts "ERRORS:"
global_errors.each {|e| puts e}
exit global_status