/[stem-hr]/StemHR.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /StemHR.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 4 by dpavlin, Sat Feb 26 00:37:18 2005 UTC revision 8 by dpavlin, Sat Feb 26 18:23:56 2005 UTC
# Line 33  my $sa = '[aeiou]'; Line 33  my $sa = '[aeiou]';
33  # suglasnici  # suglasnici
34  my $su = '[^aeiou]';  my $su = '[^aeiou]';
35    
36    my $palatal = '(lj|nj|j|æ|¾|¹|¾|¹t|¾d)';
37    
38    # glagolni razredi
39    my $g_1r = '[td]';
40    my $g_2r = '[sz]';
41    my $g_3r = '[pb]';
42    my $g_4r = '[kgh]';
43    my $g_5r = '[nm]';
44    my $g_6r = '(:?nu|n)';
45    
46  my %rules;  my %rules;
47  my %stem_words;  my %stem_words;
48  my $words = 0;  my $words = 0;
49  my $stems = 0;  my $stems = 0;
50    
51    
52    my $last_stem = '';
53    my $errors = 0;
54    sub check_stem {
55            my $s = shift || return;
56            if ($last_stem) {
57                    if ($last_stem ne $s) {
58                            print "ERROR==> ";
59                            $errors++;
60                    }
61            } else {
62                    $last_stem = $s;
63            }
64    }
65    
66  while(<>) {  while(<>) {
67          chomp;          chomp;
68            next if (/^#/);
69          if (/^$/) {          if (/^$/) {
70                  print "\n";                  print "\n";
71                    $last_stem = '';
72                  next;                  next;
73          }          }
74    
# Line 49  while(<>) { Line 76  while(<>) {
76    
77          my $orig = $_;          my $orig = $_;
78    
         # imenice  
         # vrsta a  
79    
80          unless (          unless (
81                    # infinitiv
82                    s/(${sa})(ti|æi)$/$1.$2 100/g ||
83                    # 1. razred
84                    s/([^s])[td](em|e¹|emo|ete|oh|osmo|oste|o¹e|ijah|ija¹e|ijasno|ijaste|ijahu|imo|ite|en|ena|eni)$/$1.sti 101/g ||
85                    # 2. razred
86                    s/(${sa}[sz])(em|e¹|e¹emo|ete|u|oh|e|osmo|oste|o¹e|ijah|ija¹e|ijasmo|ijaste|ijahu|imo|ite|uæi|av¹i|ao|la|lo|li|le|la|en|ena|eni)$/$1.sti 102/ ||
87                    # 3. razdred
88                    s/(p|b|sp|su)(em|e¹|e|emo|ete|u|oh|osmo|oste|o¹e|ah|a¹e|asmo|aste|ahu|ijah|ija¹e|i|imo|ite||uæi|av¹i|ao|la|lo|en|ena|eni)$/$1.sti 103/ ||
89    
90                    # imenice
91    
92                    # vrsta a
93                    s/(${su}st)a$/$1 13/g ||
94                    s/(${su})c[ae]$/$1ce 17/g ||
95                  # kgh                  # kgh
96                  s/(${sa})([è¾¹czs])(i|e|ima)$/kgh($1,$2,' 1')/gex ||                  s/(${sa})([è¾¹czs])(i|e|ima)$/kgh($1,$2,' 1')/gex ||
97                  s/(${sa}[kgh])(a|u|om)$/$1 2/g ||                  s/(${sa}[kgh])(a|u|om)$/$1 2/g ||
98                  s/(${su})([è¾¹czs])(i|e|ima)$/kgh($1,"a$2",' 3')/gex ||                  s/(${su})([è¾¹czs])(i|e|ima)$/kgh($1,"a$2",' 3')/gex ||
99                    # imenice na palatal
100                    s/${palatal}${palatal}(a|u|em|i|ima|e)$/$1a$2 9/g ||
101                    s/${palatal}(a|u|em)$/$1 8/g ||
102                  # nepostojano a                  # nepostojano a
103                  s/(${su}a{$su})a/$1 4/g ||                  s/(${su}a{$su})a/$1 4/g ||
104                  s/(${su})(${su})(a|u|i|e|om|ima)$/$1a$2 5/g                  s/(${su})(${su})(a|u|i|e|om|ima)$/$1a$2 5/g
105          ) {          ) {
106    
107                    # vrsta a
108                    s/me$/me 11/g ||
109                    s/(eta|ena)$/e 12/g ||
110                    s/(${sa}${su})(o|e|a|u|om|em|i|ima|ina)$/$1 7/g ||
111    
112                    s/(${su})sa$/$1as 14/g ||
113                    s/(${su})ena$/$1e 16/g ||
114                    s/(${su})eta$/$1e 17/g ||
115                    s/(${su})([oe])$/$1-$2 18/g ||
116    
117                  # mno¾ina                  # mno¾ina
118                  s/(${su})(ov|ev)*(i|a|ima|e|in|ina)$/$1 6/g;                  s/(${su})(ov|ev)*(i|a|ima|e|in|ina|eta)$/$1 6/g;
                 # jednina  
                 s/(o|e|a|u|om|em)$/ 7/g;  
119          }          }
120    
121          if (s/^(.+)\s(\d+)$/$1\t$2/g) {          if (s/^(.+)\s(\d+)$/$1\t$2/g) {
122                  $rules{$2}++;                  $rules{$2}++;
123                  $stems++;                  $stems++;
124                  $stem_words{$1}++;                  $stem_words{$1}++;
125                    check_stem($1);
126            } else  {
127                    $last_stem = $_;
128          }          }
129    
130          printf("%-15s %s\n",$orig,$_);          printf("%-15s %s\n",$orig,$_);
131    
132  }  }
133  my $nr_stems = keys(%stem_words);  my $nr_stems = keys(%stem_words);
134  printf "\n# %d words, %d stems in %d ops, %.2f%% size\n",$words,$nr_stems,$stems,($nr_stems*100/$words);  printf "\n# %d words, %d stems in %d ops, %.2f%% size [%d errors]\n",$words,$nr_stems,$stems,($nr_stems*100/$words),$errors;
135    
136  foreach my $s (keys %stem_words) {  foreach my $s (keys %stem_words) {
137          print "#stem $stem_words{$s} $s\n";          print "#stem $stem_words{$s} $s\n";
138  }  }
139    
140  foreach my $r (keys %rules) {  foreach my $r (sort keys %rules) {
141          print "#rule $rules{$r} $r\n";          print "#rule $rules{$r} $r\n";
142  }  }

Legend:
Removed from v.4  
changed lines
  Added in v.8

  ViewVC Help
Powered by ViewVC 1.1.26