-
Notifications
You must be signed in to change notification settings - Fork 1
/
recode_pho.rb
59 lines (43 loc) · 1.7 KB
/
recode_pho.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
require 'Datavyu_API'
$percent = 0.10
$output_dir = "~/code/work/seedlings/reliability_data/recode_output"
begin
columns = get_column_list()
for column in columns
col = get_column(column)
annotation_cells = col.cells.select do |elem|
elem.object.to_s.start_with? "%pho"
end
if annotation_cells.empty?
next
end
n = (annotation_cells.size * $percent).ceil
start = rand(0..annotation_cells.size-n)
randrange = annotation_cells.size-1-n
puts("numcells: #{annotation_cells.size} randrange: #{randrange} n: #{n} start: #{start} end: #{start+n} ")
recode_slice = annotation_cells[start..start+(n-1)]
new_column = create_new_column("recode_pho", "object", "utterance_type","object_present","speaker")
for cell in recode_slice
parent = col.cells[cell.ordinal-2]
parent_chi = new_column.make_new_cell()
parent_chi.change_code("object", parent.object)
parent_chi.change_code("utterance_type", "NA")
parent_chi.change_code("object_present", "NA")
parent_chi.change_code("speaker", parent.speaker)
parent_chi.change_code("onset", parent.onset)
parent_chi.change_code("offset", parent.offset)
newcell = new_column.make_new_cell()
newcell.change_code("object", "%pho: ")
newcell.change_code("onset", cell.onset)
newcell.change_code("offset", cell.offset)
newcell.change_code("utterance_type", "NA")
newcell.change_code("speaker", "NA")
newcell.change_code("object_present", "NA")
end
for colu in columns
delete_variable(colu)
end
set_column(new_column)
save_db(File.join(File.expand_path($output_dir), "#{$pj.getProjectName()}_recode.opf"))
end
end