#!/usr/bin/perl

open(INPUT_FILE, "< /home/kurisuto/documents/linguistics/norse_class/schema_strong_verbs") || die "Fatal error:$!\n";

while (<INPUT_FILE>) {
    
    chop;
    push @schemata, $_;
    
}


while (<>) {
    
    chop;

    ($command, $class, $base, $infinitive, $gloss) = split(/\t/);


    foreach $schema (@schemata) {

	($basetype, $pos_tags, $sound_change, $ending) = split(/\t/, $schema);

	$basecopy = $base;
	if ($sound_change eq "uml") {
	    $basecopy =~ s/au/ey/;
	    $basecopy =~ s/j//;
	    $basecopy =~ s/\&o-hook;//;
	    $basecopy =~ s/a/e/;
	    $basecopy =~ s///;
	    $basecopy =~ s/o//;
	    $basecopy =~ s//\&oelig;/;
	    $basecopy =~ s/u/y/;
	    $basecopy =~ s///;
	}
	if ($sound_change eq "u") {
	    $basecopy =~ s/a/\&o-hook;/;
	}

	$thisform = $basecopy . $ending;

	# 2 and 3 pres sg indic
	# This isn't right!  Needs to only be long stems!
	$thisform =~ s/s111r/ss/;
	$thisform =~ s/l111r/ll/;
	$thisform =~ s/n111r/nn/;
	$thisform =~ s/x111r/x/;
	$thisform =~ s/111//;

	# 2 pret sg indic
	$thisform =~ s/[t]222t/zt/;
	$thisform =~ s/222t/tt/;   # Need to do this with all long stems.
	$thisform =~ s/222//;
	
	# 1 and 3 pret sg indic
	$thisform =~ s/g333/k/;
	$thisform =~ s/d333/t/;
	$thisform =~ s/333//;

	if ($basetype eq $command) {
	    print $thisform, "\t$infinitive+verb+", $class, "+", $pos_tags, "\t", $gloss, "\n";
	}
	
	
    }
    

}
