From c8a17ee264a269a59651936b34a960f4d40a9074 Mon Sep 17 00:00:00 2001 From: Santhosh Thottingal Date: Sun, 19 Jul 2009 18:32:04 +0530 Subject: JSON RPC Based new architecture and corresponding changes --- silpa/modules/stemmer/stemmer.py | 128 ++++++++++++++++++++++ silpa/modules/stemmer/stemmer_ml.rules | 193 +++++++++++++++++++++++++++++++++ 2 files changed, 321 insertions(+) create mode 100755 silpa/modules/stemmer/stemmer.py create mode 100755 silpa/modules/stemmer/stemmer_ml.rules (limited to 'silpa/modules/stemmer') diff --git a/silpa/modules/stemmer/stemmer.py b/silpa/modules/stemmer/stemmer.py new file mode 100755 index 0000000..64bfaea --- /dev/null +++ b/silpa/modules/stemmer/stemmer.py @@ -0,0 +1,128 @@ +#! /usr/bin/env python +# -*- coding: utf-8 -*- + +import sys +import codecs +import os +import string +import curses.ascii +from common import SilpaModule +class Stemmer(SilpaModule): + + def __init__(self): + self.rules_file = "./modules/stemmer/stemmer_ml.rules" + self.rulesDict = dict() + + def lemmatize(self, text): + result = "" + self.rulesDict = self.LoadRules() + words=text.split(" ") + word_count=len(words) + result_dict = dict() + word_iter=0 + word="" + while word_iter < word_count: + word = words[word_iter] + word = self.trim(word) + word_length = len(word) + suffix_pos_itr = 2 + word_stemmed="" + while suffix_pos_itr < word_length : + suffix = word[suffix_pos_itr:word_length] + if suffix in self.rulesDict: + word_stemmed= word[0:suffix_pos_itr] + self.rulesDict[suffix] + break; + suffix_pos_itr = suffix_pos_itr+1 + word_iter = word_iter+1 + if(word_stemmed==""): + word_stemmed=word + result_dict[ word ] = word_stemmed + return result_dict + + def LoadRules(self): + print "Loading the rules..." + rules_dict = dict() + line = [] + line_number = 0 + rule_number = 0 + rules_file = codecs. open(self.rules_file,encoding='utf-8', errors='ignore') + while 1: + line_number = line_number +1 + text = unicode( rules_file.readline()) + if text == "": + break + if text[0] == '#': + continue #this is a comment - ignore + text = text.split("#")[0] #remove the comment part of the line + line_number = line_number +1 + line = text.strip() # remove unwanted space + if(line == ""): + continue + if(len(line.split("=")) != 2): + print "[Error] Syntax Error in the Rules. Line number: ", line_number + print "Line: "+ text + continue + lhs = line.split("=") [ 0 ] .strip() + rhs = line.split("=") [ 1 ] .strip() + if(len(rhs)>0): + if(lhs[0]=='"'): + lhs=lhs[1:len(lhs)] # if the string is "quoted" + if(lhs[len(lhs)-1]=='"'): + lhs=lhs[0:len(lhs)-1] # if the string is "quoted" + if(len(rhs)>0): + if(rhs[0]=='"'): + rhs=rhs[1:len(rhs)] # if the string is "quoted" + if(rhs[len(rhs)-1]=='"'): + rhs=rhs[0:len(rhs)-1] # if the string is "quoted" + rule_number=rule_number+1 + rules_dict[lhs]=rhs + #print "[", rule_number ,"] " +lhs + " : " +rhs + print "Found ",rule_number, " rules." + return rules_dict + + def trim(self,word): + punctuations=['~','!','@','#','$','%','^','&','*','(',')','-','+','_','=','{','}','|' ,':',';','<','>','\,','.','?'] + word=word.strip() + index=len(word)-1 + while index>0: + if word[index] in punctuations: + word=word[0:index] + else: + break + index=index-1 + return word + def process(self, form): + response = """ +

Stemmer

+

Enter the text for stemming in the below text area. + Language of each word will be detected. + You can give the text in any language and even with mixed language +

