#!/usr/bin/perl


# for Suffixes...

# ./SuffLexEntries2MorphEntries.pl < /usr0/aria/quechua2spa/lexicons/SuffLexicon1.trf >! /usr0/aria/quechua2spa/morph_analysis/Auto-SuffLex-SuffLexicon1.txt

# need to get rid of empty SLwords ("")


#IN (from translation lexicon):
#VSuff::VSuff |: [nki] -> [""]
#(
#(X1::Y1)
#((x0 person) = 2)
#((x0 number) = sg)
#((x0 mood) = ind)
#((x0 tense) = pres) ; if tense is *UNDEFINED* pres or future didn't work
#((x0 inflected) = +)
#)

#OUT (for morphology lexicon):
#nki;      V; n.3,  ;    ( ( lex nki ) ( pos VSuff ) ( person 2 ) ( number sg ) ( tense pres ) ( mood ind ) )



while (<>){
    # if the end of the rule has been reached ")", print out rule
    if ( /^\)$/ ) {
	print STDOUT "$lex;\t$POS;\t ; ((lex $lex) (pos $POS) $features)\n";
    } elsif ( /;.*/ ){ 
	next;
    } else {      # if it's not a comment
	$line = $_;
	if ( $line =~ /^[A-Z].*/ ) {  # just lines starting with a POS
	    ($POS,$trash1,$trash2,$rest) = split(/:/);
	    ($lex,$trash3) = split(/]/,$rest);
	    $lex =~ s/ \[([a-z]+)/$1/;  # getting rid of spaces and [
	    $features = "";
                           #((x0 inflected) = +)
	} elsif ( $line =~ /.*\:\:\.*/ ) {
	    next;
	} elsif ( $line =~ /^\($/ ) {
	    next;
	} elsif ( $line =~ /^\n$/ ) {
	    next;
	} else {
	    ($attr,$val) = split(/=/);
	    chomp($attr);
	    chomp($val);
	    $attr =~ s/\(\(x0 ([a-z]+)\) /$1/;
          # need to make sure value does not have any parents
	    $val =~ s/ ([a-z1-9*+-]+)\)/$1/;
#	    print STDOUT "attr is |$attr| and val is |$val| \n";
            
            $features = $features . "($attr $val)"; 
	}        
    }
}


