/[Lingua-Spelling-Alternative]/Alternative.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 /Alternative.pm

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

revision 1.2 by dpavlin, Mon Feb 11 14:33:42 2002 UTC revision 1.3 by dpavlin, Mon Feb 11 20:19:59 2002 UTC
# Line 16  $VERSION = '0.01'; Line 16  $VERSION = '0.01';
16          &load_affix          &load_affix
17          );          );
18    
 #my @affix_regexp;  
 #my @affix_add;  
 #my @affix_sub;  
   
19  my $debug=0;  my $debug=0;
20    
21  # stub  #
22    # make new instance of language, get args
23    #
24  sub new {  sub new {
25          my $class = shift;          my $class = shift;
26          my $self = {};          my $self = {};
27          bless($self, $class);          bless($self, $class);
28          $self->{ARGS} = {@_};          $self->{ARGS} = {@_};
29          $debug = $self->{ARGS}->{DEBUG};          $debug = $self->{ARGS}->{DEBUG};
30            @{$self->{affix_regexp}} = ();
31            @{$self->{affix_add}} = ();
32            @{$self->{affix_sub}} = ();
33          $self ? return $self : return undef;          $self ? return $self : return undef;
34  }  }
35    
# Line 79  sub load_affix { Line 79  sub load_affix {
79                  sub nuke_s {                  sub nuke_s {
80                          my $tmp = $_[0];                          my $tmp = $_[0];
81                          return if (!$tmp);                          return if (!$tmp);
82                          $tmp=~s/^ *//g;                  #       $tmp=~s/^\s+//g;
83                          $tmp=~s/ *$//g;                  #       $tmp=~s/\s+$//g;
84                          $tmp=~s/ *//g;                          $tmp=~s/\s+//g;
85                          return $tmp;                          return $tmp;
86                  }                  }
87    
# Line 93  sub load_affix { Line 93  sub load_affix {
93  }  }
94    
95  #  #
96    # function for reading raw findaffix output
97    #
98    
99    sub load_findaffix {
100            my $self = shift;
101            my $filename = shift;
102    
103            print STDERR "reading findaffix output $filename\n" if ($debug);
104    
105            open (A,$filename) || die "Can't open findaffix output $filename: $!";
106            while(<A>) {
107                    chomp;
108                    my @line=split(m;/;,$_,4);
109                    if ($#line > 2) {
110                            push @{$self->{affix_regexp}},'.';
111                            push @{$self->{affix_sub}},$line[0];
112                            push @{$self->{affix_add}},$line[1];
113                    }
114            }
115            return 1;
116    }
117    
118    #
119  # function which returns original word and all alternatives  # function which returns original word and all alternatives
120  #  #
121    
# Line 106  sub alternatives { Line 129  sub alternatives {
129                          my $regexp = $self->{affix_regexp}[$i];                          my $regexp = $self->{affix_regexp}[$i];
130                          my $add = $self->{affix_add}[$i];                          my $add = $self->{affix_add}[$i];
131                          my $sub = $self->{affix_sub}[$i];                          my $sub = $self->{affix_sub}[$i];
132                            print STDERR "r:'$regexp'\t-'",$sub||'',"'\t+'",$add||'',"'\n" if ($debug);
133                          next if length($word) < length($sub);                          next if length($word) < length($sub);
134                          my $tmp_word = $word;                          my $tmp_word = $word;
135                          if ($sub) {                          if ($sub) {
# Line 118  sub alternatives { Line 142  sub alternatives {
142                          } else {                          } else {
143                                  $tmp_word = $word.$add;                                  $tmp_word = $word.$add;
144                          }                          }
145                            print STDERR "\t ?:$tmp_word\n" if ($debug);
146                          if ($tmp_word =~ m/$regexp/ix) {                          if ($tmp_word =~ m/$regexp/ix) {
147  #                               print "$word -> $tmp_word\t-$sub, +$add, regexp: $regexp\n";  #                               print "$word -> $tmp_word\t-$sub, +$add, regexp: $regexp\n";
148                                  push @out,lc($tmp_word);                                  push @out,lc($tmp_word);
# Line 133  __END__ Line 158  __END__
158    
159  =head1 NAME  =head1 NAME
160    
161  Alternative.pm - see all alternatives of a given word in a given language  Alternative.pm - alternative spelling of a given word in a given language
162    
163  =head1 SYNOPSIS  =head1 SYNOPSIS
164    

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

  ViewVC Help
Powered by ViewVC 1.1.26