#!/usr/bin/perl

# Takes a file of (keywork \t paperID) lines and groups all of the
# keywords for the same paperid into the appropriate \keywords macro

$input = $ARGV[0];

open( INPUT, $input ) || die "no input file";

$holdpaper = '' ;
$didOneAlready = 0;

while( $line=<INPUT> ) {
    chomp $line;
    ( $key, $paper ) = split( '\t', $line );
    if( "$paper" ne "$holdpaper" ) {
	print "}\n\n";
	if( $didOneAlready ){
	    $didOneAlready = 0;
        }
        print "$paper\n";
	print "\\keywords{";
    }
    $holdpaper = $paper;
    if( $didOneAlready ) {
	print ", ";
    }
    print $key;
    $didOneAlready = 1;
}
print "}\n";
close INPUT;
