# # Conjugation Table (English version) # # Reads the English conjugation table and saves the useful information. # package conjtable_en; use Carp; #Takes a list of 32 words in this order: # (Infinitive, Past tense, # 1SG(PR, PRO, FUT, CND, PER), # 2SG(...), 3SG(...), 1PL(...), 2PL(...) # 3PL(...) @TPNs_EN = qw(INF PAS 1SG-PR 1SG-PRO 1SG-FUT 1SG-CND 1SG-PER 2SG-PR 2SG-PRO 2SG-FUT 2SG-CND 2SG-PER 3SG-PR 3SG-PRO 3SG-FUT 3SG-CND 3SG-PER 1PL-PR 1PL-PRO 1PL-FUT 1PL-CND 1PL-PER 2PL-PR 2PL-PRO 2PL-FUT 2PL-CND 2PL-PER 3PL-PR 3PL-PRO 3PL-FUT 3PL-CND 3PL-PER GER); #@MODAL = qw(would should could may); #@1SG_COP = qw(am was); #@2SG_COP = qw(are were); #@3SG_COP = qw(is was); #@1PL_COP = qw(are were); #@2PL_COP = qw(are were); #@3PL_COP = qw(are were); %lookup_table = (); # conjform -> list of TPNs_EN %conjugations = (); # infinitive -> list of conjugations (no duplicates), | sep # also: TPN-inf_en -> correct conjugation %map_fr = (); # This is the French-to-English map of the tenses %map_en = (); # This is the English-to-French map of the tenses &init_en(); &init_map(); sub fill_conjtable_en { my (@conjs_en) = @_; my $inf = $conjs_en[0]; $i = 0; foreach (@conjs_en) { my ($verb) = $_; #print "Conjugation of $TPNs_EN[$i]-$inf is $verb\n"; my ($already_there) = $lookup_table{$verb}; if (defined $already_there ) { $lookup_table{$verb} = $already_there . ",$TPNs_EN[$i]-$inf"; } else { $lookup_table{$verb} = "$TPNs_EN[$i]-$inf"; } $conjugations{"$TPNs_EN[$i]-$inf"} = $verb; $i++; } my (%uniq) = (); foreach (@conjs_en) { $uniq{$_} ++; } $conjugations{$inf} = join "|", keys %uniq; #print "All conjugations of $inf = $conjugations{$inf}\n"; } sub init_en { my $filename = $_[0] || "full_conj_en.txt"; %lookup_table = (); %conjugations = (); open (FILE, $filename) or croak "Couldn't read $filename for conjugations" and return; my (@verbs_en); while () { if ($_ =~ /-----/) { if (defined @verbs_en) { warn "Filling conjugation for $verbs_en[0]\n" if $main::verbose; &fill_conjtable_en(@verbs_en); } @verbs_en = (); } else { chomp; push @verbs_en, $_; } } } sub init_map { my $filename = $_[0] || "map.txt"; %map_fr = (); %map_en = (); open (FILE, $filename) or croak "Couldn't read $filename for conjugations_en" and return; while () { if ($_ =~ /-----/) { warn "Filling map\n" if $main::verbose; } else { chomp; @field = split(/->/,$_); #If there are duplicates, append to the end with a comma $tempresult = $map_fr{$field[0]}; if ($tempresult ne "") { $map_fr{$field[0]} = $tempresult . "," . $field[1]; } else { $map_fr{$field[0]} = $field[1]; } $tempresult = $map_en{$field[1]}; if ($tempresult ne "") { $map_en{$field[1]} = $tempresult . "," . $field[0]; } else { $map_en{$field[1]} = $field[0]; } } } } 1;