#!/usr/bin/perl -w
#
# kvasikode
#
# Felt:
# # fitswe (denne berre for referanse)
# #"Lemma","POS","trans"
# 
# # nobfkv
# #"Lemma;POS;trans;stamme1;stamme2;eks;syn1;syn2"
# 
# Les inn felta
# 
# Putt relevante felt inn i relevante stader i xml-strukturen
# 
#   <entry>
#     <lemma POS="POS">Lemma</lemma>
#     <mgr>
#       <trgr>
#         <trans decl="POS">trans</trans>
#       </trgr>
#     </mgr>
#  </entry>      

########################################################

use encoding 'utf-8';

# File and directory variables:
$SRCDIR = ".";

$CSVF = $SRCDIR . "/fitswe.csv";

$DICT = $SRCDIR . "/dictionary.xml";

open CSVF or die "Can't find file $CSVF: $!\n";
open DICT, ">$DICT" or die "Can't find file $DICT: $!\n";

print DICT "<dictionary >\n";

$line = <CSVF> ;

while ( $line = <CSVF> ) {
	chomp $line;
	($Lemma,
	 $POS,
	 $trans)
	   = split /"?,"?/, $line ;
#    print "Lina er: $line\n";
#    print "Lemma er: $Lemma\n";
    $Lemma =~ s/"\W?(\w)/$1/; # rens $Lemma for " og ^L
    print DICT "\t<entry>\n";
    print DICT "\t  <lemma POS=\"$POS\">$Lemma</lemma>\n";
    print DICT "\t  <mgr>\n";
    print DICT "\t    <trgr>\n";
    print DICT "\t      <trans decl=\"$POS\">$trans</trans>\n";
    print DICT "\t    </trgr>\n";
    print DICT "\t  </mgr>\n";
    print DICT "\t</entry>\n";
}

print DICT "</dictionary>\n";
close DICT;
close CSVF;


# Note: Desse blir feil og skal fiksast:
# Dei blir merka som exgr, skal vers syneks
# "levoton paikka","louhikkonen",
# "tykköö","Hän oon minun tykkönä",
# "tykköö","Hän oon minun tykkönä",
# "himmee","Himmi sää oon umpu sää",
# "himmee","Himmi sää oon umpu sää",
# "tykönä","Hän oon minun tykköö",
# "tykönä","Hän oon minun tykköö",
# 
# "Nahka kun menee ",,
# "Tehe nyt sen valmhiiksi!",,
# "Tehe nyt sen valmhiiksi!",,
# "Ole vaiti!",,
# 
