/[stem-hr]/stem-hr.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 /stem-hr.pm

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

stem-hr.pl revision 11 by dpavlin, Sat Jul 9 10:04:51 2005 UTC stem-hr.pm revision 12 by dpavlin, Sat Jul 9 10:15:09 2005 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  sub kgh {  sub kgh {
26          my ($pre,$replace,$post) = @_;          my ($pre,$replace,$post) = @_;
# Line 43  my $g_4r = '[kgh]'; Line 45  my $g_4r = '[kgh]';
45  my $g_5r = '[nm]';  my $g_5r = '[nm]';
46  my $g_6r = '(:?nu|n)';  my $g_6r = '(:?nu|n)';
47    
48  my %rules;  sub stem {
 my %stem_words;  
 my $words = 0;  
 my $stems = 0;  
   
   
 my $last_stem = '';  
 my $errors = 0;  
 sub check_stem {  
         my $s = shift || return;  
         if ($last_stem) {  
                 if ($last_stem ne $s) {  
                         print "ERROR==> ";  
                         $errors++;  
                 }  
         } else {  
                 $last_stem = $s;  
         }  
 }  
   
 while(<>) {  
         chomp;  
         next if (/^#/);  
         if (/^$/) {  
                 print "\n";  
                 $last_stem = '';  
                 next;  
         }  
   
         $words++;  
   
         my $orig = $_;  
   
49    
50          unless (          unless (
51                  # infinitiv                  # infinitiv
# Line 124  while(<>) { Line 94  while(<>) {
94    
95          }          }
96    
97          if (s/^(.+)\s(\d+)$/$1\t$2/g) {          s/\s\d+$//;
                 $rules{$2}++;  
                 $stems++;  
                 $stem_words{$1}++;  
                 check_stem($1);  
         } else  {  
                 $last_stem = $_;  
         }  
   
         printf("%-15s %s\n",$orig,$_);  
   
98  }  }
 my $nr_stems = keys(%stem_words);  
 printf "\n# %d words, %d stems in %d ops, %.2f%% size [%d errors]\n",$words,$nr_stems,$stems,($nr_stems*100/$words),$errors;  
99    
 foreach my $s (keys %stem_words) {  
         print "#stem $stem_words{$s} $s\n";  
 }  
   
 foreach my $r (sort keys %rules) {  
         print "#rule $rules{$r} $r\n";  
 }  

Legend:
Removed from v.11  
changed lines
  Added in v.12

  ViewVC Help
Powered by ViewVC 1.1.26