/[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 5 - (show annotations)
Sat Feb 26 02:18:43 2005 UTC (19 years, 1 month ago) by dpavlin
Original Path: stem-hr.pl
File MIME type: text/plain
File size: 2048 byte(s)
some experiments

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/${palatal}e$/$1e 10/g ||
72 s/(${su}st)a$/$1 13/g ||
73 s/(${su})c[ae]$/$1ce 17/g ||
74 # kgh
75 s/(${sa})([è¾¹czs])(i|e|ima)$/kgh($1,$2,' 1')/gex ||
76 s/(${sa}[kgh])(a|u|om)$/$1 2/g ||
77 s/(${su})([è¾¹czs])(i|e|ima)$/kgh($1,"a$2",' 3')/gex ||
78 # imenice na palatal
79 s/${palatal}${palatal}(a|u|em|i|ima|e)$/$1a$2 9/g ||
80 s/${palatal}(a|u|em)$/$1 8/g ||
81 # nepostojano a
82 s/(${su}a{$su})a/$1 4/g ||
83 s/(${su})(${su})(a|u|i|e|om|ima)$/$1a$2 5/g
84 ) {
85
86 # vrsta a
87 s/me$/me 11/g ||
88 s/(eta|ena)$/e 12/g ||
89 s/(${sa}${su})(o|e|a|u|om|em|i|ima)$/$1 7/g;
90
91 s/(${su})sa$/$1as 14/g ||
92 s/(${su})ena$/$1e 16/g ||
93 s/eta$/e 17/g ||
94 s/(${su})([oe])$/$1-$2 18/g ||
95
96 # mno¾ina
97 s/(${su})(ov|ev)*(i|a|ima|e|in|ina|eta)$/$1 6/g;
98 }
99
100 if (s/^(.+)\s(\d+)$/$1\t$2/g) {
101 $rules{$2}++;
102 $stems++;
103 $stem_words{$1}++;
104 check_stem($1);
105 } else {
106 $last_stem = $_;
107 }
108
109 printf("%-15s %s\n",$orig,$_);
110
111 }
112 my $nr_stems = keys(%stem_words);
113 printf "\n# %d words, %d stems in %d ops, %.2f%% size\n",$words,$nr_stems,$stems,($nr_stems*100/$words);
114
115 foreach my $s (keys %stem_words) {
116 print "#stem $stem_words{$s} $s\n";
117 }
118
119 foreach my $r (sort keys %rules) {
120 print "#rule $rules{$r} $r\n";
121 }

Properties

Name Value
svn:executable

  ViewVC Help
Powered by ViewVC 1.1.26