From 10d9985caf134fcf7ac85de8105de53c5d2442f1 Mon Sep 17 00:00:00 2001 From: Jinesh K J Date: Sat, 18 Apr 2009 22:00:56 +0530 Subject: corrected some spellings --- silpa/modules/ngram/ngram.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'silpa') diff --git a/silpa/modules/ngram/ngram.py b/silpa/modules/ngram/ngram.py index 8f2d65b..cab2ed9 100644 --- a/silpa/modules/ngram/ngram.py +++ b/silpa/modules/ngram/ngram.py @@ -305,7 +305,7 @@ class NGram: pickle.dump(self.getRoot(),open(PICKLED_TREE,'w')) if __name__ == "__main__": usage = "usage: %prog [options] inputfile" - parser = OptionParser(version="%prog 0.1",description="Malayalama NGram Analyser") + parser = OptionParser(version="%prog 0.1",description="Malayalam NGram Analyser") parser.set_usage(usage) parser.add_option("-g", "--generate-graph", dest="gen_graph",help="Generates a graph in png format to visualize the ngram") parser.add_option("-p", "--print", action="store_true",default=False,dest="print_ngram",help="Print the Ngram") @@ -317,9 +317,9 @@ if __name__ == "__main__": if(options.gen_graph): ng = NGram () ng.toGraph(options.gen_graph) - if(options. input_file): + if(options.input_file): if not os.path.exists(options.input_file): - print "File Doesnot Existis" + print "File Doesnot Exist" sys.exit(1) else: corpus_file = codecs. open(options.input_file,encoding='utf-8', errors='ignore') @@ -332,16 +332,16 @@ if __name__ == "__main__": ng.populateSyllableNgram(text) ng.populateWordNgram(text) print "Populated" - if(options. print_ngram): + if(options.print_ngram): ng = NGram () print ng.getRoot().toString() - if(options. suggest_syllables): + if(options.suggest_syllables): ng = NGram () print "Searching for" + options.suggest_words - print ng.searchNodeByName(unicode(options. suggest_syllables)) - if(options. suggest_syllables): + print ng.searchNodeByName(unicode(options.suggest_syllables)) + if(options.suggest_syllables): ng = NGram () print "Searching for "+ options.suggest_words - print ng.searchNodeByName(unicode(options. suggest_words)) + print ng.searchNodeByName(unicode(options.suggest_words)) -- cgit From 39d12a4a44fe0a2b386ba9562833f8bf6f6275f2 Mon Sep 17 00:00:00 2001 From: Santhosh Thottingal Date: Wed, 22 Apr 2009 23:39:53 +0530 Subject: Adding Dictionary Module to Silpa --- silpa/index.py | 1 + silpa/modules/__init__.py | 4 +- silpa/modules/dictionary/dictionary.py | 70 ++++++++++++++++++++++++++++++++++ silpa/silpa.conf | 15 +++++--- 4 files changed, 83 insertions(+), 7 deletions(-) create mode 100644 silpa/modules/dictionary/dictionary.py (limited to 'silpa') diff --git a/silpa/index.py b/silpa/index.py index 91798a1..8a44a15 100644 --- a/silpa/index.py +++ b/silpa/index.py @@ -15,6 +15,7 @@ def index(form): response=SilpaResponse() if(action): module_manager=ModuleManager() + action=action.replace(" ","_") module_instance = module_manager.getModuleInstance(action) if(module_instance): response.setBreadcrumb(module_instance.get_module_name()) diff --git a/silpa/modules/__init__.py b/silpa/modules/__init__.py index 7a3b875..c46904b 100644 --- a/silpa/modules/__init__.py +++ b/silpa/modules/__init__.py @@ -1,10 +1,12 @@ #! /usr/bin/env python # -*- coding: utf-8 -*- -from lemmatizer import * +from stemmer import * from payyans import * from transliterator import * from syllabalizer import * from guesslanguages import * from hyphenator import * from fortune import * +from inexactsearch import * +from dictionary import * diff --git a/silpa/modules/dictionary/dictionary.py b/silpa/modules/dictionary/dictionary.py new file mode 100644 index 0000000..7ba877a --- /dev/null +++ b/silpa/modules/dictionary/dictionary.py @@ -0,0 +1,70 @@ +#! /usr/bin/env python +# -*- coding: utf-8 -*- +# English Malayalam Dictionary +# Copyright 2008 Santhosh Thottingal +# http://www.smc.org.in +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Library General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +# If you find any bugs or have any suggestions email: santhosh.thottingal@gmail.com +# URL: http://www.smc.org.in + + +from common import * +import os +import pickle +class Dictionary(SilpaModule): + + def lookup_en_ml(self, key): + self.dictFile=os.path.dirname(__file__) + "/data/dict.dat" + pickled_dict=open(self.dictFile,'r') + self.dictionary=pickle.load(pickled_dict) + meaning="" + if self.dictionary.has_key(key): + meaningList=self.dictionary[key] + for meaning_item in meaningList: + meaning=meaning+meaning_item.strip() +"
" + else : + meaning="No Meaning found" + return meaning.decode('utf-8') + def process(self,form): + response = """ +

