# # Conjugation Table # # Reads a conjugation table and saves the useful information. # # For now, all it does is maps Conjugated Verbs (in french) # to their possible tense/person/number (TPN) # package conjtable_fr; use Carp; #Takes a list of 37 words in this order: # (Infinitive, # 1SG(IND, IMP, SBJ, FUT, CND, PAS), # 2SG(...), 3SG, 1PL, 2PL, 3PL) @TPNs = qw(INF-INF 1SG-IND 1SG-IMP 1SG-SBJ 1SG-FUT 1SG-CND 1SG-PAS 2SG-IND 2SG-IMP 2SG-SBJ 2SG-FUT 2SG-CND 2SG-PAS 3SG-IND 3SG-IMP 3SG-SBJ 3SG-FUT 3SG-CND 3SG-PAS 1PL-IND 1PL-IMP 1PL-SBJ 1PL-FUT 1PL-CND 1PL-PAS 2PL-IND 2PL-IMP 2PL-SBJ 2PL-FUT 2PL-CND 2PL-PAS 3PL-IND 3PL-IMP 3PL-SBJ 3PL-FUT 3PL-CND 3PL-PAS 1SG-VA 2SG-VA 3SG-VA 1PL-VA 2PL-VA 3PL-VA); %lookup_table = (); # conjform -> list of TPNs %conjugations = (); # infinitive -> list of conjugations (no duplicates), | sep # also: TPN-inf -> correct conjugation &init(); sub fill_conjtable { my (@conjs) = @_; my $inf = $conjs[0]; $i = 0; foreach (@conjs) { my ($verb) = $_; #print "Conjugation of $TPNs[$i]-$inf is $verb\n"; my ($already_there) = $lookup_table{$verb}; if (defined $already_there ) { $lookup_table{$verb} = $already_there . ",$TPNs[$i]-$inf"; } else { $lookup_table{$verb} = "$TPNs[$i]-$inf"; } $conjugations{"$TPNs[$i]-$inf"} = $verb; $i++; } my (%uniq) = (); foreach (@conjs) { $uniq{$_} ++; } $conjugations{$inf} = join "|", keys %uniq; } sub init { my $filename = $_[0] || "fuller_conj_fr.txt"; %lookup_table = (); %conjugations = (); open (FILE, $filename) or croak "Couldn't read $filename for conjugations" and return; my (@verbs); while () { if ($_ =~ /-----/) { if (defined @verbs) { warn "Filling conjugation for $verbs[0]\n" if $main::verbose; &fill_conjtable(@verbs); } @verbs = (); } else { chomp; push @verbs, $_; } } } 1; # vim:sw=2