+
+ + + +
+
+ """ + if(form.has_key('input_text')): + text = form['input_text'].value .decode('utf-8') + response=response % text + result_dict = self.lemmatize(text) + response = response+"

Stemming Results

" + response = response+"" + for key in result_dict: + response = response+"" + response = response+"
WordStem
"+key+""+result_dict[key]+"
" + else: + response=response % "" + return response + def get_module_name(self): + return "Stemmer" + def get_info(self): + return "Malayalam Stemmer(Experimental)" + +def getInstance(): + return Stemmer() + + diff --git a/silpa/modules/stemmer/stemmer_ml.rules b/silpa/modules/stemmer/stemmer_ml.rules new file mode 100755 index 0000000..5bfc40d --- /dev/null +++ b/silpa/modules/stemmer/stemmer_ml.rules @@ -0,0 +1,193 @@ +#Malayalam Prathyaya Rules +$min_root_length=1 +$iterations=1 +#അനുസ്വാരത്തിലവസാനിക്കുന്ന ക്രിയ/നാമം +ത്തില്‍ = ം +ത്ത്=ം +ത്തു്=ം +ത്തു=ം +ത്തെ = ം +വുമായി = ം +ത്തിനെ=ം +ത്തിലെ=ം +ത്തിലേയ്ക്ക് =ം +ത്തിലേയ്ക്കു്= ം +ത്തേക്ക്=ം +ത്തിന്റെ=ം +ത്തേയ്ക്കു്=ം +ത്തിലായി= ം +മാക്കി=ം +മായും=ം +മെങ്കില്‍=ം എങ്കില്‍ +വും=ം +മാണു് = ം ആണു് +മാണ്=ം ആണ് +മല്ല = ം അല്ല +മില്ല = ം ഇല്ല +മേ =ം +മാകാം = ം ആകാം +മായിരിക്കും=ം‌ ആയിരിക്കുക +മുണ്ടായിരുന്നതായി=ം ഉണ്ടു് ആവുക +മുണ്ടായി=ം ഉണ്ടു് ആവുക +മുണ്ടായിരുന്ന=ം ഉണ്ടു് ആവുക +മുണ്ടായിരുന്നു=ം ഉണ്ടു് ആവുക +മുള്ള=ം ഉണ്ടാവുക +മോ = ം +മെ = ം +ങ്ങളില്‍= ം +ങ്ങള്‍ = ം +ങ്ങളെ=ം +ങ്ങള്‍ക്ക്=ം +ങ്ങള്‍ക്കു്=ം +ുകള്‍ = ു് +#ക്രിയകള്‍ +യ്ക്കുന്ന = യ്ക്കുക +ക്കുന്ന = ക്കുക +#ചില്ലിലവസാനിക്കുന്ന നാമങ്ങള്‍ +രില്‍ = ര്‍ +രാണു് = ര്‍ ആണു് +രാണ് = ര്‍ ആണ് +രല്ല = ര്‍ അല്ല +രില്ല = ര്‍ ഇല്ല +രുടെ = ര്‍ +രുടേ = ര്‍ +രു് = ര്‍ +രെ = ര്‍ +രോടു് = ര്‍ +രൊടു് = ര്‍ +രൊട് = ര്‍ +രോട് = ര്‍ +രാല്‍ = ര്‍ +രോ = ര്‍ +രും=ര്‍ +നില്‍ = ന്‍ +നാണു് = ന്‍ ആണു് +നാണ്=ന്‍ ആണ് +നല്ല = ന്‍ അല്ല +നില്ല= ന്‍ ഇല്ല +നുടെ = ന്‍ +നുടേ= ന്‍ +നോടു് = ന്‍ +നോട് = ന്‍ +നായി = ന്‍ ആയി +നോ =ന്‍ +നും=ന്‍ +ലാണു്= ല്‍ ആണു് +ലാണ് = ല്‍ ആണ് +ലല്ല= ല്‍ അല്ല +ലില്ല = ല്‍ ഇല്ല +ലില്‍ = ല്‍ +ലിന്റെ = ല്‍ +ലോട് = ല്‍ +ലോടു് = ല്‍ +ലായി=ല്‍ ആയി +ലോ= ല്‍ +ലും=ല്‍ +ണാണു്= ണ്‍ ആണു് +ണാണ് = ണ്‍ ആണ് +ണിന്റെ = ണ്‍ +ണല്ല = ണ്‍ അല്ല +ണില്ല = ണ്‍ ഇല്ല +ണോട് =ണ്‍ +ണോടു = ണ്‍ +ണോടു്= ണ്‍ +ണോ= ണ്‍ +ണും=ണ്‍ +ളാണു്= ള്‍ ആണു് +ളാണ്=ള്‍ ആണ് +ളല്ല = ള്‍ അല്ല +ളില്ല= ള്‍ ഇല്ല +ളില്‍=ള്‍ +ളോട് = ള്‍ +ളോടു് =ള്‍ +ളോടു = ള്‍ +ളോ=ള്‍ +ളുടെ =ള്‍ +ളുടേ=ള്‍ +ള്‍ക്കായി=ള്‍ +ള്‍ക്കുള്ള =ള്‍ ഉള്ള +ളും=ള്‍ +#അ/ഇകാരത്തിലവസാനിക്കുന്ന നാമങ്ങള്‍ +യില്‍= +യുടെ= +യെ= +യാണു്= +യിലുള്ള=യില്‍ ഉള്ള +യാണ്= +യും= +യ്ക്ക് = +യ്ക്കു് = +യോ= +യായ= +യ്ക്കായി= +ക്കായി= +#ഉകാരത്തിലവസാനിക്കുന്ന നാമങ്ങള്‍ +വിനെ= +വിന്റെ= +വിന്= +വിനു്= +വെ= +#് എന്നതിലവസാനിക്കുന്ന നാമങ്ങള്‍ +ില്‍=ു് +ിനെ=ു് +ിന്റെ=ു് +യായി= +#അ/ഇകാരത്തിലവസാനിക്കുന്ന ക്രിയകള്‍ +താണു്= +താണ്= +കള്‍= +യാകാന്‍=" ആകാന്‍" +യുള്ള=" ഉള്ള" +ീകരിച്ചതു്=ിയാക്കുക +#ഉകാരത്തിലവസാനിക്കുന്ന ക്രിയകള്‍ +ുണ്ടായ= ു് ഉണ്ടായ +ുണ്ടാവുക= ു് ഉണ്ടാവുക +#ത്തുക എന്നതില്‍ അവസാനിക്കുന്ന ക്രിയകള്‍= ഉണര്‍ത്തുക, പകര്‍ത്തുക +ത്താറുണ്ടു്= ത്തുക ഉണ്ടു് +ത്താറുണ്ട്= ത്തുക ഉണ്ടു് +ത്തിയിട്ടുണ്ടു്= ത്തുക ഉണ്ടു് +ത്തുയിട്ടുണ്ട്=ത്തുക ഉണ്ടു് +ത്തിയില്ല=ത്തുക ഇല്ല +ത്തുമോ=ത്തുക +ത്തി=ത്തുക +#തുക എന്നതില്‍ അവസാനിക്കുന്ന ക്രിയകള്‍ = കരുതുക. പൊരുതുക +തി=തുക +താറുണ്ടു്=തുക ഉണ്ടു് +താറുണ്ട്=തുക ഉണ്ടു് +തിയില്ല=തുക ഇല്ല +#ക്കുക എന്നതില്‍ അവസാനിക്കുന്ന ക്രിയകള്‍ = സഞ്ചരിക്കുക, ഉറക്കുക പറക്കുക +ക്കാന്‍=ക്കുക +ക്കാറാണു്= ക്കുക ആണു് +ക്കാറാണ്=ക്കുക ആണു് +ക്കി=ക്കുക +യ്ക്കാനായി=യ്ക്കാന്‍ ആവുക +ക്കാനായി=ക്കാന്‍ ആവുക +ച്ചു=യ്ക്കുക +ിച്ച്=ിയ്ക്കുക +ിച്ചു്=ിയ്ക്കുക +റന്നു്=റക്കുക +റന്ന്=റക്കുക +ന്നിട്ടുണ്ടു്=ക്കുക ഉണ്ടു് +ന്നിട്ടുണ്ട്=ക്കുക ഉണ്ടു് +#കുക എന്നതില്‍ അവസാനിക്കുന്ന ക്രിയകള്‍= പടരുക, തുടരുക, വിടരുക +ര്‍ന്നു്=രുക +ര്‍ന്നു=രുക +ര്‍ന്നില്ല=രുക ഇല്ല +രാനായി=രുക ആവുക +രുന്നതിനു=രുക +ടരും=ടരുക +#ങ്ങുക എന്നതില്‍ അവസാനിക്കുന്ന ക്രിയകള്‍=കറങ്ങുക +ങ്ങന്നതിനു്=ങ്ങുക +ക്കം=ക്കുക +#msc +യാണിവ=" ആണു് ഇവ" +യുള്ളവ=" ഉള്ള അവ" +യുള്ളതു്=" ഉള്ള അതു്" +ാക്കപ്പെടുന്ന=ു് ആക്കുക പെടുക" +ായിരിക്കും=" ു് ആയിരിക്കും" +യാണുണ്ടാവുക=" ഉണ്ടാവുക" +ളാണുള്ളത്="ള്‍ ആണു് ഉള്ളതു്" +യുപയോഗിച്ചു്=ു് ഉപയോഗിക്കുക +ുപയോഗിച്ചു്=ു് ഉപയോഗിക്കുക +യുപയോഗിച്ച്=ു് ഉപയോഗിക്കുക +ുപയോഗിച്ച്=ു് ഉപയോഗിക്കുക -- cgit