~jtv/corpusfiltergraph/cross-python

« back to all changes in this revision

Viewing changes to trunk/lib/corpusfg/graphs/sa-champollion/hn/light_hindi_stemmer.pl

  • Committer: tahoar
  • Date: 2012-05-02 15:46:23 UTC
  • Revision ID: svn-v4:bc069b21-dff4-4e29-a776-06a4e04bad4e::266
new layout. need to update code to use the new layout

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
##################################################
 
3
#
 
4
#  Light Stemmer for Hindi
 
5
#  
 
6
#  Modified by Xiaoyi Ma 6/6/2003
 
7
#  Created by Kareem Darwish
 
8
#  Last Modified June 4, 2003
 
9
#  kareem@glue.umd.edu
 
10
#
 
11
##################################################
 
12
#
 
13
#  Based on the suffix list provided by A. Ramanathan 
 
14
#  and D. Rao in their paper entitled
 
15
#  "A Lightweight Stemmer for Hindi"
 
16
#
 
17
#  usage:  Reads STDIN, outputs to STDOUT
 
18
#  uses utf8 encoding
 
19
#  
 
20
##################################################
 
21
$| = 1; # disable Perl output buffering
 
22
#use utf8;
 
23
use Encode;
 
24
 
 
25
$Usage = "Usage: $0 [filename]\n";
 
26
die $Usage if ( @ARGV > 1 or ( @ARGV == 1 and ! -f $ARGV[0] ));
 
27
 
 
28
if ( @ARGV ) {
 
29
    open( STDIN, shift );
 
30
}
 
31
binmode STDIN, ":utf8";
 
32
binmode STDOUT, ":utf8";
 
33
 
 
34
# sort by string length
 
35
sub lengthly {length $b <=> length $a };
 
36
 
 
37
# possible suffixes
 
38
$suffixes = "\x{0906} \x{0907} \x{0908} \x{0909} \x{090a} \x{090f} \x{0913} \x{090f}\x{0902} \x{0913}\x{0902} \x{0906}\x{0902} \x{0909}\x{0906}\x{0902} \x{0909}\x{090f}\x{0902} \x{0909}\x{0913}\x{0902} \x{0906}\x{090f}\x{0902} \x{0906}\x{0913}\x{0902} \x{0907}\x{092f}\x{093e}\x{0905}\x{0902} \x{0907}\x{092f}\x{0913}\x{0902} \x{0906}\x{0907}\x{092f}\x{093e}\x{0905}\x{0902} \x{0906}\x{0902}\x{0939} \x{0906}\x{0907}\x{092f}\x{0913}\x{0902} \x{0907}\x{092f}\x{093e}\x{0905}\x{0902}\x{0939} \x{0906}\x{0907}\x{092f}\x{093e}\x{0905}\x{0902}\x{0939} \x{0905}\x{0924}\x{093e}\x{0905}\x{090f}\x{0902} \x{0905}\x{0924}\x{093e}\x{0905}\x{0913}\x{0902} \x{0905}\x{0928}\x{093e}\x{0905}\x{090f}\x{0902} \x{0905}\x{0928}\x{093e}\x{0905}\x{0913}\x{0902} \x{0905}\x{0924}\x{093e}\x{0905} \x{0905}\x{0924}\x{0948}\x{0907} \x{0908}\x{0902} \x{0905}\x{0924}\x{0948}\x{0907}\x{0902} \x{0905}\x{0924}\x{090f} \x{0906}\x{0924}\x{093e}\x{0905} \x{0906}\x{0924}\x{0948}\x{0907} \x{0906}\x{0924}\x{0948}\x{0907}\x{0902} \x{0906}\x{0924}\x{090f} \x{0905}\x{0928}\x{093e}\x{0905} \x{0905}\x{0928}\x{0948}\x{0907} \x{0905}\x{0928}\x{090f} \x{0906}\x{0928}\x{093e}\x{0905} \x{0906}\x{0928}\x{090f} \x{090a}\x{0902}\x{0917}\x{093e}\x{0905} \x{090a}\x{0902}\x{0917}\x{0948}\x{0907} \x{0906}\x{090a}\x{0902}\x{0917}\x{093e}\x{0905} \x{0906}\x{090a}\x{0902}\x{0917}\x{0948}\x{0907} \x{090f}\x{0902}\x{0917}\x{090f} \x{090f}\x{0902}\x{0917}\x{0948}\x{0907} \x{0906}\x{090f}\x{0902}\x{0917}\x{090f} \x{0906}\x{090f}\x{0902}\x{0917}\x{0948}\x{0907} \x{0913}\x{0917}\x{090f} \x{0913}\x{0917}\x{0948}\x{0907} \x{0906}\x{0913}\x{0917}\x{090f} \x{0906}\x{0913}\x{0917}\x{0948}\x{0907} \x{090f}\x{0917}\x{093e}\x{0905} \x{090f}\x{0917}\x{0948}\x{0907} \x{0906}\x{090f}\x{0917}\x{093e}\x{0905} \x{0906}\x{090f}\x{0917}\x{0948}\x{0907} \x{0906}\x{092f}\x{093e}\x{0905} \x{0906}\x{090f} \x{0906}\x{0908} \x{0906}\x{0908}\x{0902} \x{0907}\x{090f} \x{0906}\x{0913} \x{0906}\x{0907}\x{090f} \x{0905}\x{0915}\x{093e}\x{0930}\x{093e} \x{0906}\x{0915}\x{093e}\x{0930}\x{093e}";
 
39
 
 
40
@s = sort lengthly ( split ' ', $suffixes );
 
41
while (<>) {
 
42
    @_ = split ' ', $_;
 
43
    # candidate stems -- the code eventually picks the shortest one at the end
 
44
    foreach $w (@_) {
 
45
        $c = $w;
 
46
        foreach $stem (@s) {
 
47
            if ($w =~ /(.+?)($stem)$/) {
 
48
                $c = $1;
 
49
                last;
 
50
            }
 
51
        }
 
52
        print "$c ";
 
53
    }
 
54
    print "\n";
 
55
}
 
56