/[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 6 - (show annotations)
Sat Feb 26 16:19:22 2005 UTC (19 years, 1 month ago) by dpavlin
Original Path: stem-hr.pl
File MIME type: text/plain
File size: 2034 byte(s)
quick fix

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 use strict;
22
23 sub kgh {
24 my ($pre,$replace,$post) = @_;
25 $replace =~ s/[cè]/k/g;
26 $replace =~ s/[z¾]/g/g;
27 $replace =~ s/[s¹]/h/g;
28 return $pre . $replace . $post;
29 }
30
31 # samoglasnici
32 my $sa = '[aeiou]';
33 # suglasnici
34 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(<>) {
55 chomp;
56 next if (/^#/);
57 if (/^$/) {
58 print "\n";
59 $last_stem = '';
60 next;
61 }
62
63 $words++;
64
65 my $orig = $_;
66
67 # imenice
68
69 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
81 s/(${su}a{$su})a/$1 4/g ||
82 s/(${su})(${su})(a|u|i|e|om|ima)$/$1a$2 5/g
83 ) {
84
85 # vrsta a
86 s/me$/me 11/g ||
87 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
96 s/(${su})(ov|ev)*(i|a|ima|e|in|ina|eta)$/$1 6/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,$_);
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 }

Properties

Name Value
svn:executable

  ViewVC Help
Powered by ViewVC 1.1.26