summaryrefslogtreecommitdiffstats
path: root/silpa
diff options
context:
space:
mode:
Diffstat (limited to 'silpa')
-rw-r--r--silpa/common/modulemanager.py9
-rw-r--r--silpa/css/main.css1
-rw-r--r--silpa/index.py1
-rw-r--r--silpa/modules/__init__.py5
-rw-r--r--silpa/modules/anagram/__init__.py4
-rw-r--r--silpa/modules/anagram/anagram.py105
-rw-r--r--silpa/modules/dictionary/dictionary.py70
-rw-r--r--silpa/modules/fortune/fortune.py39
-rw-r--r--silpa/modules/guesslanguages/guess_language.py2
-rw-r--r--silpa/modules/hyphenator/hyphenator.py2
-rw-r--r--silpa/modules/ngram/ngram.py16
-rw-r--r--silpa/silpa.conf16
-rw-r--r--silpa/templates/base.py6
13 files changed, 242 insertions, 34 deletions
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+"<table class=\"table1\"><tr><th>Module</th><th>Description</th><th>Status</th></tr>"
for action in module_dict:
module_instance=self.getModuleInstance(action)
- response = response+"<tr><td><a href='?action="+ action +"'>"+module_instance.get_module_name()+"</a></td>"
- response = response+"<td>"+module_instance.get_info()+"</td><td>OK</td></tr>"
+ if(module_instance!=None):
+ response = response+"<tr><td><a href='?action="+ action +"'>"+module_instance.get_module_name()+"</a></td>"
+ response = response+"<td>"+module_instance.get_info()+"</td><td>OK</td></tr>"
+ else:
+ response = response+"<tr><td>"+action.replace("_"," ")+"</td>"
+ response = response+"<td>Error while retrieving module details</td><td>Fail</td></tr>"
return response+"</table>"
if __name__ == '__main__':
mm=ModuleManager()
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/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..4fe98d1 100644
--- a/silpa/modules/__init__.py
+++ b/silpa/modules/__init__.py
@@ -1,10 +1,13 @@
#! /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 *
+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/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 <santhosh.thottingal@gmail.com>
+# 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() +"<br/>"
+ else :
+ meaning="No Meaning found"
+ return meaning.decode('utf-8')
+ def process(self,form):
+ response = """
+ <h2>English Malayalam Dictionary</h2></hr>
+ <p>Enter the word to lookup in the dictionary
+ </p>
+ <form action="" method="get">
+ <input type="text" value="%s" name="word"/>
+ <input type="submit" id="Find_Meaning" value="Find Meaning" name="action" style="width:12em;"/>
+ </br>
+ </form>
+ """
+ if(form.has_key('word')):
+ search_key = form['word'].value.decode('utf-8')
+ response=response % search_key
+ response = response+"<h2>Search Results</h2></hr>"
+ 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/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 = """
- <h2>Lemmatization</h2></hr>
+ <h2>Guess the language</h2></hr>
<p>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
</p>
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+"<h2>Language Detection Results</h2></hr>"
+ response = response+"<h2>Hyphenation Results</h2></hr>"
response = response+"<table class=\"table1\"><tr><th>Word</th><th>Hyphenated Word</th></tr>"
for word in words:
word=word.strip()
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))
diff --git a/silpa/silpa.conf b/silpa/silpa.conf
index 2323b33..068112c 100644
--- a/silpa/silpa.conf
+++ b/silpa/silpa.conf
@@ -14,13 +14,17 @@ 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.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>