summaryrefslogtreecommitdiffstats
path: root/silpa/www/modules/lemmatizer
diff options
context:
space:
mode:
Diffstat (limited to 'silpa/www/modules/lemmatizer')
-rw-r--r--silpa/www/modules/lemmatizer/__init__.py4
-rw-r--r--silpa/www/modules/lemmatizer/lemmatizer.py121
-rw-r--r--silpa/www/modules/lemmatizer/lemmatizer_ml.rules193
3 files changed, 318 insertions, 0 deletions
diff --git a/silpa/www/modules/lemmatizer/__init__.py b/silpa/www/modules/lemmatizer/__init__.py
new file mode 100644
index 0000000..3e77cd8
--- /dev/null
+++ b/silpa/www/modules/lemmatizer/__init__.py
@@ -0,0 +1,4 @@
+#! /usr/bin/env python
+# -*- coding: utf-8 -*-
+import lemmatizer
+
diff --git a/silpa/www/modules/lemmatizer/lemmatizer.py b/silpa/www/modules/lemmatizer/lemmatizer.py
new file mode 100644
index 0000000..c1ca78f
--- /dev/null
+++ b/silpa/www/modules/lemmatizer/lemmatizer.py
@@ -0,0 +1,121 @@
+#! /usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import sys
+import codecs
+import os
+import string
+import curses.ascii
+from common import SilpaModule
+class Lemmatizer(SilpaModule):
+
+ def __init__(self):
+ self.rules_file = "./modules/lemmatizer/lemmatizer_ml.rules"
+ self.rulesDict = dict()
+
+ def lemmatize(self, text):
+ result = ""
+ self.rulesDict = self.LoadRules()
+ words=text.split(" ")
+ word_count=len(words)
+ 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
+ while suffix_pos_itr < word_length :
+ suffix = word[suffix_pos_itr:word_length]
+ if suffix in self.rulesDict:
+ word= word[0:suffix_pos_itr] + self.rulesDict[suffix]
+ break;
+ suffix_pos_itr = suffix_pos_itr+1
+ word_iter = word_iter+1
+ #print word
+ result = result + word + " "
+ return result
+
+ 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 = """
+ <h2>Lemmatization</h2></hr>
+ <p>Enter the text for lemmatization 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
+ </p>
+ <form action="" method="post">
+ <textarea cols='100' rows='25' name='input_text' id='id1'>%s</textarea>
+ <input type="submit" id="Lemmatize" value="Lemmatize" name="action" style="width:12em;"/>
+ <input type="reset" value="Clear" style="width:12em;"/>
+ </br>
+ </form>
+ """
+ if(form.has_key('input_text')):
+ text = action=form['input_text'].value .decode('utf-8')
+ response=response % text
+ result = self.lemmatize(text)
+ response = response+"<h2>Lemmatization Results</h2></hr>"
+ response = response+"<p>"+result+"</p>"
+ else:
+ response=response % ""
+ return response
+
+def getInstance():
+ return Lemmatizer()
+if __name__ == "__main__":
+ lemmatizer= Lemmatizer()
+ lemmatizer.rules_file="/home/santhosh/www/malayalam.map"
+ lemmatizer.lemmatize("മുദ്രാവാക്യവുമായി മുറ്റത്തില്‍")
+
diff --git a/silpa/www/modules/lemmatizer/lemmatizer_ml.rules b/silpa/www/modules/lemmatizer/lemmatizer_ml.rules
new file mode 100644
index 0000000..5bfc40d
--- /dev/null
+++ b/silpa/www/modules/lemmatizer/lemmatizer_ml.rules
@@ -0,0 +1,193 @@
+#Malayalam Prathyaya Rules
+$min_root_length=1
+$iterations=1
+#അനുസ്വാരത്തിലവസാനിക്കുന്ന ക്രിയ/നാമം
+ത്തില്‍ = ം
+ത്ത്=ം
+ത്തു്=ം
+ത്തു=ം
+ത്തെ = ം
+വുമായി = ം
+ത്തിനെ=ം
+ത്തിലെ=ം
+ത്തിലേയ്ക്ക് =ം
+ത്തിലേയ്ക്കു്= ം
+ത്തേക്ക്=ം
+ത്തിന്റെ=ം
+ത്തേയ്ക്കു്=ം
+ത്തിലായി= ം
+മാക്കി=ം
+മായും=ം
+മെങ്കില്‍=ം എങ്കില്‍
+വും=ം
+മാണു് = ം ആണു്
+മാണ്=ം ആണ്
+മല്ല = ം അല്ല
+മില്ല = ം ഇല്ല
+മേ =ം
+മാകാം = ം ആകാം
+മായിരിക്കും=ം‌ ആയിരിക്കുക
+മുണ്ടായിരുന്നതായി=ം ഉണ്ടു് ആവുക
+മുണ്ടായി=ം ഉണ്ടു് ആവുക
+മുണ്ടായിരുന്ന=ം ഉണ്ടു് ആവുക
+മുണ്ടായിരുന്നു=ം ഉണ്ടു് ആവുക
+മുള്ള=ം ഉണ്ടാവുക
+മോ = ം
+മെ = ം
+ങ്ങളില്‍= ം
+ങ്ങള്‍ = ം
+ങ്ങളെ=ം
+ങ്ങള്‍ക്ക്=ം
+ങ്ങള്‍ക്കു്=ം
+ുകള്‍ = ു്
+#ക്രിയകള്‍
+യ്ക്കുന്ന = യ്ക്കുക
+ക്കുന്ന = ക്കുക
+#ചില്ലിലവസാനിക്കുന്ന നാമങ്ങള്‍
+രില്‍ = ര്‍
+രാണു് = ര്‍ ആണു്
+രാണ് = ര്‍ ആണ്
+രല്ല = ര്‍ അല്ല
+രില്ല = ര്‍ ഇല്ല
+രുടെ = ര്‍
+രുടേ = ര്‍
+രു് = ര്‍
+രെ = ര്‍
+രോടു് = ര്‍
+രൊടു് = ര്‍
+രൊട് = ര്‍
+രോട് = ര്‍
+രാല്‍ = ര്‍
+രോ = ര്‍
+രും=ര്‍
+നില്‍ = ന്‍
+നാണു് = ന്‍ ആണു്
+നാണ്=ന്‍ ആണ്
+നല്ല = ന്‍ അല്ല
+നില്ല= ന്‍ ഇല്ല
+നുടെ = ന്‍
+നുടേ= ന്‍
+നോടു് = ന്‍
+നോട് = ന്‍
+നായി = ന്‍ ആയി
+നോ =ന്‍
+നും=ന്‍
+ലാണു്= ല്‍ ആണു്
+ലാണ് = ല്‍ ആണ്
+ലല്ല= ല്‍ അല്ല
+ലില്ല = ല്‍ ഇല്ല
+ലില്‍ = ല്‍
+ലിന്റെ = ല്‍
+ലോട് = ല്‍
+ലോടു് = ല്‍
+ലായി=ല്‍ ആയി
+ലോ= ല്‍
+ലും=ല്‍
+ണാണു്= ണ്‍ ആണു്
+ണാണ് = ണ്‍ ആണ്
+ണിന്റെ = ണ്‍
+ണല്ല = ണ്‍ അല്ല
+ണില്ല = ണ്‍ ഇല്ല
+ണോട് =ണ്‍
+ണോടു = ണ്‍
+ണോടു്= ണ്‍
+ണോ= ണ്‍
+ണും=ണ്‍
+ളാണു്= ള്‍ ആണു്
+ളാണ്=ള്‍ ആണ്
+ളല്ല = ള്‍ അല്ല
+ളില്ല= ള്‍ ഇല്ല
+ളില്‍=ള്‍
+ളോട് = ള്‍
+ളോടു് =ള്‍
+ളോടു = ള്‍
+ളോ=ള്‍
+ളുടെ =ള്‍
+ളുടേ=ള്‍
+ള്‍ക്കായി=ള്‍
+ള്‍ക്കുള്ള =ള്‍ ഉള്ള
+ളും=ള്‍
+#അ/ഇകാരത്തിലവസാനിക്കുന്ന നാമങ്ങള്‍
+യില്‍=
+യുടെ=
+യെ=
+യാണു്=
+യിലുള്ള=യില്‍ ഉള്ള
+യാണ്=
+യും=
+യ്ക്ക് =
+യ്ക്കു് =
+യോ=
+യായ=
+യ്ക്കായി=
+ക്കായി=
+#ഉകാരത്തിലവസാനിക്കുന്ന നാമങ്ങള്‍
+വിനെ=
+വിന്റെ=
+വിന്=
+വിനു്=
+വെ=
+#് എന്നതിലവസാനിക്കുന്ന നാമങ്ങള്‍
+ില്‍=ു്
+ിനെ=ു്
+ിന്റെ=ു്
+യായി=
+#അ/ഇകാരത്തിലവസാനിക്കുന്ന ക്രിയകള്‍
+താണു്=
+താണ്=
+കള്‍=
+യാകാന്‍=" ആകാന്‍"
+യുള്ള=" ഉള്ള"
+ീകരിച്ചതു്=ിയാക്കുക
+#ഉകാരത്തിലവസാനിക്കുന്ന ക്രിയകള്‍
+ുണ്ടായ= ു് ഉണ്ടായ
+ുണ്ടാവുക= ു് ഉണ്ടാവുക
+#ത്തുക എന്നതില്‍ അവസാനിക്കുന്ന ക്രിയകള്‍= ഉണര്‍ത്തുക, പകര്‍ത്തുക
+ത്താറുണ്ടു്= ത്തുക ഉണ്ടു്
+ത്താറുണ്ട്= ത്തുക ഉണ്ടു്
+ത്തിയിട്ടുണ്ടു്= ത്തുക ഉണ്ടു്
+ത്തുയിട്ടുണ്ട്=ത്തുക ഉണ്ടു്
+ത്തിയില്ല=ത്തുക ഇല്ല
+ത്തുമോ=ത്തുക
+ത്തി=ത്തുക
+#തുക എന്നതില്‍ അവസാനിക്കുന്ന ക്രിയകള്‍ = കരുതുക. പൊരുതുക
+തി=തുക
+താറുണ്ടു്=തുക ഉണ്ടു്
+താറുണ്ട്=തുക ഉണ്ടു്
+തിയില്ല=തുക ഇല്ല
+#ക്കുക എന്നതില്‍ അവസാനിക്കുന്ന ക്രിയകള്‍ = സഞ്ചരിക്കുക, ഉറക്കുക പറക്കുക
+ക്കാന്‍=ക്കുക
+ക്കാറാണു്= ക്കുക ആണു്
+ക്കാറാണ്=ക്കുക ആണു്
+ക്കി=ക്കുക
+യ്ക്കാനായി=യ്ക്കാന്‍ ആവുക
+ക്കാനായി=ക്കാന്‍ ആവുക
+ച്ചു=യ്ക്കുക
+ിച്ച്=ിയ്ക്കുക
+ിച്ചു്=ിയ്ക്കുക
+റന്നു്=റക്കുക
+റന്ന്=റക്കുക
+ന്നിട്ടുണ്ടു്=ക്കുക ഉണ്ടു്
+ന്നിട്ടുണ്ട്=ക്കുക ഉണ്ടു്
+#കുക എന്നതില്‍ അവസാനിക്കുന്ന ക്രിയകള്‍= പടരുക, തുടരുക, വിടരുക
+ര്‍ന്നു്=രുക
+ര്‍ന്നു=രുക
+ര്‍ന്നില്ല=രുക ഇല്ല
+രാനായി=രുക ആവുക
+രുന്നതിനു=രുക
+ടരും=ടരുക
+#ങ്ങുക എന്നതില്‍ അവസാനിക്കുന്ന ക്രിയകള്‍=കറങ്ങുക
+ങ്ങന്നതിനു്=ങ്ങുക
+ക്കം=ക്കുക
+#msc
+യാണിവ=" ആണു് ഇവ"
+യുള്ളവ=" ഉള്ള അവ"
+യുള്ളതു്=" ഉള്ള അതു്"
+ാക്കപ്പെടുന്ന=ു് ആക്കുക പെടുക"
+ായിരിക്കും=" ു് ആയിരിക്കും"
+യാണുണ്ടാവുക=" ഉണ്ടാവുക"
+ളാണുള്ളത്="ള്‍ ആണു് ഉള്ളതു്"
+യുപയോഗിച്ചു്=ു് ഉപയോഗിക്കുക
+ുപയോഗിച്ചു്=ു് ഉപയോഗിക്കുക
+യുപയോഗിച്ച്=ു് ഉപയോഗിക്കുക
+ുപയോഗിച്ച്=ു് ഉപയോഗിക്കുക