English Malayalam Dictionary

+

Enter the word to lookup in the dictionary +

+
+ + +
+
+ """ + if(form.has_key('word')): + search_key = form['word'].value.decode('utf-8') + response=response % search_key + response = response+"

Search Results

" + if(search_key==None): + response = response+ "Enter a word to find meaning." + else: + response = response+ self.lookup_en_ml(search_key) + else: + response=response % "" + return response + def get_module_name(self): + return "English Malayalam Dictionary" + def get_info(self): + return "English Malayalam Dictionary. Dictionary is compiled by Kerala state IT Mission" + +def getInstance(): + return Dictionary() diff --git a/silpa/silpa.conf b/silpa/silpa.conf index 2323b33..7e47cad 100644 --- a/silpa/silpa.conf +++ b/silpa/silpa.conf @@ -14,13 +14,16 @@ SILPA_SITE_COPYRIGHT= Copyright 2008-2009. Silpa Team. All rights Reserved. #Action names should be unique. and should be prefixed with "SILPA_ACTION." #TO disable an action, comment out the line #An example entry -#SILPA_ACTION.sort=modules.sort #comment at the end of line is also allowed +#SILPA_ACTION.Sort=modules.sort #comment at the end of line is also allowed SILPA_ACTION.Transliterate=modules.transliterate #transliterator module -SILPA_ACTION.Lemmatize=modules.lemmatizer #Lemmatizer module for Indian Languages -SILPA_ACTION.Detect Language=utils #This is also a valid module -SILPA_ACTION.Guess Language=modules.guess_language #This is also a valid module -SILPA_ACTION.To Unicode=modules.payyans #Ascii to Unicode conversion Module -SILPA_ACTION.To ASCII=modules.payyans #Unicode to Ascii conversion Module +SILPA_ACTION.Stem=modules.stemmer #stemmer module for Indian Languages +SILPA_ACTION.Detect_Language=utils #This is also a valid module +SILPA_ACTION.Guess_Language=modules.guess_language #This is also a valid module +SILPA_ACTION.To_Unicode=modules.payyans #Ascii to Unicode conversion Module +SILPA_ACTION.To_ASCII=modules.payyans #Unicode to Ascii conversion Module 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.Approximate_Search=modules.inexactsearch #Approximate search #End of Silpa configuration file -- cgit From 550f1ef9f4cd12f6a75090fa14490effc1230631 Mon Sep 17 00:00:00 2001 From: Santhosh Thottingal Date: Wed, 22 Apr 2009 23:42:35 +0530 Subject: Bug Fixes --- silpa/common/modulemanager.py | 9 ++++-- silpa/modules/fortune/fortune.py | 39 ++++++++++++++++++-------- silpa/modules/guesslanguages/guess_language.py | 2 +- silpa/modules/hyphenator/hyphenator.py | 2 +- 4 files changed, 36 insertions(+), 16 deletions(-) (limited to 'silpa') diff --git a/silpa/common/modulemanager.py b/silpa/common/modulemanager.py index 8f9c79d..a3e9f1b 100644 --- a/silpa/common/modulemanager.py +++ b/silpa/common/modulemanager.py @@ -18,6 +18,7 @@ class ModuleManager: return obj def getModuleInstance(self,action): + action=action.replace(" ","_") module_name = self.find_module(action) if(module_name): try: @@ -37,8 +38,12 @@ class ModuleManager: response = response+"" for action in module_dict: module_instance=self.getModuleInstance(action) - response = response+"" - response = response+"" + if(module_instance!=None): + response = response+"" + response = response+"" + else: + response = response+"" + response = response+"" return response+"
ModuleDescriptionStatus
"+module_instance.get_module_name()+""+module_instance.get_info()+"OK
"+module_instance.get_module_name()+""+module_instance.get_info()+"OK
"+action.replace("_"," ")+"Error while retrieving module detailsFail
" if __name__ == '__main__': mm=ModuleManager() diff --git a/silpa/modules/fortune/fortune.py b/silpa/modules/fortune/fortune.py index e7aac98..cf31aad 100644 --- a/silpa/modules/fortune/fortune.py +++ b/silpa/modules/fortune/fortune.py @@ -1,22 +1,37 @@ -# Spellchecker with language detection -# coding: utf-8 +# Fortune +# -*- coding: utf-8 -*- # # Copyright © 2008 Santhosh Thottingal # Released under the GPLV3+ license -import os +import os,random from common import * class Fortune(SilpaModule): + def fortunes(self,infile,pattern=None): + """ Yield fortunes as lists of lines """ + result = [] + for line in infile: + line=line.decode("utf-8") + if line == "%\n": + yield result + result = [] + else: + if(pattern==None): + result.append(line) + else: + if(line.find(pattern)==-1): + result.append(line) + if result: + yield result + def fortune_ml(self, word): - if(word>""): - command = "/usr/games/fortune -m " + word + " ./modules/fortune/database/fortune-ml" - else: - command = "/usr/games/fortune ./modules/fortune/database/fortune-ml" - command=command.encode('utf-8') - pipe = os.popen('{ ' + command + '; } 2>&1', 'r') - text = pipe.read().decode('utf-8') - pipe.close() - return text + filename="./modules/fortune/database/fortune-ml" + """ Pick a random fortune from a file """ + for index, fortune in enumerate(self.fortunes(file(filename),None)): + if random.random() < (1.0 / (index+1)): + chosen = fortune + + return "".join(chosen) def process(self, form): response = """ diff --git a/silpa/modules/guesslanguages/guess_language.py b/silpa/modules/guesslanguages/guess_language.py index 1d88891..158b5f5 100644 --- a/silpa/modules/guesslanguages/guess_language.py +++ b/silpa/modules/guesslanguages/guess_language.py @@ -531,7 +531,7 @@ def normalize(u): class LangGuess(SilpaModule): def process(self, form): response = """ -

Lemmatization

+

Guess the language

Enter the text for guessing the language in the below text area. You can give the text in any language and even with mixed language

diff --git a/silpa/modules/hyphenator/hyphenator.py b/silpa/modules/hyphenator/hyphenator.py index 3f223d4..f5e8fe2 100644 --- a/silpa/modules/hyphenator/hyphenator.py +++ b/silpa/modules/hyphenator/hyphenator.py @@ -244,7 +244,7 @@ class Hyphenator(SilpaModule): text = action=form['input_text'].value .decode('utf-8') response=response % text words=text.split(" ") - response = response+"

Language Detection Results

" + response = response+"

Hyphenation Results

" response = response+"" for word in words: word=word.strip() -- cgit From 97106eeee9a7fe946d59e4d80459874412d8c206 Mon Sep 17 00:00:00 2001 From: Santhosh Thottingal Date: Sat, 25 Apr 2009 20:38:12 +0530 Subject: Anagram Module --- silpa/css/main.css | 1 + silpa/modules/__init__.py | 1 + silpa/modules/anagram/__init__.py | 4 ++ silpa/modules/anagram/anagram.py | 105 ++++++++++++++++++++++++++++++++++++++ silpa/silpa.conf | 1 + silpa/templates/base.py | 6 +-- 6 files changed, 115 insertions(+), 3 deletions(-) create mode 100644 silpa/modules/anagram/__init__.py create mode 100644 silpa/modules/anagram/anagram.py (limited to 'silpa') 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 = """ +

Malayalam Anagram

+

Find out the original word from the scrambled word given below. +

+
+ %s +
+ + + +
+ +
+ + """ + 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+"

You are correct!

" + response = response+"Answer: "+answer+"" + else: + response = response+"

Your Answer is Wrong!

" + response = response+"Answer: "+answer+"" + 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/
WordHyphenated Word