summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoraashiks <aashiks@gmail.com>2009-04-30 12:40:23 +0530
committeraashiks <aashiks@gmail.com>2009-04-30 12:40:23 +0530
commit560d36aa534a458eee1663e56bf600286c802c6d (patch)
tree3d6ef34d17bf6fd87e9ab7f842a221415e341c9b
parent0bc0f508ebba733e8fe8430cbd4aab9e74fdcb69 (diff)
parent101ae75439d5e33e20b11243426028956abe93ad (diff)
downloadAnjaliOldLipi.git-560d36aa534a458eee1663e56bf600286c802c6d.tar.gz
AnjaliOldLipi.git-560d36aa534a458eee1663e56bf600286c802c6d.tar.xz
AnjaliOldLipi.git-560d36aa534a458eee1663e56bf600286c802c6d.zip
Merge branch 'master' of ssh://aashiks@git.sv.nongnu.org/srv/git/smc
-rwxr-xr-xbots/eng-mal-bot.py1
-rw-r--r--hyphenation/hyph_bn_IN.dic82
-rw-r--r--payyans-doc-converter/oorunner.py171
-rw-r--r--payyans-doc-converter/payyans-doc-converter.py113
-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
17 files changed, 609 insertions, 34 deletions
diff --git a/bots/eng-mal-bot.py b/bots/eng-mal-bot.py
index f6a5644..3b3ffac 100755
--- a/bots/eng-mal-bot.py
+++ b/bots/eng-mal-bot.py
@@ -6,6 +6,7 @@
# Copyright (c) 2009
# Santhosh Thottingal <santhosh.thottingal@gmail.com>
# Sarath Lakshman <sarathlakshman@gmail.com>
+# Ragsagar <ragsagar@gmail.com>
# Swathanthra Malayalam Computing(http://smc.org.in/)
#
# This program is free software; you can redistribute it and/or modify
diff --git a/hyphenation/hyph_bn_IN.dic b/hyphenation/hyph_bn_IN.dic
new file mode 100644
index 0000000..52acee5
--- /dev/null
+++ b/hyphenation/hyph_bn_IN.dic
@@ -0,0 +1,82 @@
+UTF-8
+% Hyphenation for Bengali
+% Copyright (C) 2008 Santhosh Thottingal <santhosh.thottingal@gmail.com>
+%
+% This library 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;
+% version 3 or later version of the License.
+%
+% This library 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
+% Lesser General Public License for more details.
+%
+% You should have received a copy of the GNU General Public
+% License along with this library; if not, write to the Free Software
+% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+%
+
+অ1
+আ1
+ই1
+ঈ1
+উ1
+ঊ1
+ঋ1
+এ1
+ঐ1
+ঔ1
+া1
+ি1
+ী1
+ু1
+ে1
+ো1
+ৈ1
+ৌ1
+ৗ1
+্2
+ঃ1
+ং1
+1ন
+ন্2
+2ন্‍
+1র
+র্2
+2র্‍
+1ল
+ল্2
+2ল্‍
+্2
+1ণ
+ণ্2
+2ণ্‍
+1ক
+1গ
+1খ
+1ঘ
+1ঙ
+1চ
+1ছ
+1জ
+1ঝ
+1ঞ
+1ট
+1ঠ
+1ড
+1ঢ
+1ত
+1থ
+1দ
+1ধ
+1প
+1ফ
+1ব
+1ভ
+1ম
+1য
+1শ
+1ষ
+1স
+1হ
diff --git a/payyans-doc-converter/oorunner.py b/payyans-doc-converter/oorunner.py
new file mode 100644
index 0000000..3241fe7
--- /dev/null
+++ b/payyans-doc-converter/oorunner.py
@@ -0,0 +1,171 @@
+# OpenOffice utils.
+#
+# Based on code from:
+# PyODConverter (Python OpenDocument Converter) v1.0.0 - 2008-05-05
+# Copyright (C) 2008 Mirko Nasato <mirko@artofsolving.com>
+# Copyright (C) 2009 Rajeesh K Nambiar <rajeeshknambiar@gmail.com>
+# Licensed under the GNU LGPL v2.1 - or any later version.
+# http://www.gnu.org/licenses/lgpl-2.1.html
+#
+
+import sys
+import os
+import time
+import atexit
+
+
+OPENOFFICE_PORT = 2002
+
+# Find OpenOffice.
+_oopaths=(
+ ('/usr/lib64/ooo-2.0/program', '/usr/lib64/ooo-2.0/program'),
+ ('/opt/openoffice.org3/program', '/opt/openoffice.org/basis3.0/program'),
+ )
+
+for p in _oopaths:
+ if os.path.exists(p[0]):
+ OPENOFFICE_PATH = p[0]
+ OPENOFFICE_BIN = os.path.join(OPENOFFICE_PATH, 'soffice')
+ OPENOFFICE_LIBPATH = p[1]
+
+ # Add to path so we can find uno.
+ if sys.path.count(OPENOFFICE_LIBPATH) == 0:
+ sys.path.insert(0, OPENOFFICE_LIBPATH)
+ # This is required for loadComponentFromURL
+ os.putenv('URE_BOOTSTRAP','vnd.sun.star.pathname:' + OPENOFFICE_PATH + '/fundamentalrc')
+ break
+
+
+import uno
+from com.sun.star.beans import PropertyValue
+from com.sun.star.connection import NoConnectException
+
+
+class OORunner:
+ """
+ Start, stop, and connect to OpenOffice.
+ """
+ def __init__(self, port=OPENOFFICE_PORT):
+ """ Create OORunner that connects on the specified port. """
+ self.port = port
+
+
+ def connect(self, no_startup=False):
+ """
+ Connect to OpenOffice.
+ If a connection cannot be established try to start OpenOffice.
+ """
+ localContext = uno.getComponentContext()
+ resolver = localContext.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", localContext)
+ context = None
+ did_start = False
+
+ n = 0
+ while n < 6:
+ try:
+ context = resolver.resolve("uno:socket,host=localhost,port=%d;urp;StarOffice.ComponentContext" % self.port)
+ break
+ except NoConnectException:
+ pass
+
+ # If first connect failed then try starting OpenOffice.
+ if n == 0:
+ # Exit loop if startup not desired.
+ if no_startup:
+ break
+ self.startup()
+ did_start = True
+
+ # Pause and try again to connect
+ time.sleep(1)
+ n += 1
+
+ if not context:
+ raise Exception, "Failed to connect to OpenOffice on port %d" % self.port
+
+ desktop = context.ServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", context)
+
+ if not desktop:
+ raise Exception, "Failed to create OpenOffice desktop on port %d" % self.port
+
+ if did_start:
+ _started_desktops[self.port] = desktop
+
+ return desktop
+
+
+ def startup(self):
+ """
+ Start a headless instance of OpenOffice.
+ """
+ args = [OPENOFFICE_BIN,
+ '-accept=socket,host=localhost,port=%d;urp;StarOffice.ServiceManager' % self.port,
+ '-norestore',
+ '-nofirststartwizard',
+ '-nologo',
+ '-headless',
+ ]
+ env = {'PATH' : '/bin:/usr/bin:%s' % OPENOFFICE_PATH,
+ 'PYTHONPATH' : OPENOFFICE_LIBPATH,
+ }
+
+ try:
+ pid = os.spawnve(os.P_NOWAIT, args[0], args, env)
+ except Exception, e:
+ raise Exception, "Failed to start OpenOffice on port %d: %s" % (self.port, e.message)
+
+ if pid <= 0:
+ raise Exception, "Failed to start OpenOffice on port %d" % self.port
+
+
+ def shutdown(self):
+ """
+ Shutdown OpenOffice.
+ """
+ try:
+ if _started_desktops.get(self.port):
+ _started_desktops[self.port].terminate()
+ del _started_desktops[self.port]
+ except Exception, e:
+ pass
+
+
+
+# Keep track of started desktops and shut them down on exit.
+_started_desktops = {}
+
+def _shutdown_desktops():
+ """ Shutdown all OpenOffice desktops that were started by the program. """
+ for port, desktop in _started_desktops.items():
+ try:
+ if desktop:
+ desktop.terminate()
+ except Exception, e:
+ pass
+
+
+atexit.register(_shutdown_desktops)
+
+
+def oo_shutdown_if_running(port=OPENOFFICE_PORT):
+ """ Shutdown OpenOffice if it's running on the specified port. """
+ oorunner = OORunner(port)
+ try:
+ desktop = oorunner.connect(no_startup=True)
+ desktop.terminate()
+ except Exception, e:
+ pass
+
+
+def oo_properties(**args):
+ """
+ Convert args to OpenOffice property values.
+ """
+ props = []
+ for key in args:
+ prop = PropertyValue()
+ prop.Name = key
+ prop.Value = args[key]
+ props.append(prop)
+
+ return tuple(props)
diff --git a/payyans-doc-converter/payyans-doc-converter.py b/payyans-doc-converter/payyans-doc-converter.py
new file mode 100644
index 0000000..2734d88
--- /dev/null
+++ b/payyans-doc-converter/payyans-doc-converter.py
@@ -0,0 +1,113 @@
+#!/usr/bin/env python
+#
+# Copyright (C) 2009 Rajeesh K Nambiar <rajeeshknambiar@gmail.com>
+#
+# 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 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., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301, USA.
+
+import sys
+import os
+
+# import the oorunner helper module we've written
+import oorunner
+# Payyans
+from payyans import Payyans
+
+class OOWrapper:
+ def __init__(self):
+ # Find OpenOffice.
+ _oopaths=(
+ ('/usr/lib64/ooo-2.0/program', '/usr/lib64/ooo-2.0/program'),
+ ('/opt/openoffice.org3/program', '/opt/openoffice.org/basis3.0/program'),
+ )
+ for p in _oopaths:
+ if os.path.exists(p[0]):
+ OPENOFFICE_PATH = p[0]
+ OPENOFFICE_BIN = os.path.join(OPENOFFICE_PATH, 'soffice')
+ OPENOFFICE_LIBPATH = p[1]
+
+ # Add to path so we can find uno.
+ if sys.path.count(OPENOFFICE_LIBPATH) == 0:
+ sys.path.insert(0, OPENOFFICE_LIBPATH)
+ os.putenv('URE_BOOTSTRAP','vnd.sun.star.pathname:' + OPENOFFICE_PATH + '/fundamentalrc')
+ # This is required for loadComponentFromURL to work properly
+ break
+
+ # start the openoffice instance
+ oor = oorunner.OORunner()
+ # get the central desktop object
+ self.desktop = oor.connect()
+ self.infile = None
+ self.outfile = None
+
+ def createTextFilter(self):
+ # Needed for FilterName - to export to TXT
+ import uno
+ from com.sun.star.beans import PropertyValue
+ TXT = PropertyValue()
+ TXT.Name = "FilterName"
+ TXT.Value = "Text"
+ return TXT
+
+ def convertDocToText(self, docFile):
+ ''' Convert the Document file to Text format '''
+ self.infile = os.path.abspath(docFile)
+ if not os.path.exists(self.infile):
+ raise SystemExit ("Input file doesn't exist")
+
+ self.document = self.desktop.loadComponentFromURL("file://"+self.infile, "_blank", 0, ())
+ filter = self.createTextFilter()
+ (fname, ext) = os.path.splitext(self.infile)
+ self.textfile = fname + ".txt"
+ self.document.storeAsURL("file://" + self.textfile, (filter,))
+
+ self.closeOffice()
+
+ def closeOffice(self):
+
+ # Close the document
+ self.document.dispose()
+ # Close the OpenOffice desktop
+ self.desktop.terminate()
+
+ def covertDocWithPayyans(self, inFile, mapFile, outFile, direction):
+ ''' Call Payyans to do the actual conversion '''
+ # @direction : a2u/u2a for ASCII-to-Unicode and vice versa
+ self.convertDocToText(inFile)
+ p=Payyans(self.textfile, os.path.abspath(outFile), os.path.abspath(mapFile))
+ if not p:
+ raise SystemExit("Couldn't create Payyan instance")
+ if direction == "a2u":
+ p.ascii2unicode()
+ else:
+ p.unicode2ascii()
+
+
+if __name__ == "__main__":
+ if sys.argv.__len__() != 5:
+ raise SystemExit("usage: "+sys.argv[0]+" <infile> <outfile> <mapfile> <direction>")
+ infile = sys.argv[1]
+ outfile = sys.argv[2]
+ mapfile = sys.argv[3]
+ direction = sys.argv[4]
+ if not os.path.exists(os.path.abspath(infile)):
+ raise SystemExit("Cannot find Input file")
+ if not os.path.exists(os.path.abspath(mapfile)):
+ raise SystemExit("Cannot find Mapping file")
+ if not direction in ['a2u', 'u2a']:
+ raise SystemExit("Direction should be either 'a2u' or 'u2a'")
+
+ app = OOWrapper()
+ app.covertDocWithPayyans(infile, mapfile, outfile, direction)
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>