call log('FeatureOnt', 'begin');
create table FeatureOnt
(
  match_source varchar(50) not null,
  match_value  varchar(50) not null,
  cnt          int         null
) engine = myisam;

insert into FeatureOnt
select match_source,match_value, count(*) as cnt
from OntologyMatch
where match_source != 'regex'
group by match_source,match_value
order by match_source,match_value;

alter table FeatureOnt add feature_idx integer UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY;
alter table FeatureOnt add index (match_source, match_value);
alter table FeatureOnt add index (feature_idx, match_source, match_value);

alter table FeatureOnt add column str text;

update FeatureOnt f, lookup_umls u
 set f.str = u.str
where
    f.match_source = u.sab and
    f.match_value  = u.cui   ;

call log('FeatureOnt',        'done');
call log('FeatureMatrixOnt', 'start');
call log('FeatureMatrixOnt', 'table');


create table FeatureMatrixOnt
(
  sample_idx   MEDIUMINT unsigned ,
  feature_idx  smallint  unsigned ,
  match_source varchar(10)
)
engine = myisam;

call log('FeatureMatrixOnt', 'table');

-- call log('FeatureMatrixOnt',  'slow bulk insert....');
--
-- create table FeatureMatrixOnt
-- select  s.sample_idx,o.match_source, o.match_value
-- from    Sample s, OntologyMatch o
-- where   o.match_source   !='regex'          and
--         o.file_idx        = s.file_idx      and
--         o.start_idx       <= s.start_idx    and
--         o.end_idx         >= s.end_idx        ;
--
-- call log('FeatureMatrixOnt', 'done');