-
Notifications
You must be signed in to change notification settings - Fork 1
/
merge_reliability_chi.rb
98 lines (78 loc) · 2.5 KB
/
merge_reliability_chi.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
require 'Datavyu_API'
$origin_in = "~/code/work/seedlings/datavyu_scripts/data/chichecks_orig"
$recode_in = "~/code/work/seedlings/datavyu_scripts/data/chichecks_combined"
$output_dir = "~/code/work/seedlings/datavyu_scripts/data/chichecks_finalout"
def merge(orig_in, reco_in, groups)
groups.each_value { |files|
prefix = files["orig"][0..4]
puts("**********#{prefix}*********")
if files["consensus"].nil?
next
end
$db, $pj = load_db(File.join(reco_in, files["consensus"]))
conv_col = get_column("recode")
$db, $pj = load_db(File.join(orig_in, files["orig"]))
cols = get_column_list()
if cols.length != 1
puts("\n#{files["orig"]} has more than 1 column\n\n")
exit
else
col = cols[0]
orig_column = get_column(col)
end
for cell in conv_col.cells
# puts(cell.original_ordinal)
found = false
for c in orig_column.cells
if c.ordinal.to_s == cell.original_ordinal.to_s
puts("found ordinal: #{c.ordinal}")
orig_cell = c
found = true
end
end
# orig_cell = orig_column.cells[cell.original_ordinal.to_i-1]
if !found
orig_cell = orig_column.make_new_cell()
puts("made a new cell")
end
puts(orig_cell.object)
orig_cell.change_code("object", cell.object)
orig_cell.change_code("utterance_type", cell.utterance_type)
orig_cell.change_code("object_present", cell.object_present)
orig_cell.change_code("speaker", cell.speaker)
orig_cell.change_code("onset", cell.onset)
orig_cell.change_code("offset", cell.offset)
end
set_column(orig_column)
save_db(File.join(File.expand_path($output_dir), File.basename(files["orig"])))
}
end
begin
orig_in = File.expand_path($origin_in)
reco_in = File.expand_path($recode_in)
orig_files = Dir.new(orig_in).entries
reco_files = Dir.new(reco_in).entries
filenames = orig_files + reco_files
groups = Hash.new
for file in filenames
if file.end_with? ".opf"
prefix = file[0..4]
if groups.has_key?(prefix)
if file.include? "consensus_relia.opf"
groups[prefix]["consensus"] = file
else
groups[prefix]["orig"] = file
end
else
groups[prefix] = Hash.new
if file.include? "consensus_relia.opf"
groups[prefix]["consensus"] = file
else
groups[prefix]["orig"] = file
end
end
end
end
# puts(groups)
merge(orig_in, reco_in, groups)
end