5 #no warnings 'uninitialized';
7 # Usage: add-affixes [<inc_level>] [<flags>]
10 if ($ARGV[0] =~ /^[\d.]+$/) {
11 $inc_level = $ARGV[0];
15 #print STDERR "Include Level: $inc_level\n";
18 my $just_possessive = 0;
19 my $no_possessive = 0;
21 if ($_ eq 'use-all') {$use_all = 2}
22 elsif ($_ eq 'use-some') {$use_all = 1}
23 elsif ($_ eq 'just-possessive') {$just_possessive = 1}
24 elsif ($_ eq 'no-possessive') {$no_possessive = 1}
25 else {die "ERROR: Invalid flag $_\n";}
28 open F, "r/alt12dicts/2of12id.txt" or die;
33 # possessive_cross = additional forms that should be looked up in the
39 # (flags, base word, part of speach, infl forms)
40 my ($d,$w,$p,$a) = /^([-@]?)(\w+) (.).*: ?(.*)$/ or die;
41 $possessive{$w} = "$w\'s\n" if $p eq 'N' && ($d eq '' || $use_all);
43 my @a = $a =~ /([-~@!\w]+)/g;
44 @a = map {"$d$_"} @a if ($d);
46 foreach (@a) {if (s/^[~!-]//) {push @a0, $_} else {push @a1, $_}}
47 $remove{"$w:$p"} = 1 unless @a1;
48 foreach (@a0) {$remove{"$w:$p:$_"} = 1}
51 # Maybe using AGID isn't a good idea here, many of the entries in AGID
52 # are unchecked, for example "associationism" may be an uncountable
53 # noun, but since the base entry is not in 2of12id it is not flagged
54 # that way, thus the plural "associationisms" gets included. However,
55 # AGID still needs to be used for uppercase words since they are not
56 # in 2of12id. For now I won't worry about it since it primary effects
59 open F, "r/infl/infl.txt" or die;
62 # (base word, part of speach, guess flag, infl forms)
63 my ($w,$p,$q,$a) = /(\S+) (.)(.*): (.+)/ or die;
65 # AGID things it is a noun and "use-some" or Uppercase
66 # (since 2of12id doesn't include uppercase)
67 # AGIG is guessing it is a noun and "use-all"
68 my $add_possessive = $p eq 'N' && (($q eq '' && ($use_all || $w =~ /^[A-Z]/))
70 $possessive{$w} = "$w\'s\n" if $add_possessive;
71 next if $remove{"$w:$p"};
72 next unless $q eq '' || $use_all >= 2;
73 my @a = split /, | \| /, $a;
74 @a = grep {my ($word,$tags,$level)
75 = /^([A-Za-z\']+)([~<!?]*)(| [\d.]+)(| {\S+})$/ or die $_;
77 $tags !~ /~|\?|!</ && $level <= $inc_level} @a;
78 @a = grep {not $remove{"$w:$p:$_"}} @a;
80 $lookup{$w} .= join("\n",@a)."\n";
82 # For irregular nouns that have plurals that do not end in s
83 # then add the possessive form of the plural as well
84 next unless $add_possessive;
87 $possessive{$_} .= "$_\'s\n";
88 push @{$possessive_cross{$w}}, $_
92 unless ($no_possessive) {
94 open F, "r/special/not-possessive" or die;
98 delete $possessive{$_};
101 open F, "working/possessive-also.lst" or die;
105 $possessive{$_} = "$_\'s\n";
113 print $lookup{$w} unless $just_possessive;
114 print $possessive{$w} unless $no_possessive;
115 unless ($just_possessive || $no_possessive) {
116 foreach (@{$possessive_cross{$w}}) {
117 print $possessive{$_}