-
Notifications
You must be signed in to change notification settings - Fork 0
/
hierarchy.rb
55 lines (46 loc) · 1.41 KB
/
hierarchy.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
require 'json'
ontology = ARGV[0]
ontology = JSON.parse(File.read(ontology))
prefix_in = ARGV[1]
prefix_out = ARGV[2]
class_set = []
ontology_ids = ontology['superclass'].transform_values{ |superclass|
superclass['class'].transform_values{ |classes|
classes['subclass']&.keys
}
}
mv = ontology_ids.collect{ |superclass_id, superclass|
class_set << "#{prefix_out}/#{superclass_id}"
mv = superclass.collect{ |classs_id, classes|
subclass = if classes
class_set << "#{prefix_out}/#{superclass_id}/#{classs_id}"
classes.collect{ |subclass_id|
file_in = "#{prefix_in}/#{subclass_id}.svg"
file_out = "#{prefix_out}/#{superclass_id}/#{classs_id}/#{subclass_id}.svg"
if File.exist?(file_in)
"mv #{file_in} #{file_out}"
else
warn "MISSING #{file_in} -> #{file_out}"
end
}
end || []
file_in = "#{prefix_in}/#{classs_id}.svg"
file_out = "#{prefix_out}/#{superclass_id}/#{classs_id}.svg"
if File.exist?(file_in)
subclass << "mv #{file_in} #{file_out}"
elsif !classes
warn "MISSING #{file_in} -> #{file_out}"
end
subclass
}
file_in = "#{prefix_in}/#{superclass_id}.svg"
file_out = "#{prefix_out}/#{superclass_id}.svg"
if File.exist?(file_in)
mv += ["mv #{file_in} #{file_out}"]
else
warn "MISSING #{file_in} -> #{file_out}"
end
mv
}.flatten.compact
puts "mkdir -p #{class_set.join(' ')}"
puts mv