#!/usr/bin/perl -w

# $Id: zipmodel.in,v 1.2 2001/06/14 14:45:18 taku-ku Exp $;
my %oldDicHash = ();
my %oldIdHash  = ();
my %newIdHash = ();
my $paramStr = "";

##################################################
#
# read old param + model
#

# param
while(<>) {
    last if (/^\s*$/);
    $paramStr .= $_;
}

# dic
while(<>) {
    chomp;
    last if (/^\s*$/);
    my ($id, $str) = split;
    $oldDicHash{$id} = $str;
}

#model
while(<>) {
    chomp;
    push(@modelStrList,$_);
    next if (/\#/);
    next if (/^MULTI_CLASS/);
    next if (/^$/);
    next if (/^SVM-light/i || /^TinySVM/i);
    my(@tmp) = split();
    my($class) =  shift(@tmp);
    for (@tmp) { 
	my($i,$v) = split(/:/,$_);
	$oldIdHash{$i} = 1;
    }
}

##################################################
#
# print new param
#
print $paramStr;
print "\n";

my $id = 1;
for (sort {$a <=> $b} (keys %oldIdHash)) {
    my($str) = $oldDicHash{$_};
    print "$id $str\n";
    $newIdHash{$_} = $id;
    $id++;
}
print "\n";

for (@modelStrList) {
  if (/\#/ ||  /^MULTI_CLASS/ || /^$/ || /^SVM-light/ || /^TinySVM/) {
      print "$_\n" ;
      next;
  }
  my(@tmp)   = split();
  my($class) =  shift(@tmp);
  my(@new);
  for (@tmp) { 
      my($i,$v) = split(/:/,$_);
      push(@new,"$newIdHash{$i}:$v");
  }
  print "$class @new\n";
}
