/[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

stem-hr.pl revision 4 by dpavlin, Sat Feb 26 00:37:18 2005 UTC StemHR.pm revision 15 by dpavlin, Thu Jun 28 10:34:39 2007 UTC
# Line 1  Line 1 
1  #!/usr/bin/perl -w  package StemHr;
2    
3  #  #
4  # Croatian stemmer  # Croatian stemmer
5  #  #
# Line 19  Line 20 
20  #  #
21    
22  use strict;  use strict;
23    use locale;
24    
25    use Memoize;
26    #memoize('stem');
27    
28  sub kgh {  sub kgh {
29          my ($pre,$replace,$post) = @_;          my ($pre,$replace,$post) = @_;
# Line 33  my $sa = '[aeiou]'; Line 38  my $sa = '[aeiou]';
38  # suglasnici  # suglasnici
39  my $su = '[^aeiou]';  my $su = '[^aeiou]';
40    
41  my %rules;  my $palatal = '(lj|nj|j|æ|¾|¹|¾|¹t|¾d)';
 my %stem_words;  
 my $words = 0;  
 my $stems = 0;  
   
 while(<>) {  
         chomp;  
         if (/^$/) {  
                 print "\n";  
                 next;  
         }  
42    
43          $words++;  # glagolni razredi
44    my $g_1r = '[td]';
45    my $g_2r = '[sz]';
46    my $g_3r = '[pb]';
47    my $g_4r = '[kgh]';
48    my $g_5r = '[nm]';
49    my $g_6r = '(:?nu|n)';
50    
51          my $orig = $_;  sub stem {
52    
53          # imenice          my $w = shift || return;
         # vrsta a  
54    
55          unless (          unless (
56                    # infinitiv
57                    $w =~ s/(\w)(ti|æi)$/$1.$2 100/g ||
58                    # 1. razred
59                    $w =~ s/([^sk])[td](em|e¹|e|emo|ete|oh|osmo|oste|o¹e|ijah|ija¹e|ijasno|ijaste|ijahu|imo|ite|en|ena|eni)$/$1s.ti 101/g ||
60                    # 2. razred
61                    $w =~ s/(${sa})[sz](em|e¹|e|e¹emo|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)$/$1s.ti 102/ ||
62                    # 3. razred
63                    $w =~ 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|ijahu|i|imo|ite||uæi|av¹i|ao|la|lo|en|ena|eni)$/$1s.ti 103/ ||
64                    # 4. razred
65                    $w =~ s/[è¾¹](em|e¹|e|emo|ete|u|ah|ahu|en|ena)$/.æi 104/g ||
66                    $w =~ s/[k](oh|osmo|oste|o¹e|uæi|av¹i|ao|la|lo)$/.æi 105/g ||
67                    $w =~ s/[c](ijah|ija¹e|ijasmo|ijaste|ijahu|i|imo|ite)$/.æi 106/g ||
68                    $w =~ s/[g](nuti|oh|nuh|nu|av¹i|nuv¹i|ao|nuo|nem|ne¹|ni|imo|nut|nimo)$/.æi 107/g ||
69    
70                    # imenice
71    
72                    # vrsta a
73                    $w =~ s/(${su}st)a$/$1 13/g ||
74                    $w =~ s/(${su})c[ae]$/$1ce 17/g ||
75                  # kgh                  # kgh
76                  s/(${sa})([è¾¹czs])(i|e|ima)$/kgh($1,$2,' 1')/gex ||                  $w =~ s/(\w${sa})([è¾¹czs])(i|e|ima)$/kgh($1,$2,' 1')/gex ||
77                  s/(${sa}[kgh])(a|u|om)$/$1 2/g ||                  $w =~ s/(${sa}[kgh])(a|u|om)$/$1 2/g ||
78                  s/(${su})([è¾¹czs])(i|e|ima)$/kgh($1,"a$2",' 3')/gex ||                  $w =~ s/(${su})([è¾¹czs])(i|e|ima)$/kgh($1,"a$2",' 3')/gex ||
79                    # imenice na palatal
80                    $w =~ s/${palatal}${palatal}(a|u|em|i|ima|e)$/$1a$2 9/g ||
81                    $w =~ s/${palatal}(a|u|em)$/$1 8/g ||
82                  # nepostojano a                  # nepostojano a
83                  s/(${su}a{$su})a/$1 4/g ||                  $w =~ s/(${su}a{$su})a/$1 4/g ||
84                  s/(${su})(${su})(a|u|i|e|om|ima)$/$1a$2 5/g                  $w =~ s/(${su})(${su})(a|u|i|e|om|ima)$/$1a$2 5/g
85          ) {          ) {
86    
87                  # mno¾ina                  # vrsta a
88                  s/(${su})(ov|ev)*(i|a|ima|e|in|ina)$/$1 6/g;                  $w =~ s/me$/me 11/g ||
89                  # jednina                  $w =~ s/(eta|ena)$/e 12/g ||
90                  s/(o|e|a|u|om|em)$/ 7/g;  
91          }                  $w =~ s/(\w${sa}${su})(o|e|a|u|om|em|i|ima|ina|eta)$/$1 7/g ||
92    
93                    $w =~ s/(${su})sa$/$1as 14/g ||
94                    $w =~ s/(${su})ena$/$1e 16/g ||
95                    $w =~ s/(${su})eta$/$1e 17/g ||
96                    $w =~ s/(${su})([oe])$/$1$2 18/g ||
97    
98          if (s/^(.+)\s(\d+)$/$1\t$2/g) {                  0;
                 $rules{$2}++;  
                 $stems++;  
                 $stem_words{$1}++;  
         }  
99    
100          printf("%-15s %s\n",$orig,$_);          }
101    
102  }          # makni broj pravila
103  my $nr_stems = keys(%stem_words);          $w =~ s/\s\d+$//;
104  printf "\n# %d words, %d stems in %d ops, %.2f%% size\n",$words,$nr_stems,$stems,($nr_stems*100/$words);          # makni toèku koja oznaèava korjen rijeèi
105            $w =~ s/\.//g;
106    
107  foreach my $s (keys %stem_words) {          return $w;
         print "#stem $stem_words{$s} $s\n";  
108  }  }
109    
 foreach my $r (keys %rules) {  
         print "#rule $rules{$r} $r\n";  
 }  

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

  ViewVC Help
Powered by ViewVC 1.1.26