diff options
author | Santhosh Thottingal <santhosh.thottingal@gmail.com> | 2009-04-25 20:38:12 +0530 |
---|---|---|
committer | Santhosh Thottingal <santhosh.thottingal@gmail.com> | 2009-04-25 20:38:12 +0530 |
commit | 97106eeee9a7fe946d59e4d80459874412d8c206 (patch) | |
tree | 9cc904b24d463849e1ba67123ad6d40327ecb5fd | |
parent | 7102af081488fbc7aa021cbd5008bed07b864e33 (diff) | |
download | AnjaliOldLipi.git-97106eeee9a7fe946d59e4d80459874412d8c206.tar.gz AnjaliOldLipi.git-97106eeee9a7fe946d59e4d80459874412d8c206.tar.xz AnjaliOldLipi.git-97106eeee9a7fe946d59e4d80459874412d8c206.zip |
Anagram Module
-rw-r--r-- | silpa/css/main.css | 1 | ||||
-rw-r--r-- | silpa/modules/__init__.py | 1 | ||||
-rw-r--r-- | silpa/modules/anagram/__init__.py | 4 | ||||
-rw-r--r-- | silpa/modules/anagram/anagram.py | 105 | ||||
-rw-r--r-- | silpa/silpa.conf | 1 | ||||
-rw-r--r-- | silpa/templates/base.py | 6 |
6 files changed, 115 insertions, 3 deletions
diff --git a/silpa/css/main.css b/silpa/css/main.css index 70658e6..851efae 100644 --- a/silpa/css/main.css +++ b/silpa/css/main.css @@ -24,6 +24,7 @@ a:hover,a:active {color:#069} /* FORMS */
form {margin: 0 0 1.5em}
input {font-family: arial,tahoma,verdana,sans-serif;margin: 2px 0}
+textarea {font-family: arial,tahoma,verdana,sans-serif;margin: 2px 0;width: 100%;height:300px}
fieldset {border: none}
label {display:block;padding: 5px 0}
label br {clear:left}
diff --git a/silpa/modules/__init__.py b/silpa/modules/__init__.py index c46904b..4fe98d1 100644 --- a/silpa/modules/__init__.py +++ b/silpa/modules/__init__.py @@ -9,4 +9,5 @@ from hyphenator import * from fortune import * from inexactsearch import * from dictionary import * +from anagram import * diff --git a/silpa/modules/anagram/__init__.py b/silpa/modules/anagram/__init__.py new file mode 100644 index 0000000..34480c2 --- /dev/null +++ b/silpa/modules/anagram/__init__.py @@ -0,0 +1,4 @@ +#! /usr/bin/env python +# -*- coding: utf-8 -*- +import anagram + diff --git a/silpa/modules/anagram/anagram.py b/silpa/modules/anagram/anagram.py new file mode 100644 index 0000000..0147c43 --- /dev/null +++ b/silpa/modules/anagram/anagram.py @@ -0,0 +1,105 @@ +#Anagram Maker +import random +import array +import sys +from common import * +class Anagram(SilpaModule): + def getRandomWord (self): + words = [ i.rstrip () for i in file ('./modules/anagram/ml_IN.dic') ] + len_words = len (words) + randnum=random.randrange(0,len_words) + return [randnum,words[randnum].decode("utf-8")] + + def syllabalize_ml(self,text): + signs = [ + u'\u0d02', u'\u0d03', u'\u0d3e', u'\u0d3f', u'\u0d40', u'\u0d41', + u'\u0d42', u'\u0d43', u'\u0d44', u'\u0d46', u'\u0d47', u'\u0d48', + u'\u0d4a', u'\u0d4b', u'\u0d4c', u'\u0d4d'] + limiters = ['.','\"','\'','`','!',';',',','?'] + + chandrakkala = u'\u0d4d' + lst_chars = [] + for char in text: + if char in limiters: + lst_chars.append(char) + elif char in signs: + lst_chars[-1] = lst_chars[-1] + char + else: + try: + if lst_chars[-1][-1] == chandrakkala: + lst_chars[-1] = lst_chars[-1] + char + else: + lst_chars.append(char) + except IndexError: + lst_chars.append(char) + + return lst_chars + + def scramble(self, word): + newword = "" + randused = [] + i=0 + while i < len(word): + randnum=random.randrange(0, len(word)) + if randnum not in randused: + randused.append(randnum) + #oldchar=word[i] + newword=newword+word[randnum] + i+=1 + #newword[randnum]=oldchar + return newword + + def check_answer(self,ans_hint): + words = [ i.rstrip () for i in file ('./modules/anagram/ml_IN.dic') ] + return words[ans_hint].decode("utf-8") + + def anagram(self): + ans_hint,orig_word=self.getRandomWord() + scrambled_word=self.scramble(self.syllabalize_ml(orig_word)) + return [ans_hint, scrambled_word] + + def process(self, form): + response = """ + <h2>Malayalam Anagram</h2></hr> + <p>Find out the original word from the scrambled word given below. + </p> + <form action="" method="post"> + %s + <br/> + <input type="hidden" name="ans_hint" value="%s"> + <input type="hidden" name="action" value="Anagram"> + <input type="text" cols='100' name='input_text' id='input_text' value="%s"/> + <br/> + <input type="submit" id="anagram" value="Submit" style="width:12em;"/> + <br/> + </form> + """ + if(form.has_key('input_text')): + text = form['input_text'].value .decode('utf-8') + ans_hint= int(form['ans_hint'].value) + answer=self.check_answer(ans_hint) + if(answer==text): + response = response+"<h2>You are correct!</h2></hr>" + response = response+"<b>Answer: "+answer+"</b>" + else: + response = response+"<h2>Your Answer is Wrong!</h2></hr>" + response = response+"<b>Answer: "+answer+"</b>" + response=response % (answer ,ans_hint,text) + else: + text="" + anagram_pair=self.anagram() + ans_hint=anagram_pair[0] + qn_word=anagram_pair[1] + response=response % (qn_word ,ans_hint,text) + return response + def get_module_name(self): + return "Malayalam Anagram" + def get_info(self): + return "Find out the original word from scrambled word!" +def getInstance(): + return Anagram() + +if __name__ == "__main__": + anagram = Anagram() + pair=anagram.anagram() + print pair[0]+"-->"+pair[1] diff --git a/silpa/silpa.conf b/silpa/silpa.conf index 7e47cad..068112c 100644 --- a/silpa/silpa.conf +++ b/silpa/silpa.conf @@ -25,5 +25,6 @@ SILPA_ACTION.Syllabalize=modules.syllabalizer #Syllabalizer module SILPA_ACTION.Hyphenate=modules.hyphenator #Syllabalizer module SILPA_ACTION.Find_Meaning=modules.dictionary #English Malayalam Module SILPA_ACTION.Fortune=modules.fortune #Syllabalizer module +SILPA_ACTION.Anagram=modules.anagram #Anagram module SILPA_ACTION.Approximate_Search=modules.inexactsearch #Approximate search #End of Silpa configuration file diff --git a/silpa/templates/base.py b/silpa/templates/base.py index c4be9c4..00d6586 100644 --- a/silpa/templates/base.py +++ b/silpa/templates/base.py @@ -63,7 +63,7 @@ http://creativecommons.org/licenses/GPL/2.0/ <ul id="nav-secondary"> <li class="first"><a href="?action=Detect+Language">Language Detection</a></li> - <li><a href="?action=Spellcheck">Spellcheck</a></li> + <li><a href="?action=spellcheck">Spellcheck</a></li> <li class="active"><a href="#">Font Conversion</a> <ul> <li class="first"><a href="?action=To+Unicode">Ascii to Unicode</a></li> @@ -72,8 +72,8 @@ http://creativecommons.org/licenses/GPL/2.0/ </li> <li><a href="#">Lemmatizer</a></li> <li><a href="#">Normalizer</a></li> - <li class="last"><a href="?action=Sort"">Sort</a></li> - <li class="last"><a href="?action=Hyphenate">Hyphenate</a></li> + + <li class="last"><a href="#">Sort</a></li> </ul> </div> |