/[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 1 by dpavlin, Fri Feb 25 23:14:44 2005 UTC revision 6 by dpavlin, Sat Feb 26 16:19:22 2005 UTC
# Line 18  Line 18 
18  # - uzvici  # - uzvici
19  #  #
20    
21  sub rm_a {  use strict;
         s/a//g;  
 }  
22    
23  sub kgh {  sub kgh {
24          my ($pre,$replace,$post) = @_;          my ($pre,$replace,$post) = @_;
25          $replace =~ s/[cè]/k/g;          $replace =~ s/[cè]/k/g;
26          $replace =~ s/[z¾]/g/g;          $replace =~ s/[z¾]/g/g;
27          $replace =~ s/[s¹]/h/g;          $replace =~ s/[s¹]/h/g;
28          return $pre . $replace . $post . "\tkgh";          return $pre . $replace . $post;
29  }  }
30    
31  # samoglasnici  # samoglasnici
# Line 35  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    my %rules;
39    my %stem_words;
40    my $words = 0;
41    my $stems = 0;
42    
43    
44    my $last_stem = '';
45    sub check_stem {
46            my $s = shift || return;
47            if ($last_stem) {
48                    print "ERROR==> " if ($last_stem ne $s);
49            } else {
50                    $last_stem = $s;
51            }
52    }
53    
54  while(<>) {  while(<>) {
55          chomp;          chomp;
56            next if (/^#/);
57            if (/^$/) {
58                    print "\n";
59                    $last_stem = '';
60                    next;
61            }
62    
63            $words++;
64    
65          my $orig = $_;          my $orig = $_;
66    
67          # imenice          # imenice
         # vrsta a  
68    
69          unless (          unless (
70                    # vrsta a
71                    s/(${su}st)a$/$1 13/g ||
72                    s/(${su})c[ae]$/$1ce 17/g ||
73                    # kgh
74                    s/(${sa})([è¾¹czs])(i|e|ima)$/kgh($1,$2,' 1')/gex ||
75                    s/(${sa}[kgh])(a|u|om)$/$1 2/g ||
76                    s/(${su})([è¾¹czs])(i|e|ima)$/kgh($1,"a$2",' 3')/gex ||
77                    # imenice na palatal
78                    s/${palatal}${palatal}(a|u|em|i|ima|e)$/$1a$2 9/g ||
79                    s/${palatal}(a|u|em)$/$1 8/g ||
80                  # nepostojano a                  # nepostojano a
81                  s/(${su}a{$su})a/$1 1/g ||                  s/(${su}a{$su})a/$1 4/g ||
82                  s/(${su})(${su})(a|u|i|e|om|ima)$/$1a$2\t3/g                  s/(${su})(${su})(a|u|i|e|om|ima)$/$1a$2 5/g
83          ) {          ) {
84                  # kgh  
85                  s/(${su}${sa})([è¾¹czs])(i|e|ima)$/kgh($1,$2,'')/gex;                  # vrsta a
86  #               s/${su}${sa}[c](i|ima) 4//g;                  s/me$/me 11/g ||
87                  s/(${su}${sa}[kgh])(a|u|om)\t5/$1/g;                  s/(eta|ena)$/e 12/g ||
88                    s/(${sa}${su})(o|e|a|u|om|em|i|ima|ina)$/$1 7/g ||
89    
90                    s/(${su})sa$/$1as 14/g ||
91                    s/(${su})ena$/$1e 16/g ||
92                    s/(${su})eta$/$1e 17/g ||
93                    s/(${su})([oe])$/$1-$2 18/g ||
94    
95                  # mno¾ina                  # mno¾ina
96                  s/(${su})(ov|ev)*(i|a|ima|e|in|ina)$/$1\t6/g;                  s/(${su})(ov|ev)*(i|a|ima|e|in|ina|eta)$/$1 6/g;
                 # jednina  
                 s/(o|e|a|u|om|em)$/\t7/g;  
97          }          }
98    
99            if (s/^(.+)\s(\d+)$/$1\t$2/g) {
100                    $rules{$2}++;
101                    $stems++;
102                    $stem_words{$1}++;
103                    check_stem($1);
104            } else  {
105                    $last_stem = $_;
106            }
107    
108          printf("%-15s %s\n",$orig,$_);          printf("%-15s %s\n",$orig,$_);
109    
110    }
111    my $nr_stems = keys(%stem_words);
112    printf "\n# %d words, %d stems in %d ops, %.2f%% size\n",$words,$nr_stems,$stems,($nr_stems*100/$words);
113    
114    foreach my $s (keys %stem_words) {
115            print "#stem $stem_words{$s} $s\n";
116    }
117    
118    foreach my $r (sort keys %rules) {
119            print "#rule $rules{$r} $r\n";
120  }  }

Legend:
Removed from v.1  
changed lines
  Added in v.6

  ViewVC Help
Powered by ViewVC 1.1.26