call Session;

call log('load_human_annotations.sql', 'begin');

call log('HumanAnnotations',   'begin');

call drop_table('HumanAnnotations');

create table HumanAnnotations like human_annotations_train;
alter table HumanAnnotations  drop column id;
alter table HumanAnnotations  add column DATASET varchar(20);

call log('HumanAnnotations', 'begin');
call log('HumanAnnotations', 'TRAIN');

select count(*) from HumanAnnotations into @num_rows;

insert into HumanAnnotations (DATASET, subject_id, tag_name, tag_value, start_idx,end_idx)
select 'TRAIN' , subject_id, tag_name, tag_value, start_idx,end_idx
from human_annotations_train;

call log('HumanAnnotations', @num_rows);
call log('HumanAnnotations',  'TEST');

insert into HumanAnnotations (DATASET, subject_id, tag_name, tag_value, start_idx,end_idx)
select 'TEST' , subject_id, tag_name, tag_value, start_idx,end_idx
from human_annotations_test;

select count(*) from HumanAnnotations into @num_rows;

call log('HumanAnnotations',  @num_rows);
call log('HumanAnnotations', 'done');
call log('Class',            'begin');

call drop_table('Class');

create table Class
(
  class_idx  smallint UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
  class      varchar(20),
  cnt        integer,
  DATASET    varchar(10)
) engine = myisam;


insert into Class (DATASET, class) values (@DATASET, 'NA');
insert into Class (DATASET, class, cnt)
select @DATASET, tag_name as class, count(*) as cnt
from HumanAnnotations
where DATASET = @DATASET
group by tag_name;

alter table  Class add index (class);

call log('Class',   'done');
call log('load_human_annotations.sql', 'done');