#!/usr/pkg/bin/perl -w

=comment

  YamCha -- Yet Another Multipurpose CHunk Annotator
 
  $Id: zipmodel.in,v 1.3 2004/03/26 13:33:03 taku-ku Exp $;

  Copyright (C) 2000-2004 Taku Kudo <taku-ku@is.aist-nara.ac.jp>
  This is free software with ABSOLUTELY NO WARRANTY.
  
  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.
  
  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.
  
  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
=cut

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";
}
