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

Contents of /StemHR.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3 - (show annotations)
Sat Feb 26 00:01:42 2005 UTC (19 years, 1 month ago) by dpavlin
Original Path: stem-hr.pl
File MIME type: text/plain
File size: 1226 byte(s)
yummy: stats

1 #!/usr/bin/perl -w
2 #
3 # Croatian stemmer
4 #
5
6 # promjenjive:
7 # - imenice
8 # - pridjevi
9 # - brojevi
10 # - zamjenice
11 # - prilozi
12 # - glagoli
13 #
14 # nepromjenjive:
15 # - prijedlozi
16 # - veznici
17 # - èestice
18 # - uzvici
19 #
20
21 sub kgh {
22 my ($pre,$replace,$post) = @_;
23 $replace =~ s/[cè]/k/g;
24 $replace =~ s/[z¾]/g/g;
25 $replace =~ s/[s¹]/h/g;
26 return $pre . $replace . $post;
27 }
28
29 # samoglasnici
30 my $sa = '[aeiou]';
31 # suglasnici
32 my $su = '[^aeiou]';
33
34 my %rules;
35 my %stem_words;
36 my $words = 0;
37 my $stems = 0;
38
39 while(<>) {
40 chomp;
41 if (/^$/) {
42 print "\n";
43 next;
44 }
45
46 $words++;
47
48 my $orig = $_;
49
50 # imenice
51 # vrsta a
52
53 unless (
54 # kgh
55 s/(${sa})([è¾¹czs])(i|e|ima)$/kgh($1,$2,' 1')/gex ||
56 s/(${sa}[kgh])(a|u|om)$/$1 2/g ||
57 s/(${su})([è¾¹czs])(i|e|ima)$/kgh($1,"a$2",' 3')/gex ||
58 # nepostojano a
59 s/(${su}a{$su})a/$1 4/g ||
60 s/(${su})(${su})(a|u|i|e|om|ima)$/$1a$2 5/g
61 ) {
62
63 # mno¾ina
64 s/(${su})(ov|ev)*(i|a|ima|e|in|ina)$/$1 6/g;
65 # jednina
66 s/(o|e|a|u|om|em)$/ 7/g;
67 }
68
69 if (s/^(.+)\s(\d+)$/$1\t$2/g) {
70 $rules{$2}++;
71 $stems++;
72 $stem_words{$1}++;
73 }
74
75 printf("%-15s %s\n",$orig,$_);
76
77 }
78 my $nr_stems = keys(%stem_words);
79 printf "\n# %d words, %d stems in %d ops, %.2f%% size\n",$words,$nr_stems,$stems,($nr_stems*100/$words);
80

Properties

Name Value
svn:executable

  ViewVC Help
Powered by ViewVC 1.1.26